Downloading a png image - android

I need to retrieve a png image from the Internet. I have the correct URL pointing to the image, it's something like this:
So, I have my URL object like this:
URL url = new URL(methodThatLoadsTheStringPointingToMyURL());
An I can get a InputStream like this:
InputStream is = url.openStream();
However, the only way I know to decode it into a Drawable is by using BitmapDrawable constructor, and that kills the PNG transparency.
Is there any way to retain PNG transparency?

http://www.libpng.org/pub/png/libpng.html
The able link must help you out to address the problem of retaining the Transparency.
Its a standard Library to read and write png image data

Related

Android Glide load the SVG image directly from the string

I want to load svg image in Android using Glide. In fact Glide support such job and I found a sample https://github.com/bumptech/glide/tree/v3.6.0/samples/svg/src/main/java/com/bumptech/svgsample/app. The question is that I want to directly load the image from a string which is in svg format, not from the svg file. The string is received from network or selected from sqlite. Can someone help me? I have searched a long time but it seems no one meet such requirement.
Your question is unclear. You haven't been that clear on what part you are stuck on.
If you just need to get an InputStream from a String, then you can do:
InputStream stream = new ByteArrayInputStream(svgString.getBytes(StandardCharsets.UTF_8));

Using frame by frame animation with Universal Image Loader

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.

Display byte array of image in imageview

I am trying to show byte array of image from server inside the image view of an android activity. I am able to get the byte array correctly as sent from the server, but while converting it into bitmap it is always returning null. I have used the BitmapFactory.decode(byteArray,0, byteArray.length) for converting image byte array to bitmap which is returning null always.
Please help me solving this and tell me if there are any alternative.
Thanks in advance.
Well a better option is to use this. I used it to display images that is present on a server. Pretty fast
URL url = new URL(link);
InputStream picin = url.openStream();
Bitmap myBitmap = BitmapFactory.decodeStream(picin);
pic.setImageBitmap(myBitmap);
Where link points to the jpg image. Works for other image formats also.

How to get the picture's shooting time in android development?

String picPath = "/mnt/sdcard/yepcolor/sina.png";
Bitmap bitmap = BitmapFactory.decodeFile(picPath);
I know the 'picPath' of the picture.Now, I want to get the picture's shooting time,and what should I do?Thanks.
As far as I know, png files doesn't contain such information. If you are reading jpeg files, however, you can use ExifInterface.

android getting pictures from drawables

Bitmap picture = BitmapFactory.decodeResource(getResources(),R.drawable.phscale);
apart from above code any other ways to get the bitmap from drawables
If you get your png name as string, you could use the following:
int resID = getResources().getIdentifier("bug", "drawable", "org.anddev.android.testproject");
source
If you would like to have full control over resource bits, you'd better put it either in res/asset or res/raw folders and then get access to them as:
InputStream is=this.getResources().getAssets().open("drawable.png");
//
is=this.getResources().openRawResource(R.raw.myDrawable);
See th link
How to convert a Drawable to a Bitmap?

Categories

Resources