securesmartcam / app / src / main / java / org / witness / obscuracam / photo / filters / MaskObscure.java @ 41590feb
History | View | Annotate | Download (2.19 KB)
1 |
/*
|
---|---|
2 |
* This ObscureMethod paints the "anon.jpg" over the region
|
3 |
*/
|
4 |
|
5 |
package org.witness.obscuracam.photo.filters; |
6 |
|
7 |
import java.io.BufferedInputStream; |
8 |
import java.io.IOException; |
9 |
import java.io.InputStream; |
10 |
import java.util.Properties; |
11 |
|
12 |
import android.content.Context; |
13 |
import android.content.res.AssetManager; |
14 |
import android.graphics.Bitmap; |
15 |
import android.graphics.BitmapFactory; |
16 |
import android.graphics.Canvas; |
17 |
import android.graphics.Paint; |
18 |
import android.graphics.RectF; |
19 |
import android.util.Log; |
20 |
|
21 |
public class MaskObscure implements RegionProcesser { |
22 |
|
23 |
Bitmap _bitmap; |
24 |
Paint _painter;
|
25 |
Context _context;
|
26 |
|
27 |
Properties mProps;
|
28 |
|
29 |
Bitmap mask; |
30 |
|
31 |
String[] maskArray = {"mask.png","MrSmileyFace.png","lucha.png"}; |
32 |
int maskArrayIdx = -1; |
33 |
|
34 |
public MaskObscure(Context context, Paint painter) { |
35 |
|
36 |
_painter = painter; |
37 |
_context = context; |
38 |
|
39 |
mProps = new Properties(); |
40 |
|
41 |
mProps.put("obfuscationType", this.getClass().getName()); |
42 |
|
43 |
rotateMask(); |
44 |
} |
45 |
|
46 |
public void rotateMask () |
47 |
{ |
48 |
try
|
49 |
{ |
50 |
|
51 |
maskArrayIdx++; |
52 |
|
53 |
if (maskArrayIdx > maskArray.length-1) |
54 |
maskArrayIdx = 0;
|
55 |
|
56 |
mProps.put("path", maskArray[maskArrayIdx]);
|
57 |
|
58 |
mask = loadBitmap(_context,mProps.getProperty("path"));
|
59 |
|
60 |
} |
61 |
catch (IOException e) |
62 |
{ |
63 |
Log.e("anon",e.toString(),e);
|
64 |
} |
65 |
|
66 |
} |
67 |
|
68 |
public void processRegion(RectF rect, Canvas canvas, Bitmap bitmap) { |
69 |
|
70 |
_bitmap = bitmap; |
71 |
|
72 |
// return properties and data as a map
|
73 |
mProps.put("initialCoordinates", "[" + rect.top + "," + rect.left + "]"); |
74 |
mProps.put("regionWidth", Float.toString(Math.abs(rect.left - rect.right))); |
75 |
mProps.put("regionHeight", Float.toString(Math.abs(rect.top - rect.bottom))); |
76 |
|
77 |
canvas.drawBitmap(mask, null, rect, _painter);
|
78 |
} |
79 |
|
80 |
|
81 |
public static Bitmap loadBitmap(Context context, String filename) throws IOException |
82 |
{ |
83 |
AssetManager assets = context.getResources().getAssets(); |
84 |
InputStream buf = new BufferedInputStream((assets.open(filename))); |
85 |
Bitmap bitmap = BitmapFactory.decodeStream(buf); |
86 |
return bitmap;
|
87 |
} |
88 |
|
89 |
public Properties getProperties() |
90 |
{ |
91 |
return mProps;
|
92 |
} |
93 |
|
94 |
public void setProperties(Properties props) |
95 |
{ |
96 |
mProps = props; |
97 |
} |
98 |
|
99 |
@Override
|
100 |
public Bitmap getBitmap() {
|
101 |
// TODO Auto-generated method stub
|
102 |
return null; |
103 |
} |
104 |
} |
105 |
|
106 |
|
107 |
|