Resize Android canvas by a few pixels

I have a Canvas object at the beginning. I need to change the color of some pixels depending on their current color. How can I do it right?

More details:

I have my own class extended from ImageView . In the onDraw(Canvas canvas) method, I draw something with a third-party class and have only the Canvas object with the result. After that I need to change the color of some pixels depending on their current color.

+7
source share
3 answers

Assuming you have an android.graphics.Canvas object called canvas and X and Y are the points where you want to change the pixel, so you go

Call:

 canvas.drawPoint(X, Y, paint); 

Here's how you initialize an Object of class android.graphics.Paint ie paint

 Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); 

More on this Link to change several pixels at different positions, there are many functions that will help you achieve what you want. Good luck :-)

+3
source

There are probably a dozen ways to do this. If you want to make a Canvas approach, you can use the Bitmap object. Then you can draw the object onto another canvas. A Bitmap object may also have functions for changing pixels.

A bitmap also allows you to get a copy to the buffer, and if you know how pixels are stored, this will be a very quick way to manipulate images. I'm not sure Canvas has this

+1
source

I recommend looking at a faster way to set the color of a bitmap (PNG) instead of pixel by pixel . It has a code for receiving and setting the colors of the bitmap image in pixels (in the question), as well as an alternative to the pixel approach (in the answer). Also possibly useful: Explanation of the getPixels method for a bitmap in Android .

0
source

All Articles