Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Unified Diff: examples/dart/camera_video/lib/main.dart

Issue 1375733004: -Add a mojo service to get video frames from the camera through an android service (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: merge. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « examples/dart/camera_roll/lib/main.dart ('k') | examples/dart/camera_video/pubspec.lock » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/dart/camera_video/lib/main.dart
diff --git a/examples/dart/camera_roll/lib/main.dart b/examples/dart/camera_video/lib/main.dart
similarity index 54%
copy from examples/dart/camera_roll/lib/main.dart
copy to examples/dart/camera_video/lib/main.dart
index d0a1bd7061568f75d038a71838cfb756eecb66d9..4637a211271dbe9a30fbb4f41c295e357ed2cbe3 100644
--- a/examples/dart/camera_roll/lib/main.dart
+++ b/examples/dart/camera_video/lib/main.dart
@@ -2,8 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// This example makes use of mojo:camera_roll which is available only when
-// running on Android.
+// This example makes use of mojo:camera which is available only when
+// running on Android. It repeatedly captures camera video frame images
+// and displays it in a mojo view.
//
// Example usage:
// pub get
@@ -13,19 +14,20 @@
import 'dart:sky';
import 'dart:typed_data';
-import 'package:mojo_services/mojo/camera_roll.mojom.dart';
+import 'package:mojo_services/mojo/camera.mojom.dart';
import 'package:sky/services.dart';
-final CameraRollServiceProxy cameraRoll = new CameraRollServiceProxy.unbound();
-Image currentImage;
-int photoIndex = 0;
+Image image = null;
+final CameraServiceProxy camera = new CameraServiceProxy.unbound();
Picture paint(Rect paintBounds) {
PictureRecorder recorder = new PictureRecorder();
- Canvas canvas = new Canvas(recorder, paintBounds);
- Paint paint = new Paint()..color = const Color.fromARGB(255, 0, 255, 0);
- if (currentImage != null) {
- canvas.drawImage(currentImage, new Point(0.0, 0.0), paint);
+ if (image != null) {
+ Canvas canvas = new Canvas(recorder, paintBounds);
+ canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
+ canvas.scale(0.3, 0.3);
+ Paint paint = new Paint()..color = const Color.fromARGB(255, 0, 255, 0);
+ canvas.drawImage(image, new Point(-image.width / 2.0, -image.height / 2.0), paint);
}
return recorder.endRecording();
}
@@ -53,44 +55,25 @@ void beginFrame(double timeStamp) {
view.scene = scene;
}
-void getPhoto() {
- var future = cameraRoll.ptr.getPhoto(photoIndex);
+void drawNextPhoto() {
+ var future = camera.ptr.getLatestFrame();
future.then((response) {
- if (response.photo == null) {
- print("Photo $photoIndex not found, returning to the first photo.");
- cameraRoll.ptr.update();
- photoIndex = 0;
- getPhoto();
+ if (response.content == null) {
+ drawNextPhoto();
return;
}
-
- new ImageDecoder(response.photo.content.handle.h, (image) {
- if (image != null) {
- currentImage = image;
- print("view.scheduleFrame");
+ new ImageDecoder(response.content.handle.h, (frame) {
+ if (frame != null) {
+ image = frame;
view.scheduleFrame();
+ drawNextPhoto();
}
});
});
}
-bool handleEvent(Event event) {
- if (event.type == 'pointerdown') {
- return true;
- }
-
- if (event.type == 'pointerup') {
- photoIndex++;
- getPhoto();
- return true;
- }
-
- return false;
-}
-
void main() {
- embedder.connectToService("mojo:camera_roll", cameraRoll);
view.setFrameCallback(beginFrame);
- view.setEventCallback(handleEvent);
- getPhoto();
-}
+ embedder.connectToService("mojo:camera", camera);
+ drawNextPhoto();
+}
« no previous file with comments | « examples/dart/camera_roll/lib/main.dart ('k') | examples/dart/camera_video/pubspec.lock » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698