I wanted to write a simple processing function.
It should run like this:
- Load a Jpeg
- Convert it to Bitmap
- save bitmap as byte array
- process
- data convert back to bitmap show Image.
public class MainActivity extends Activity {
ImageView imgView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgView = (ImageView) findViewById(R.id.imageView1);
AssetFileDescriptor asf;
String filename = Environment.getExternalStorageDirectory() + "/Test/"
+ "DSC00751.JPG";
Bitmap map = BitmapFactory.decodeFile(filename);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
// Convert image so it can be stored in byteArray
map.compress(CompressFormat.JPEG, 100, bout);
byte[] array = bout.toByteArray();
// Process image.
for (int i = 0; i < array.length; i++) {
if (array[i] < 0) {
array[i] = (byte) 200;
}
}
// Convert result and display
Bitmap bmp = BitmapFactory.decodeByteArray(array, 0, array.length);
imgView.setImageBitmap(bmp);
Toast.makeText(getApplicationContext(), "done", Toast.LENGTH_SHORT).show();
}
I get a whitescreen in return. No matter how my processing code looks like.
I tried using foreach(byte b : array) before, but this always returned the original image.
What am I doing wrong?
in this code you are changing image bytes!! so thats why it appears white!!
what else?
anyway, if you need to process an image you need to do it like that :
now you have the pixels array of the image (int[])