dharmendra
dharmendra

Reputation: 7881

Capture partial part of canvas to use it as Bitmap

i am working on one stuff in which i want to use some part of the canvas as bitmap

. here i have attached on image for that . i want a bitmap core of rectangle (which has wight Stork)

here is a Algorithm of my program .

1: create a canvas .

2: draw a color picker on canvas .

3: draw a rectangle on a canvas.

now i want to use this rectangle as a bitmap ..

so is there any way to capture a bitmap using a canvas ? (i heard about Picture class to capture a canvas , i don't know its relevant to this scenario )

enter image here .

Upvotes: 3

Views: 2176

Answers (1)

Samuel
Samuel

Reputation: 17171

All canvas is is a wrapper to a bitmap that exposes useful drawing functions. So you can create a canvas with a bitmap, then call createBitmap() on that bitmap to just get the small rectangle. Below is an outline of the code.

Bitmap bitmap = Bitmap.createBitmap(/*screen width*/, /*screen height*/);
Canvas canvas = new Canvas(bitmap);
// . . .
// Draw color picker
// . . .
Bitmap selectedRectangle = Bitmap.createBitmap(bitmap, /*x*/, /*y*/, /*rectWidth*/, /*rectHeight*/);

Upvotes: 8

Related Questions