I have image saved in phone memory. I need to get some part of the entire image in desired resolution. I could possibly first downscale the entire image and then "decodeRegion" from it. Is there any way to "decodeDownScaledRegion" in one go rather than first downscaling original image and decoding region from it?
Maybe you could follow the document "Loading Large Bitmaps Efficiently" here:
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
Related
I have an image-only PDF file that looks like a scan of a really big page. Preview shows me that it is about 42x30 inches, and 3047x2160 pixelss. I guess it was scanned at 72dpi resolution.
I'm extracting this image with PDFBox by looking for instances of PDImageXObject, similar to https://stackoverflow.com/a/37664125/10026.
However, for this image, PDImageXObject.getWidth() and PDImageXObject.getHeight() give me 16928 and 12000, respectively. When I call PDImageXObject.getImage(), it creates an enormous BufferedImage in memory.
Is there a better way to get the image out of so that it keeps the original pixel size?
I need a bitmap to work with and I am provided an URI that is shared from another apps implicit intent. I currently work with
Bitmap btmp = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), urinormal);
but it takes up to half a second to create the bitmap. I need it to work as fast as possible, what can I do?
I can't find a way to reduce the quality of the bitmap, I can only apply BitmapFactory.options afterwards to create a smaller bitmap, but that doesn't help.
There can be many reasons why image loads slow. Slow connection, large file etc.
I would suggest you to use Glide, an image loading library for android.
GlideApp
.with(ctx)
.load(url)
.centerCrop()
.placeholder(R.drawable.loading_spinner)
.into(myImageView);
This will show a custom loading image until the image is loaded.
You will have to use Generated API of Glide to have GlideApp class though. Read the docs, there are many other cool features.
Hope it helps.
Probably the file size is too large. If it is large it takes the required time. You can do nothing about it.
If it takes around half seconds, you may want to perform the decoding using AsyncTask so that the UI won't freeze.
As you mentioned that you are developing a gallery type app. You may want to store the thumbnail of the bitmaps in the storage when loading them the first time. So next time your app can quickly decode the image from the thumbnail file. When you click on the image, you can load full size image from the original location.
As #faztp12 mentioned in his answer, you may also use some third party image loading libraries like Picasso or Glide to achieve the similar functionality.
I am working on an application where i need to load the server images in list. But the way of displaying images is bit different. I need to display image as it gets downloaded i.e. pixel by pixel. Initially the image sets as blur image than as it gets downloaded, its gets more sharper and results into the original image. If you want to see what i am talking about than you can refer to the below link:
Progressive Image Rendering
In this you can see the demo of the superior PNG style two-dimensional interlaced rendering(the second one). I goggled a lot but did not find any relevant answer to my query.
Any sort of help would be appreciable.
Thanks in advance.
Try Facebook's Freso project: http://frescolib.org/#streaming
If you use Glide, the library recommended by Google for loading images in Android, you can achieve this kind of behavior with .thumbnail this receives the fraction of the resolution you'll like your image to show while the full resolution finishes loading.
Glide.with( context )
.load( "image url" )
.thumbnail( 0.1f ) //rate of the full resoultion to show while loading
into( imageView ); //ImageView where you want to display the image
Here is a more extensive explanation of the library and the thumbnails:
https://futurestud.io/blog/glide-thumbnails
This is a bit of a followup to my last question: Canvas is drawing too slowly
Now that I can draw images more quickly, the problem I am faced with is that the actual loading of the images takes far too long.
In the app I am working on, the user is able to play back video frames (jpegs) in succession, as though he is viewing the video in realtime. I have been using BitmapFactory.decodeFile() to load each jpeg in a Bitmap. I'm unable to load all images at once since there are about 240 of them, and that would use up all of my heap space. What I have been doing is preloading up to 6 at a time into an array by way of a separate thread in order to cut down on the time it takes for each image to display.
Unfortunately, it takes somewhere between 50 and 90ms to load an image, and I need to show an image every 42ms. Is there a faster way to load images possibly?
For clarification, these images are in a folder on the SD card, and they are all 720x480 jpegs. I am sampling them at half that size to cut down on memory usage.
I ended up doing this quite a bit differently than I had originally envisioned. There was quite a bit to it, but here's the gist of how I achieved my goal:
All images are stored on SD card and written to one file (each image takes up X bytes in the file)
Use native code to read from and write to the image file
When requesting an image, I pass the index of the image in the list and a bitmap object (RGB_565) to the native code using a JNI wrapper
The native code locks the bitmap surface, writes pixel data (as a uint8_t**) directly to the bitmap, then unlocks it
The image is rendered to the screen
By doing it this way, I only needed to store one image in memory at a time, and I was able to bypass garbage collection (since the bitmap was only created once and then repopulated natively). I hope someone else might find this strategy useful.
Guess you already tried all methods in this tutorial http://www.higherpass.com/Android/Tutorials/Working-With-Images-In-Android/2/ and chosen the fastest. Maybe tweaking resizing can decrease loading time.
Best of all would of course be if you didn't have to resize the images at all. If you have full control of the images maybe you could try to pack them as sprites, see article http://www.droidnova.com/2d-sprite-animation-in-android,471.html
Is it possible to get the current quality of an existing image?
I want to load a JPEG and save it again without any change in quality and DPI. (I need to do some pixel manipulation before saving)
JPEG is a lossy format.
The direct way to do this, read the image, do what you need to do, reencode the image, will result in the image being slightly deteriorated.
That said, if that is fine, then you need to know that the way that quality works in JPEG encoding, is to determine how much information to keep about contrast. The less quality, the less sharp a transition you can have. In other words, this is not a single setting enclosed in the JPEG-file, but a setting determining the number of image data saved.
What you can do is to say that the final image need to be around the same size as the original. You can then encode the result at different quality settings and choose the one giving the image size you want.