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

Side by Side Diff: examples/dart/camera_roll/camera_roll.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: remove stale files. 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 unified diff | Download patch
OLDNEW
(Empty)
1 #!mojo sky_viewer.mojo
2 // Copyright 2015 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 // To run: mojo/devtools/common/mojo_run --sky \
7 // examples/dart/camera_roll/camera_roll.dart --android
8 // This example makes use of mojo:camera_roll which is available only when
9 // running on Android.
10
11 import 'dart:async';
12 import 'dart:sky';
13
14 import 'package:mojom/mojo/camera_roll.mojom.dart';
15 import 'package:sky/mojo/embedder.dart';
16
17 final CameraRollServiceProxy cameraRoll = new CameraRollServiceProxy.unbound();
18 int photoIndex = 0;
19
20 Picture draw(Image image) {
21 PictureRecorder canvas = new PictureRecorder(view.width, view.height);
22 Paint paint = new Paint()..color = const Color.fromARGB(255, 0, 255, 0);
23 canvas.scale(view.width / image.width, view.height / image.height);
24 canvas.drawImage(image, 0.0, 0.0, paint);
25 return canvas.endRecording();
26 }
27
28 void drawNextPhoto() {
29 var future = cameraRoll.ptr.getPhoto(photoIndex);
30 future.then((response) {
31 if (response.photo == null) {
32 cameraRoll.ptr.update();
33 photoIndex = 0;
34 drawNextPhoto();
35 return;
36 }
37
38 new ImageDecoder(response.photo.content.handle.h, (image) {
39 if (image != null) {
40 view.picture = draw(image);
41 view.scheduleFrame();
42 }
43 });
44 });
45 }
46
47 bool handleEvent(Event event) {
48 if (event.type == "pointerdown") {
49 return true;
50 }
51
52 if (event.type == "pointerup") {
53 photoIndex++;
54 drawNextPhoto();
55 return true;
56 }
57
58 return false;
59 }
60
61 void main() {
62 embedder.connectToService("mojo:camera_roll", cameraRoll);
63 view.setEventCallback(handleEvent);
64 drawNextPhoto();
65 }
OLDNEW
« no previous file with comments | « no previous file | examples/dart/camera_roll/lib/main.dart » ('j') | examples/dart/device_info/lib/main.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698