Reputation: 351
I have an app that takes a picture, assigns it to an imageview and then uploads it to a parse server. The problem is that I need the images to be 200 x 200 px before upload. Is there a way to do this programatically? this is my function so far:
public void Myfunction (){
//image
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 40, baos);
byte[] imageInByte = baos.toByteArray();
ParseFile file = new ParseFile("myimage.jpg",imageInByte);
Could anyone help me please?
Upvotes: 2
Views: 4587
Reputation: 57203
To scale bitmap down before compress, add
bitmap = Bitmap.createScaledBitmap(bitmap, 200, 200, false));
If your bitmap is not square, you probably want to crop it before scaling
Upvotes: 4