Every image in android should be treated as a bitmap

2

I was having a problem uploading images in a TextView , when I came across a pretty dumb question, rs, would anyone know how to respond?

Next, I was trying to load a large (high-resolution) image as a background of a TextView , so I figured I'd have to resize the image to give it no problem.
So far so good, but I wondered, after all in android the whole image is a bitmap ???

Because I was loading the .jpg image of the drawable folder, direct as resource ( txt.setBackgroundResource() ) was not even using the Bitmap class, however in the error logcat "problems loading bitmap" (something like this).

So the question is, does it 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 dumb question, but if anyone can clarify it, I appreciate it. And also, no matter where the image comes from, should I always resize it like a bitmap?

    
asked by anonymous 06.08.2016 / 15:53

1 answer

4
  

Should any image in android be treated as a bitmap?

It depends.

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

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

No , because most methods accept as a Drawable parameter. A Drawable is a general abstraction for "something that can be drawn." It can take a variety of forms, including 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);  

Read in the Android documentation:

06.08.2016 / 16:59