I want to edit the photo that was just taken by the camera in my app. Got everything working in terms of taking a picture and saving that picture to the gallery; however, I want to get that picture before saving it so I can overlay an logo on it. My idea was running this bit of code in activity result:
/* Decode the JPEG file into a Bitmap */
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
then creating another bitmap with my logo and overlay that on the first bitmap. However the picture and drawable source are too big to decode into a bitmap and I get an OutOfMemoryError. I don't want to scale down my images, because it must be a high res image. What's the way to go now?
Set Android:LargeHeap="true" option in the Manifest file. And allow image loading action only when you have enough available memory. (this param is available I think only since Android 3.0)
There is no magic. If image exceeds available memory, then you could read and edit parts of image. But it's not the most convenient way to process images.
Related
I am working on an Android app functionality where I click a button and get the choice to make a photo with the camera or to load a photo from storage.
For making a photo I am using the command
myBitmap = (Bitmap) data.getExtras().get("data");
For loading from storage I am using the comman
myBitmap = BitmapFactory.decodeFile(PATH);
Now I am trying the following: first I choose to make a photo and display it, then I choose from storage but I choose the photo I just made before and display it. In both cases I resize to 200x200 before displaying.
However the results look very different. Probably in one case nearest neighboor downsampling is used and in the other linear downsampling is used. However I don't find proper documentation.
How can I find out what downsampling is used and change it so that in both cases the same is used and the image displays looks the same?
Thank you.
P.S.: in case of decodeFile I found that options can be provided to the command however no idea which kind of options.
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 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
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
I want to be able to take a snapshot of a preview camera screen being displayed on a SurfaceView. I know it has something to do with the onPreviewFrame() method and this returns a byte array in YUV format but I have no idea how to call the onPreviewFrame() method on it's own.
I have used it in conjunction with Camera.setPreviewCallback() but this is a continuous thing that keeps generating the image, I need it to do it once on an onClick(), to pretty much take a photo without making the preview window stop. Any ideas?
For anybody else with a similar problem to this I solved it by using the setOneShotPreviewCallback() method on the camera object to give me a byte[] with the information for the image. with that its can be used to create a YUV and then compressed to bitmap or whatever you need.
Capture the preview image into a canvas and hold a lock to it. You can then easily save to a BitMap
Refer this post for complete explanation with sample code
http://www.anddev.org/using_camerapreview_to_save_a_picture_on_disk-t226.html