I'm following this post to create nine patch drawable at run-time. I need to save the 9patch image on the internal/external memory, so that i can easily retrieve it's URI and assign it to an ImageView for example. Does anybody know how can I achieve this?
P.S. Bitmap.compress method won't work, because it will save the image as a regular (not 9patch) png file.
P.S. I know that I can serialize generated NinePatch object and save it to a file. But this way I can't assign it to a RemoteViews object (using RemoteViews.setImageViewUri method). So I need to save it as a real nine patch image.
You can store the image as Bitmap and then create a NinePatch using http://developer.android.com/reference/android/graphics/NinePatch.html#NinePatch(android.graphics.Bitmap, byte[])
Related
This is a different situation. I want to load a image file which has stored with different extension like 'photo.xyz' instead of 'photo.jpg or photo.png' using Picasso. to avoid image from gallery i am storing image like this. Please help me is there any option to show like this.
Neither Picasso nor Android (which does the actual image decoding) cares what the file name is. It can be anything. The type of the image is always determined from the first few bytes of the actual image data.
As a small workaround you can programmatically put .nomedia file into your app folder to prevent images to be cached by mediaserver and displayed in a Gallery app.
I am working on an a simple android application that stores objects in an array, and displays them to the user via a listview. Each object contains a photo and a single text field. For demonstration purposes, I would like to pre-populate this array with some hardcoded objects.
The trouble is that the images are typically acquired through the camera interface, and each object only stores the path to that image. I can add the hardcoded images as drawables, but then they don't have a file path. I could when the app is initialized, convert the drawables to bitmaps and save the bitmaps to the SD card, but that seems too complicated to be the correct answer...
Any ideas on the best way to get these images into file storage so that I refer to them via their URIs?
Thanks!
When you create your views in your adapter, have a ImageView in your layout and use a loader or custom AsyncTask to load the image in the background and have it update the ImageView instance once it has the data.
check the background from this on loading images from the network.
You acquire images from the camera but notice that when you do a resource chooser where mimetype = img/*, the selector just merges local camera(gallery) storage with other photo, content providers. An example of common chooser for photos is in 'Evernote' where you go to the composer view with the 2X2 grid and touch the 'attachment' icon... thats a photo chooser...
In other words , it helps to understand the general practice for managing photos and for presenting them in imageViews.
Typically, there is a lazyLoader that has an interface with args for the imgView and the URI of the image source. Under the covers on a call to 'loadImage(view, uri), the implementation checks the following:
is the bitmap already in a memCache?
the local file , that backs the bitmap, does it exist in the folder reserved for this purpose?
if none of above, go get the array of bytes for the img from across the network ( or in your case , get bytes from camera ).
Even though your question is a little different , IMO , the standard practices for images may apply and you may want to adapt one of the many libs for image presentation to your specific requirements.
I have Uri of some image at my external storage but it is too large. I have constructor further which accepts only File like parameter. How to make picture smaller adn get File from that ?
Well that depends on how you're displaying the picture. If you're simply going to show that picture in your layout, just size the ImageView element appropriately in your respective layout.xml file:
android:minHeight="your_value"
android:minWidth="your_value"
Also, don't forget to set the adjustViewBounds property as well:
android:adjustViewBounds="true"
If you're looking for something a bit more robust and you're concerned about the memory used to store the entire bitmap for display, then I'd look into using the BitmapFactory class and specifically the inSampleSize field.
This previous question also provides some background for you.
I want to read several NinePatch images from SD or from assets, thus not compiled, and there are no constructors/factories I can find to do the job. I've also tried the NinePatch tool source, but it uses internals of the image to do the job and doesn't use the Android classes...
Kenny.
Load your ninepatch image into a Bitmap object (there is many ways to do that, see http://developer.android.com/reference/android/graphics/BitmapFactory.html).
Load your chunk (created by 9patch software)
Then, use NinePatch (Bitmap bitmap, byte[] chunk, String srcName) constructor in order to create your NinePatch object.
I have a bitmap object. I want to overwrite a .png image under drawable folder with the bitmap object content. I need a sample code to do this.
Thanks in advance
You can't overwrite resources in your application.
You can instead write to the internal memory or the sdcard.