App Crashes On Converting A Bitmap Of Png Image
public Bitmap getResizedBitmap(Bitmap bm, int newWidth) { int newHeight; int width = bm.getWidth(); int height = bm.getHeight(); double aspect_ratio = width/height;
Solution 1:
you can try below code to solve your problem
public class BitmapConvert extends AppCompatActivity { Bitmap bmp;
ImageView imageview_convert;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bitmap_convert);
imageview_convert= (ImageView) findViewById(R.id.imageview_convert);
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.nature);
imageview_convert.setImageBitmap(getResizedBitmap(bmp,300,200));
}
public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
intwidth= bm.getWidth();
intheight= bm.getHeight();
floatscaleWidth= ((float) newWidth) / width;
floatscaleHeight= ((float) newHeight) / height;
Matrixmatrix=newMatrix();
matrix.postScale(scaleWidth, scaleHeight);
BitmapresizedBitmap= Bitmap.createBitmap(
bm, 0, 0, width, height, matrix, false);
ByteArrayOutputStreambyteArrayOutputStream=newByteArrayOutputStream();
resizedBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
return resizedBitmap;
}
}
Post a Comment for "App Crashes On Converting A Bitmap Of Png Image"