如何改变位图android中某些像素的颜色
我有一个位图,我想更改某些像素。我已将位图中的数据放入数组中,但是如何在该数组中设置像素颜色?
谢谢
int[] pixels = new int[myBitmap.getHeight()*myBitmap.getWidth()];
myBitmap.getPixels(pixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight());
for(int i =0; i<500;i++){
//Log.e(TAG, "pixel"+i +pixels[i]);
i've a bitmap that i want to change certain pixels. i've got the data from the bitmap into an array, but how would i set a pixels colour in that array?
thanks
int[] pixels = new int[myBitmap.getHeight()*myBitmap.getWidth()];
myBitmap.getPixels(pixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight());
for(int i =0; i<500;i++){
//Log.e(TAG, "pixel"+i +pixels[i]);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要设置
pixels
数组中像素的颜色,请从 Android Color 类并将它们分配到您的数组中。完成后,使用setPixels
将像素复制回位图。例如,要将位图的前五行变成蓝色:
您还可以一次在 Bitmap 对象中设置一个像素的颜色,而无需使用 setPixel() 方法设置像素缓冲区:
To set the colors of the pixels in your
pixels
array, get values from the static methods of Android's Color class and assign them into your array. When you're done, usesetPixels
to copy the pixels back to the bitmap.For example, to turn the first five rows of the bitmap blue:
You can also set a pixel's color in a Bitmap object one at a time without having to set up a pixel buffer with the setPixel() method: