Android :: Use BitmapFactory.decodeStream To Specify Size Of Output Bitmap?
Jul 8, 2009
I have the following code which I tried to build a Bitmap from an input stream and I want my output bitmap to be 20 x 20:
BitmapFactory.Options opts = new BitmapFactory.Options(); opts.outHeight = 20; opts.outWidth = 20;
InputStream stream = // an input stream to my image Bitmap bm = BitmapFactory.decodeStream(stream, null, opts);
But when I tried it, I do get a bitmap from the inputstream, but it does not scale it to 20x20 which I specified in the BitmapFactory.Options.
View 2 Replies
Oct 3, 2009
I have an activity which performs an image search, the results (URLs of thumbnails on the web) are rendered in a GridView. My GridView adapter class delegates creating the actual Bitmaps to an AsyncTask that loops to sequentially fetch the image content from each URL using HTTPClient, and creates the Bitmaps using:
BitmapFactory.decodeStream(entity.getContent()).
I found that the above method sometimes returns "null" silently instead of creating a Bitmap. The occurrences appear to correlate with larger stream sizes (I check this by logging entity.getContentLength()). However, if I put a breakpoint just prior to the decodeStream call & then resume immediately every time I hit it (i.e. pause briefly on each iteration), the Bitmaps are created perfectly every time. All the images are quite small (most <10K), so the download & decodeStream happens fairly quickly. There are never more than 10 images processed in one AsyncTask.
View 6 Replies
View Related
May 7, 2010
Is the BitmapFactory.decodeStream method thread safe?
View 2 Replies
View Related
Mar 23, 2010
I'm having issues with BitmapFactory.decodeStream(inputStream). When using it without options, it will return an image. But when I use it with options as in .decodeStream(inputStream, null, options) it never returns Bitmaps. What I'm trying to do is to downsample a Bitmap before I actually load it to save memory.
I've read some good guides, but none using .decodeStream.........................
View 2 Replies
View Related
Aug 30, 2010
I'm building an android app and I'm currently having trouble retrieving a bitmap from an URL.
Here is the code I'm using :
CODE:..........
Everything works fine when the picture's write but when some bytes are wrong, result gets null. I think it's basically expectable as it's written this in the doc of BitmapFactory.decodeStream :
If the input stream is null, or cannot be used to decode a bitmap, the function returns null. The stream's position will be where ever it was after the encoded data was read.
The problem is, my wrong picture is well interpreted by my web browser and I can do so on iPhone platform.
Is there a way to sort of ignore those wrong pixels? maybe with the option parameter?
View 1 Replies
View Related
Jan 30, 2010
I am working on an app that displays photos which are downloaded from Flickr. I obtain a Bitmap object from a byte array, which in turn is read from the relevant Flickr URL, as follows: Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); The problem is that the resulting bitmap is pixelated and I can't figure out why. To demonstrate, here is an example of a picture created via BitmapFactory.decodeByteArray versus the original picture obtained directly from the relevant Flickr URL:...
View 6 Replies
View Related
May 20, 2009
I'm using the Camera.PreviewCallback.onPreviewFrame to try to generate a bitmap from the byte array passed to that method. If I use BitmapFactory.decodByteArray it returns null. I'm assuming that the array is correctly formatted since the data just comes right from the camera, so what could the problem be?
View 9 Replies
View Related
Sep 23, 2010
So I'm loading images from a web service, but the size of the images are sometimes smaller or bigger than other images and the visualization looks silly when I put them in a ListView in android. I'd like to fix the size of my ImageView so that it only shows a portion of the image if it's larger than a preset amount. I've tried everything I can think of setting the setMaxWidth/setMaxHeight, setting the scale type to centerCrop, using ClipableDrawable wrapping my BitmapDrawable, setting using Drawable.setBounds(). I've tried setting in the XML and programmatically, but neither worked. I'm very surprised setting max width/height didn't do anything. Below is the XML I'm using ImageView definition in my layout file
View 1 Replies
View Related
Nov 16, 2010
I learned from several discussions of this group that BitmapFactory.decodeFile() allocates heap memory outside of the "java heap". My app receives encrypted files from a remote server. Decoding those files needs a lot of heap space. After finishing this decoding step most of the allocated heap space will be freed by the GC. But the (total) heap size - as displayed by the DDM - remains large. In this situation there is not enough heap space outside of the "Java heap" to decode even medium sized image files using BitmapFactory.decodeFile(). At the moment I limit the size of encrypted files to ensure that the Java heap space never increases to more than 10 MB. This ensures that there is enough memory for BitmapFactory.decodeFile(). But this is not very elegant.
Is it possible to tell the dalvik-vm to reduce the (total) heap size to have more space for decoding images or is there another solution?
View 6 Replies
View Related
Mar 1, 2010
Some of you may met the same problem, I was using BitmapFactory.decodeStream, and got this exception: Code...
I know the reason is because the BitmapFactory is trying to decode an uncompressed version of a big image(in my situation, jpg). I can use BitmapFactory.Options.inSampleSize to fix it. but my question is what's the maximum size that VM would like to allocate for loading a image with BitmapFactory? so I can do some scale before it loads.
View 2 Replies
View Related
Jul 11, 2010
I've tried recording video using MediaRecorder API but the file that gets saved each time is of 0 bytes.
I use the MediaRecorder recorder = new MediaRecorder(); ad then recorder.setVideoSource . . .recorder.prepare() to generate the preview and when the user clicks record, i say recorder.start() but the file recorded is of 0 bytes. And after some time, recorder.stop() -on user click that is.
View 2 Replies
View Related
Nov 17, 2010
I would like to change the height and width of the image. Displays the image using the canvas: How to change the size of the bitmap?
View 1 Replies
View Related
Jan 21, 2009
I would like to set the size of a Bitmap, there are no setWidth() or setHeight() so I don't know how to do this...
View 2 Replies
View Related
Jul 26, 2010
I have a large bitmap (say 3888x2592) in a file. Now, I want to resize that bitmap to 800x533 and save it to another file.I normally would scale the bitmap by calling Bitmap.createBitmap method but it needs a source bitmap as the first argument, which I can't provide because loading the original image into a Bitmap object would of course exceed the memory (see here, for example).Is there a way to read a large image file with 10MP or more and save it to a new image file, resized to a specific new width and height, without getting an OutOfMemory exception?I also tried BitmapFactory.decodeFile(file, options) and setting the Options.outHeight and Options.outWidth values manually to 800 and 533, but it doesn't work that way.
View 4 Replies
View Related
Jul 6, 2010
I'm writing a Music application and I have already gotten the album arts. However, they came up in various sizes. So, how do I standardized the size of the returned bitmap ?
View 1 Replies
View Related
Jan 23, 2009
I've problem with memory of the bitmaps, I'm creating a lot of bitmaps and then releasing them by recycle() and after many retries I get:
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
How to get rid of this? The problem is that even if i close the activity (call onDestroy()), in next program run the bitmap memory is still allocated! (I've also android:clearTaskOnLaunch="true" in my manifest). This is horrible. Can anybody help me with that? I suspect that every application using BitmapFactory.decodeResource must get this exception in some call! Do you have any idea what's going on?
View 4 Replies
View Related
Oct 12, 2010
It immediately has trouble with memory. In the LogCat this error is displayed, java.lang.OutOfMemoryError: bitmap size exceeds VM budget. I'm using recycle () and System.gc () but I get the same error. My application, is pressing a button switches to the next image and the images are 854x480 Loading images from the SD Card. show the images as follows
Bitmap imageB; ImageView imgV;
imageB = BitmapFactory.decodeFile ("sdcard / img.png"); imgV.setImageBitmap (imageB);
Release is as follow.
@ Override protected void onDestroy () { super.onPause (); imageBG = null; System.gc ();
}
View 21 Replies
View Related
Mar 9, 2010
How can I determine/calculate the byte size of a bitmap (after decoding with BitmapFactory)? I need to know how much memory space it occupies, because I'm doing memory caching/management in my app. (file size is not enough, since these are jpg/png files).
View 1 Replies
View Related
Dec 18, 2009
I am doing the following in my app, which at times results in the above error.
Action 1: Button on Main activity calls all pictures using ACTION_PICK (results in a thumbnail view of all pictures on my phone). User picked image (URI) is then passed over to next activity where the image is displayed (ImageView) full screen. When I hit back, I go back to the main activity. If I try to open all pictures and pick a picture again, I get a FORCE CLOSE and the logCat data says "OutofMemoryError: bitmap size exceeds VM budget.
Action 2: I get the same error and FORCE CLOSE when I try to rotate the full-sized picture by changing phone orientation back and forth.
What am I supposed to do to save memory? I can't change the use case of my app... the user has to follow the above steps. How can I free up memory without having to change anything in my app.
View 6 Replies
View Related
Jun 16, 2010
In my application i have a functionality where a user can take photo and poet it to a web server or select a photo from galerry and upload.
So initially i used to get below exception for the very* first time* i used to select a photo:
Android: OutofMemoryError: bitmap size exceeds VM budget. then i used:
*options.inSampleSize = 2;*
Now the problem is im still getting the same exception *the only difference is im getting exception after 2-3 times.*
i.e im able to upload 2-3 (one by one) photos and then i get the exception. any suggestions?
View 2 Replies
View Related
Jul 22, 2009
I am using bitmap image that i have to rotate on fling. its actually a circular image that will act like a spin wheel. so image resolution is like 1000 x 1000 but when i rotate this image and redraw it android give me an exception " java.lang.OutOfMemoryError: bitmap size exceeds VM budget "
View 2 Replies
View Related
Apr 8, 2010
I'm writing game with a large amount of .png pictures. All worked fine. Than I added new activity with WebView and got memory shortage. After that I made some experiment - replace game .png images with ones that just fully filled with some color. As result memory shortage had gone.
But I suppose that Bitmap internally hold each pixel separately so such changes should have no effect. Maybe this because of initial images have alpha channel and my test images have not it?
But actually question is: Will decreasing .png images files sizes make some effect on decreasing usage of VM application heap or not?
View 3 Replies
View Related
Apr 26, 2009
While I'm trying to resize a photo (originally on a sd card), grabbed using :
InputStream openInputStream = contentResolver.openInputStream (photoUri);
I got the following stack trace when calling : Bitmap bitmap = BitmapFactory.decodeStream(openInputStream);
04-26 14:57:57.213: ERROR/dalvikvm-heap(349): 6291456-byte external allocation too large for this process. 04-26 14:57:57.224: ERROR/(349): VM won't let us allocate 6291456 bytes 04-26 14:57:57.234: DEBUG/skia(349): xxxxxxxxxxxxxxxxxxxx allocPixelRef failed 04-26 14:58:58.005: WARN/dalvikvm(349): threadid=15: thread exiting with uncaught exception (group=0x4000fe68) 04-26 14:58:58.014: ERROR/AndroidRuntime(349): Uncaught handler: thread Thread-19 exiting due to uncaught exception 04-26 14:58:58.153: ERROR/AndroidRuntime(349): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 04-26 14:58:58.153: ERROR/AndroidRuntime(349):at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 04-26 14:58:58.153: ERROR/AndroidRuntime(349):at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:304) 04-26 14:58:58.153: ERROR/AndroidRuntime(349):at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:149) 04-26 14:58:58.153: ERROR/AndroidRuntime(349):at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:174)
Do you know an alternative way to resize a picture ? without calling BitmapFactory ? and without getting such an exception ? Thanks in advance for your help Anthony
View 2 Replies
View Related
Nov 3, 2010
Posted my problem here too HERE: A beginner..Im doing a school map app.
First of all I have background with 4 buttons ( level3, level4, level5, level6) I try and click all the buttons, normally after clicking 3 of it, the next one will crash.(each level button goes into a level map, whereby clicking the room image buttons, I will enter into the gallery-imageswitcher)
I have at least 5 imageswitchers in each level maps,so that about over 20 imageswitcher galleries overall.
I did all my stuffs using DRAWABLES instead of BITMAPS.. I have tons and tons of images (because its a school map, show all the photos in my school, and all those backgrounds and imagebuttons)
I did some research, and those who have problems are those using bitmap. Some of the ways that can be solved is system.gc();, and bitmap.recycle...(not so sure how to use it though)
In my main background - starttour.java Code...
PS: I have tons of images in the app; I have at least 5 imageswitcher gallerys in each level, so that kinda adds up to over 20 imageswitchers in my app.
View 1 Replies
View Related
Oct 14, 2010
I have an ImageView that contains a bitmap. Now the bitmap can change size within a known range. This makes the surrounding views to relocate which I want to prevent. I've tried setting margins and padding for the ImageView but without success.
View 1 Replies
View Related
Aug 19, 2010
In my application am displaying a list of names and respective pictures ? I am picking picture from gallery through Durable.getFromPath(). ? am displaying list , some i encountered with out of memory error ? please help me to sort out this error?
View 1 Replies
View Related
Jun 15, 2010
I'm using ListView to display images which I provide through an ImageAdapter class. it works great on my device (and on many other devices which I tested it on), but somehow when I'm using the emulator and I'm long-pressing the up/down button - I'm getting an outOfMemory error after 10-15 seconds.
I tried clearing cache, canceling cache, etc. - nothing helped.
I know this crash is pretty rare (i couldn't reproduced it on any "real" device), but I can see on DDMS that "GC freed" are getting bigger during that long press and I can't find a way to clear them.
View 1 Replies
View Related
Jul 24, 2010
I am facing a problem of Out Of Memory Error that is bitmap size exceeds vm budget while changing the orientation of the Droid mobile (but not in any of other mobiles like Android normal and Android small).I am displaying 10 images in grid view, each one size is less than 20kb. If i insert 6 images then it doesn't arise that error.
View 1 Replies
View Related
Feb 6, 2014
I want to output Android's camera output to a PC through Wifi or Internet.
I cant find a suitable app for the purpose. I did try to find one.
Closest I came to was MirrorOp Sender, but it shares screen?
I have a Galaxy S3 I9300 and a Galaxy Mini S5570
View 6 Replies
View Related
Jul 21, 2010
I have a very large image and I only want to display a section the size of the display (no scaling), and the section should just be the center of the image. Because the image is very large I cannot read the entire image into memory and then crop it. This is what I have so far but it will give OutOfMemory for large images. Also I don't think inSampleSize applies because I want to crop the image, not lower the resolution.
Uri data = getIntent().getData();
Input Stream is = getContentResolver().openInputStream(data);
Bitmap bitmap = BitmapFactory.decodeStream(is, null, null);
Any help would be great?
View 3 Replies
View Related