Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

draw only a portion of a Drawable/Bitmap

I was wondering if it is possible to draw only a portion of a bitmap after it is loaded into memory without creating a new Bitmap. I see Drawable has a setBounds method but im not sure if it only draws the area set or just resizes the entire image. Thank you.

like image 958
jfisk Avatar asked Dec 21 '10 21:12

jfisk


People also ask

How do I make a drawable Bitmap?

This example demonstrates how do I convert Drawable to a Bitmap in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do you draw a Bitmap?

To draw on a bitmap, use the image control's canvas and attach the mouse-event handlers to the appropriate events in the image control. Typically, you would use region operations (fills, rectangles, polylines, and so on). These are fast and efficient methods of drawing.

What is BitmapDrawable?

android.graphics.drawable.BitmapDrawable. A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. You can create a BitmapDrawable from a file path, an input stream, through XML inflation, or from a Bitmap object. It can be defined in an XML file with the <bitmap> element.

What is the preferred image format for the Drawable?

Supported file types are PNG (preferred), JPG (acceptable), and GIF (discouraged).


1 Answers

Assuming you have a main canvas to draw to, you can use one of the drawBitmap methods of the Canvas class to draw a subset of the loaded bitmap.

public void drawBitmap (Bitmap bitmap, Rect src, Rect dst, Paint paint)

like image 135
Will Kru Avatar answered Sep 21 '22 11:09

Will Kru