Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using method -canvas.drawBitmap(bitmap, src, dst, paint)

Everytime I use this code nothing is drawn. I need to draw a bitmap inside of a specified rectangle.

canvas.drawBitmap(MyBitmap, null, rectangle, null) 

I've looked online but can't find much help.

like image 900
Kohler Fryer Avatar asked Mar 13 '12 20:03

Kohler Fryer


People also ask

What is bitmap density?

The pixel density of a bitmap layer affects the amount of pixels it contains, but not its apparent size in the scene. For example, if your scene resolution is set to 1920 x 1080 and your bitmap artwork's pixel density is 300%, its resolution will be 5760 x 3240.

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.

How do you make a bitmap on canvas?

Use the Canvas method public void drawBitmap (Bitmap bitmap, Rect src, RectF dst, Paint paint) . Set dst to the size of the rectangle you want the entire image to be scaled into. EDIT: Here's a possible implementation for drawing the bitmaps in squares across on the canvas.

What is bitmap in canvas?

Canvas is the place or medium where perfroms/executes the operation of drawing, and Bitmap is responsible for storing the pixel of the picture you draw.


1 Answers

EDIT


The original answer is incorrect. You can use the sourceRect to specify a part of a Bitmap to draw. It may be null, in which case the whole image will be used.

As per the fryer comment he was drawing beneath something, I'll add a note on that.

drawBitmap(bitmap, srcRect, destRect, paint) does not handle Z ordering (depth) and the order of calling draw on object matters.

If you have 3 shapes to be drawn, square, triangle and circle. If you want the square to be on top then it must be drawn last.


You're not specified any source, so its not drawn anything.

Example:

You have a Bitmap 100x100 pixels. You want to draw the whole Bitmap.

canvas.drawBitmap(MyBitmap, new Rect(0,0,100,100), rectangle, null); 

You want to draw only the left half of the bitmap.

canvas.drawBitmap(MyBitmap, new Rect(0,0,50,100), rectangle, null); 

You need to specify the source rect, the source rect can be a rectangle anywhere from 0,0 to the width,height of the bitmap.

like image 160
triggs Avatar answered Sep 30 '22 16:09

triggs