如何改变某些像素的位图android的颜色 [英] how to change the color of certain pixels in bitmap android
问题描述
我,我想改变某些像素的位图。我已经得到了从位图中的数据到一个数组,但如何将我设置在阵列中的像素颜色?
感谢
INT []像素=新INT [myBitmap.getHeight()* myBitmap.getWidth()];
myBitmap.getPixels(像素,0,myBitmap.getWidth(),0,0,myBitmap.getWidth(),myBitmap.getHeight());
的for(int i = 0; I< 500;我++){
//Log.e(TAG,像素+ I +像素[I]);
要设置在像素像素的颜色
阵列,从Android的的静态方法获取值颜色类,并将它们分配到阵列。当您完成后,使用的setPixels
的像素复制回位。
例如,要打开第五行位图蓝色的:
进口android.graphics.Color;
INT []个像素=新INT [myBitmap.getHeight()* myBitmap.getWidth()];
myBitmap.getPixels(像素,0,myBitmap.getWidth(),0,0,myBitmap.getWidth(),myBitmap.getHeight());
的for(int i = 0; I< myBitmap.getWidth()* 5;我++)
像素[i] = Color.BLUE;
myBitmap.setPixels(像素,0,myBitmap.getWidth(),0,0,myBitmap.getWidth(),myBitmap.getHeight());
您也可以在一个位图对象,一个像素的颜色在一个时间,而不必设立一个像素缓冲区对setPixel()方法:
myBitmap.setPixel(X,Y,Color.rgb(45,127,0));
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]);
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, use setPixels
to copy the pixels back to the bitmap.
For example, to turn the first five rows of the bitmap blue:
import android.graphics.Color;
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<myBitmap.getWidth()*5; i++)
pixels[i] = Color.BLUE;
myBitmap.setPixels(pixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight());
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:
myBitmap.setPixel(x, y, Color.rgb(45, 127, 0));
这篇关于如何改变某些像素的位图android的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!