Using frame by frame animation with Universal Image Loader - android

Is there any good way to use frame by frame animation AnimationDrawable using UIL library. AnimationDrawable accept only BitmpaDrawable . Is there any way to convert quickly to bitmaps my images or any maybe there is method like imageLoader.getBitmap, I haven't find anything like that.
Please help , I would be very grateful for any help .
Edit I have my images in assets folder. Maybe there any way to get bitmap from cache or something else . I need open new activity , maybe several times . I need to show animation from files , but if I use decode it takes a lot of time to decode them . Please suggest something

If your images are resources you can use this for obtain Bitmap:
Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
R.drawable.icon_resource);
else, if you want donwload the image you can use this:
String name = c.getString(url);
URL urlAux = new URL(name);
ImageView prueba = (ImageView)v.findViewById(R.id.iv_prueba);
if (prueba != null) {
Bitmap bitmap =
BitmapFactory.decodeStream(urlAux.openConnection().getInputStream());
prueba.setImageBitmap(bitmap);
}
Hope it helps you.

Related

Convert colorDrawable to bitmap

I am trying to save the profile picture from Google login, and am kind of a noob at this, so I am doing it in a rather round-about way. There is likely a better way to do this, and if you know it please let me know. But I think there is an unasked question in my round-about way. SO - here we go.
String profilePicUrl = googleSignInAccount.getPhotoUrl().toString();
ImageView intermediaryIV = (ImageView)
findViewById(R.id.intermediary);
Glide.with(this).load(profilePicUrl).into(intermediaryIV);
ColorDrawable drawable = (ColorDrawable) intermediaryIV.getDrawable();
Bitmap toSaveBitmap = drawable.get; //??
savePicToInternalStorage(toSaveBitmap)
The Glide api (https://github.com/bumptech/glide) loads the image from google into an imageView, and then I grab the drawable from the imageview. But in this case I don't get a normal bitmapDrawable I get a colorDrawable which does not contain a .toBitmap() function. Which causes me a problem because I need to save a bitmap.
So the question is can I convert a colorDrawable to a bitmap?
Also, if you have a better way to save an image from google, would you link me to that in the comments? We can leave the actually post answer to the main question.
You can store the bitmap from the image view drawing cache.
iv.buildDrawingCache();
Bitmap bitmap=iv.getDrawingCache();

how to show buffered image in imageview

I'm new to android programming and currently doing research on QRcode using zxing.
I used zxing to encoding a string and now have the bufferedimage returned. Now I want to show this image in the imageview, but looks like that I need to convert it into bitmap first. Can someone tell me a way to do this?
Thank you!
Bitmap bitMapImage = BitmapFactory.decodeFile("bufferedImage.jpg");

Android ViewFlipper change background with image from URL how to

I'm trying to change a background image on my ViewFlipper... But can't get it to work... Do I have to download the image before set it to the ViewFlipper? .. I saw an example where the URL is used.. But I can't! .
this.vf.setBackgroundDrawable("http://path_to_background_image");
I found the solution myself...
Bitmap bg_img = BitmapFactory.decodeStream((InputStream) new
URL(webservice.getString("background_image_url")).getContent());
vf.setBackgroundDrawable(new BitmapDrawable(bg_img));

Save image to sdcard from imageview

I have listview having customized some textview and one imageview. When I long click on item I have store that item information to the database but the question is how to store image in sdcard and store the relevant path to the database. The image alread download as cache now I don't want to re-download that image.
Is there way to store that Image to the sdcard.
I am using this example to download the images for listview https://github.com/thest1/LazyList
Edit
I got solution
no need to extra process when using this example. Just store the web path of image into the database and pass that imageview into the ImageLoader object with path it'll use the cache images if the image was exist for same URL
No Need to extra process, Using this example it'll will care for future usage also for same URL of image. This will get from the cache directory if the image found that use that image otherwise download it and then use it.
If you use Prime the caching will be transparent, when you request the image again it will grab it from a memory cache if available or a disk cache automatically. It also is really easy to get images with.
You can save your bitmap which you get via Bitmap bitmap=memoryCache.get(url); using save-file-to-sd-card.
You can also get the bitmap from the ImageView(if you want) like:
//say your ImageView object is i;
i = (ImageView) findViewById(R.id.img);
Drawable d = i.getBackground();
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();

Android Bytes to Bitmap

I have this working just fine in our iPhone app, but am having problems in Android. I'm using the same urls/data in both apps. When I set my image in my ListView to the bitmap that came from the bytes, the image doesn't appear. The data is there. Here is the code where I assign the view:
if (camera.snapshot != null)
{
bMap = BitmapFactory.decodeByteArray(camera.snapshot, 0, camera.snapshot.length);
image.setImageBitmap(bMap);
}
This is where I convert the string data into bytes:
camera.snapshot = responseData.getBytes();
The images are PNG files. They come in about 4 times the size that I need them for the listview image but I would think they would size perfectly to the bounds I set the ImageView to be.
On iPhone I simply use NSData and then use a prebuilt method in ImageView to turn it into an image. It works perfectly! What am I missing here?
You probably need to use the 4-argument version of decodeByteArray: see http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeByteArray%28byte[],%20int,%20int,%20android.graphics.BitmapFactory.Options%29.
The options would depend on the type of PNG image, so that you might need to experiment with. For a generic PNG, maybe something like this?
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inDither = true;
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
You can see http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html and http://developer.android.com/reference/android/graphics/Bitmap.Config.html for more detail.
Everything is fine here. So you need to debug to try and find where else is the issue. i.e. is Camera.snapshot = null ? i.e. you might not be getting the data properly. Or there could also be an issue in the layouts to show the imageview. Try setting a predefined image to imageview and see if it is shown. This way you would be able to track the problem.

Categories

Resources