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.
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.
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.
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.
Supported file types are PNG (preferred), JPG (acceptable), and GIF (discouraged).
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With