3
我有一個位圖對象。當我使用getpixel()作爲位圖,並在setPixel之後爲該位圖對象使用時,像素值(顏色)不會改變。我使用imageview在背景圖像上填充顏色。主要問題是,我不能在同一區域的imageview上爲顏色填充顏色。當我在imageview上填充顏色時,那些區域不能用於填充另一種顏色。意思是我不更新imageview的填充顏色區域。下面是我的源代碼:如何更改位圖的像素顏色?
public static int DARK_PINK = Color.argb(255, 255, 51, 255);
public static int LIGHT_YELLOW = Color.argb(255, 255, 230, 102);
public static int DARK_MARUN = Color.argb(255, 148, 66, 50);
public static int LIGHT_MARUN = Color.argb(255, 186, 123, 68);
public static int RED = Color.argb(255, 252, 20, 20);
public static int LIGHT_BLUE = Color.argb(255, 102, 255, 255);
public static int DARK_BLUE = Color.argb(255, 70, 78, 202);
public static int LIGHT_GREEN = Color.argb(255, 190, 255, 91);
public static int DARK_GREEN = Color.argb(255, 15, 230, 0);
public static int JAMBLI = Color.argb(255, 123, 0, 230);
public static int ORANGE = Color.argb(255, 255, 187, 50);
public static int BLACK = Color.argb(255, 7, 5, 0);
public static int GRAY = Color.argb(255, 129, 128, 127);
public static int PINK_RED = Color.argb(255, 255, 4, 139);
public static int NEAVYBLUE = Color.argb(255, 51, 204, 255);
public static int ADVANCE_GREEN = Color.argb(255, 102, 255, 204);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main);
Bundle extras = getIntent().getExtras();
byte[] byteArray = extras.getByteArray("picture");
bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
bitmap = bmp.copy(Bitmap.Config.ARGB_8888, true);
canvas = new Canvas(bitmap);
paint = new Paint();
paint.setColor(DARK_PINK);
paint.setAntiAlias(true);
paint.setDither(true);
paint.setStrokeWidth(30);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OVER));
// paint = new Paint(Paint.DITHER_FLAG);
paths.add(path);
path = new Path();
image.setImageBitmap(bitmap);
image.setOnTouchListener(this);
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_color_one: {
int pixel = DARK_PINK;
bitmap.setPixel(x, y, pixel);
if(pixel==DARK_PINK){
pixel = LIGHT_YELLOW;
bitmap.setPixel(x, y, pixel);
canvas = new Canvas(bitmap);
}
else{
Toast.makeText(getApplicationContext(), "Not Changed", 2).show();
}
}
}
});
}
無我不是這一行的代碼的成功。 – jack 2014-09-13 11:44:43
我不能改變以前的像素的顏色,我不知道如何做到這一點。因爲我嘗試了很多方法來改變像素值而不是成功。 – jack 2014-09-13 11:46:20
你可以添加你所有的代碼嗎? – 2014-09-13 11:51:11