我有一个位图对象。当我使用getpixel()作为位图并且在setPixel之后使用该位图对象时,像素值(颜色)不会改变。我使用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();
}
}
}
});
}
答案 0 :(得分:0)
尝试给它一个像这样的RGB颜色编号
myBitmap.setPixel(x, y, Color.rgb(45, 127, 0));