Android canvas change some pixels color

I have a Canvas object at start. I need to change color of some pixels depending on their current color. How can I do that in a proper way?

Details:

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


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

Call :

canvas.drawPoint(X, Y, paint);

Here is how you initalize Object of class android.graphics.Paint ie paint

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

Search more on this Link to change multiple pixels at different positions, there are lot many functions that will help you achieve what you want. Best luck :-)


There's probably a dozen ways to do this. If you want to do the Canvas approach, there's a way to draw to a Bitmap object. You can then draw the object to another Canvas. The Bitmap object may also have functions to modify pixels.

Bitmap also lets you get a copy into a buffer, and if you know about how pixels are stored, that would be a very fast way of image manipulation. I'm not sure if Canvas itself has that


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

链接地址: http://www.djcxy.com/p/64230.html

上一篇: 如何防止删除px.get()的唯一

下一篇: Android画布会改变一些像素的颜色