blob: 0d8cba80928ec5ee01614ba6621ccd8fa8bc337f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
package com.tomgibara.android.camera;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
// This is public-domain code generously supplied to the developer community
// by Tom Gibara, at http://www.tomgibara.com/android/camera-source
/**
* A CameraSource implementation that repeatedly captures a single bitmap.
*
* @author Tom
*
*/
public class BitmapCamera implements CameraSource {
private final Bitmap bitmap;
private final Rect bounds;
private final Paint paint = new Paint();
public BitmapCamera(Bitmap bitmap, int width, int height) {
this.bitmap = bitmap;
bounds = new Rect(0, 0, width, height);
paint.setFilterBitmap(true);
paint.setAntiAlias(true);
}
@Override
public int getWidth() {
return bounds.right;
}
@Override
public int getHeight() {
return bounds.bottom;
}
@Override
public boolean open() {
return true;
}
@Override
public boolean capture(Canvas canvas) {
if (
bounds.right == bitmap.width() &&
bounds.bottom == bitmap.height()) {
canvas.drawBitmap(bitmap, 0, 0, null);
} else {
canvas.drawBitmap(bitmap, null, bounds, paint);
}
return true;
}
@Override
public void close() {
/* nothing to do */
}
}
|