Prevent Bitmap Too Large To Be Uploaded Into A Texture Android
Solution 1:
I came across the same problem and came up with a one liner solution for this problem here:
Picasso.with(context).load(new File(path/to/File)).fit().centerCrop().into(imageView);
Solution 2:
i just created a if else function to check if the image is bigger than 1M pixels here's the sample code:
publicvoidonActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
UriselectedImageUri= data.getData();
selectedImagePath = getPath(selectedImageUri);
BitmapFactory.Optionsoptions=newBitmapFactory.Options();
options.inSampleSize = 4;
Bitmapbitmap= BitmapFactory.decodeFile(selectedImagePath);
intheight= bitmap.getHeight(), width = bitmap.getWidth();
if (height > 1280 && width > 960){
Bitmapimgbitmap= BitmapFactory.decodeFile(selectedImagePath, options);
imageView.setImageBitmap(imgbitmap);
System.out.println("Need to resize");
}else {
imageView.setImageBitmap(bitmap);
System.out.println("WORKS");
}
Solution 3:
Google provided a training how to do that. Download the sample from Displaying Bitmaps Efficiently
Take a look to ImageResizer class. ImageResizer.decodeSampledBitmapFrom* use this method to get downscaled image.
Solution 4:
This is the code I used to rectify my problem of fitting an image of size 3120x4196 resolution in an image view of 4096x4096 resolution. Here ImageViewId is the id of the image view created in the main layout and ImageFileLocation is the path of the image which is to be resized.
ImageView imageView=(ImageView)findViewById(R.id.ImageViewId);
Bitmap d=BitmapFactory.decodeFile(ImageFileLcation);
intnewHeight= (int) ( d.getHeight() * (512.0 / d.getWidth()) );
BitmapputImage= Bitmap.createScaledBitmap(d, 512, newHeight, true);
imageView.setImageBitmap(putImage);
Solution 5:
You don't need to load the whole image, cause it's too large and probably your phone won't able to show the full bitmap pixels. You need to scale it first according to your device screen size. This is the best method that I found and it works pretty good: Android: Resize a large bitmap file to scaled output file
Post a Comment for "Prevent Bitmap Too Large To Be Uploaded Into A Texture Android"