Every image on android should be treated as a bitmap

Asked

Viewed 1,983 times

2

I was having a problem with uploading images into one Textview, when I came across a very stupid question, rs, someone would know to answer?

Next, I was trying to upload a large (high resolution) image like background of a Textview, then I discovered that I would have to resize the image to not give problem.
So far so good, but I wondered, after all on android every image is a bitmap???

Because it was loading the image . jpg from the drawable folder, direct as resource (txt.setBackgroundResource()) I wasn’t even wearing the class Bitmap, however at logcat in error said "problems loading bitmap" (something like that).

So the question is: it doesn’t matter if I’m working with a drawable (R.drawable.img), an image from a url, or a bitmap, android, internally will work/transform, all in bitmap?

I know it’s a stupid question, but if anyone can enlighten me, I’d appreciate it. And also, no matter where the image comes from, I should always resize it like a bitmap?

  • See how the question became much easier to read after my editing. As it was, my first reaction was not even to read it. See here the resources you can use to format questions and answers.

1 answer

4


Every image on android should be treated as a bitmap?

Depends.

Yes, because Bitmap is the class of choice to work with images whose format represents a map of bits.
A map of bits is a bit array that specifies the color of each pixel in a rectangular pixel array.

There are several formats (of file) to represent this map, the Bitmap supports JPEG, PNG and Webp(Android 4.0+).

Not, because most methods accept as a parameter a Drawable.
A Drawable is a general abstraction for "something that can be drawn." It can take a variety of forms, among them that of a Bitmap.

To create a Bitmap from a Drawable use:

Bitmap bipmap = BitmapFactory.decodeResource(context.getResources(),
                                             R.drawable.icon_resource);

To create a Drawable from a Bitmap use:

Drawable drawable = new BitmapDrawable(getResources(), bitmap);  

Reading in the Android documentation:

  • Hi, thank you, thank you. Only + 1 thing, if I should check sp all imgs (p/ resize them) and this can only be done through bitmap, it is not + easy already work sp using bitmap and create a utility method q make this resizing?

  • If images exist in your application (res/drawable folder) they should already be placed there with the desired dimensions. If they come from files or from the web and if they are large, they should be resized. In the first case use Drawable in the second Bitmap. See in the documentation this and this

  • The images already exist yes. They are images downloaded from the internet (grd wallpapers resolution) q I will store in the drawable folder along with the app. However my doubt is: if it is no use I store an img of 6000px wide for ex, because the android will not be able to display even, with what resolution I should leave this img p/ put in the xxhdpi folder (considering only this) so that it is good in qq dispositvo c/ xxhdpi resolution? That is to say that 6000px wide should turn px qts p/ be placed in xxhdpi folder?

  • It’s not easy to answer that. Start by answering this question: What size (width x length) do I want it to have on Android? Then read this as an introduction and this for something more complete.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.