A bitmap factory creates Bitmap objects from various sources, including files, streams, and byte-arrays.
Questions tagged [bitmapfactory]
636 questions
97
votes
7 answers
Create a Bitmap/Drawable from file path
I'm trying to create a Bitmap or Drawable from existing file path.
String path = intent.getStringExtra("FilePath");
BitmapFactory.Options option = new BitmapFactory.Options();
option.inPreferredConfig =…

Nari Kim Shin
- 2,459
- 1
- 25
- 33
79
votes
6 answers
How to solve java.lang.OutOfMemoryError trouble in Android
Altough I have very small size image in drawable folder, I am getting this error from users. And I am not using any bitmap function in code. At least intentionally :)
java.lang.OutOfMemoryError
at…

Utku Soytaş
- 1,475
- 2
- 19
- 30
57
votes
8 answers
How can I print an image on a Bluetooth printer in Android?
I have to print some data on thermal bluetooth printer, I'm doing with this:
String message="abcdef any message 12345";
byte[] send;
send = message.getBytes();
mService.write(send);
It works well for text, but not for images. I think I need to get…

Leonardo Sapuy
- 2,600
- 2
- 23
- 30
24
votes
4 answers
Optimal use of BitmapFactory.Options.inSampleSize for speed
Thanks to Schermvlieger for asking this question on anddev.org,
I'm just copying his question to SO as nobody replied on the other site and I'm also facing the same problem.
I was wondering what would be the optimal use of…

Labeeb Panampullan
- 34,521
- 28
- 94
- 112
22
votes
3 answers
Android how to scale an image with BitmapFactory Options
I want to decode an image from the SD card with BitmapFactory.decodeFile(path, options).
I also want images that are larger than 2048x2048 pixels to be scaled down to at most 2048x2048 (maintaining the proportions).
I could do this manually after…

saarraz1
- 2,999
- 6
- 29
- 44
21
votes
8 answers
Android: decodeFile always returns null for file in internal storage
I have a file saved locally into the application's private storage. I have verified it exists, however whenever I call BitmapFactory.decodeFile it always returns null.
If I save the file as a resource and use ImageView.setImageResource, it always…

James John McGuire 'Jahmic'
- 11,728
- 11
- 67
- 78
21
votes
6 answers
Bitmap allocation, using BitmapFactory.Options.inBitmap throws IllegalArgumentException
I get the next exception: Problem decoding into existing bitmap, when setting inBitmap to true;
Caused by: java.lang.IllegalArgumentException: Problem decoding into existing bitmap at…

sromku
- 4,663
- 1
- 36
- 37
19
votes
2 answers
bitmap.compress(Bitmap.CompressFormat.PNG, 0, fOut) making image size bigger than original
I want to compress the image taken from a camera to png format to make them smaller in size,
so I'm using this code:
compressedPictureFile = new File(imagePath);
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
FileOutputStream fOut = new…

Dany Y
- 6,833
- 6
- 46
- 83
18
votes
3 answers
Converting Bitmap in memory to Bitmap with Bitmap.Config.RGB_565
I have a loaded Bitmap which I would like to convert to set the config to Bitmap.Config.RGB_565. Is there a simple way of converting a Bitmap to this configuration after the Bitmap is already loaded into memory? For example, below I have a bitmap…

Euthyphro
- 700
- 1
- 9
- 26
17
votes
1 answer
Pre-guess size of Bitmap from the actual Uri, before scale-loading
If you have a Uri and you need the Bitmap, you could theoretically do this
Bitmap troublinglyLargeBmp =
MediaStore.Images.Media.getBitmap(
State.mainActivity.getContentResolver(), theUri );
but it will crash every time,
so you do this…

Fattie
- 27,874
- 70
- 431
- 719
13
votes
2 answers
Android: Which image format shall I use and why?
Im a beginner programmer, and my question is:
Which image format shall i use for my android app?
Descripton:
I only use illustrations, so the images are mostly background images, and some buttons, and i would like to know which is the best way to do…

Adam Varhegyi
- 11,307
- 33
- 124
- 222
13
votes
5 answers
BitmapFactory.Options.inBitmap causes tearing when switching ImageView bitmap often
I've encountered a situation where I have to display images in a slideshow that switches image very fast. The sheer number of images makes me want to store the JPEG data in memory and decode them when I want to display them. To ease on the Garbage…

Joakim Berglund
- 2,859
- 1
- 22
- 30
12
votes
4 answers
BitmapFactory returns bigger image than source
Hi i am creating a Bitmap from an png image named image.png. The image has the dimension 75 (width) x 92 (height). When I run this code:
Bitmap bitmap = BitmapFactory.decodeResource(this.context.getResources(), R.drawable.image
Log.d("image",…

Franziskus Karsunke
- 4,948
- 3
- 40
- 54
12
votes
4 answers
How to write Text on ImageView in android coding?
Hi I've been trying to write Numbers on Imageview. Images for N number of questions. If the user entered answer is correct, then it should be displayed with question number with tick mark image else question number with wrong mark image. I need to…

GOBINATH.M
- 663
- 2
- 12
- 24
11
votes
2 answers
Get size of Bitmap Android
Possible Duplicate:
Bitmap byte-size after decoding?
Is there anyway so I can get the size of this Bitmap?I've tried to use getByteCount() but I can't use it?
Bitmap bitmap = BitmapFactory.decodeByteArray(decryptedData , 0, decryptedData…

hardartcore
- 16,886
- 12
- 75
- 101