I have a small Andriod application with a sub function that searches green pixels in a PNG file.
The program first processes the file:
private Bitmap buildSource(Context context) {
Paint paint = new Paint();
Logger.info("buildSource");
Bitmap form = BitmapFactory.decodeResource(context.getResources(),
R.drawable.form);
// float d = context.getResources().getDisplayMetrics().density;
Bitmap source = Bitmap.createBitmap(form.getWidth(), form.getHeight(),
Config.ARGB_8888);
Canvas canvas = new Canvas(source);
canvas.drawBitmap(form, 0, 0, paint);
form.recycle();
Logger.info("buildSource done " + source);
}
And then it searches for green pixels:
for (int y = 0; y < mSource.getHeight(); y++) {
for (int x = source.getWidth() - 1; x > 0; x--) {
int pixel = source.getPixel(x, y);
int green = Color.green(pixel);
int red = Color.red(pixel);
if (0 == red && green > 210 && green < 220) {
// Save pixel position
}
For some reason on a specific machine I'm running this code doesn't work,
when I print out the pixels one by one, no pixel matches the condition that red
=0
and green is ~215
. This worked fine up until now.
The image itself is attached:
I'm quite new to Android programming so I'm a bit stuck. Would appreciate any help.
Update: I've saved the source bitmap and the form bitmap to the gallery (Android programming is fun). When I open the images, I clearly see that the green pixels were replaced with gray one. is there some kind of background filter I should adjust? Thanks
Attached is the form picture: