如何填充不同的颜色ImageView的(颜色在另一种颜色上的ImageView的同一区域)的同一区域? [英] How to fill different color on same area of imageview (Color over another Color on same area of imageview)?
问题描述
我有一个ImageView的,我设置的图像来填充不同的颜色。但是,当我填充颜色那么其他颜色不填上ImageView的同一个区域而previous颜色填充。我用调色板按钮上ImageView的获得不同的颜色填充。下面是我的code和形象的描述。
公共类Play_Screen扩展活动实现OnTouchListener,
OnClickListener {
私人螺纹螺纹;
私人布尔运行= FALSE;
// DrawImageView IV;
// ImageView的ImageView的;
私人上下文的背景下=这一点;
私人诠释paintAlpha = 255;
//初始颜色
私人诠释paintColor;
MediaPlayer的playsound = NULL;
搜索栏seekBar1;
按钮btn_paintbrush,btn_home,btn_cam,btn_cancel,btn_undo,btn_redo,
btn_eraser,btn_ preV,btn_next,btn_color_one,btn_color_two,
btn_color_three,btn_color_four,btn_color_five,btn_color_six,
btn_color_seven,btn_color_eight,btn_color_nine,btn_color_ten,
btn_color_elevan,btn_color_twelve,btn_color_thirteen,
btn_color_fourteen,btn_color_fifteen,btn_color_sixteen;
ImageView的形象;
点阵位图,bitmap2;
BMP位图;
帆布油画;
涂料粉刷;
浮downx = 0,霜霉病= 0,UPX = 0,upy = 0;
RelativeLayout的亲属;
共享preferences preFS;
私人布尔擦除= FALSE;
//自定义绘制视图
公共静态INT DARK_PINK = Color.argb(255,255,51,255);
公共静态INT LIGHT_YELLOW = Color.argb(255,255,230,102);
公共静态INT DARK_MARUN = Color.argb(255,148,66,50);
公共静态INT LIGHT_MARUN = Color.argb(255,186,123,68);
公共静态INT RED = Color.argb(255,252,20,20);
公共静态INT LIGHT_BLUE = Color.argb(255,102,255,255);
公共静态INT DARK_BLUE = Color.argb(255,70,78,202);
公共静态INT LIGHT_GREEN = Color.argb(255,190,255,91);
公共静态INT DARK_GREEN = Color.argb(255,15,230,0);
公共静态INT JAMBLI = Color.argb(255,123,0,230);
公共静态INT橙色= Color.argb(255,255,187,50);
公共静态INT BLACK = Color.argb(255,7,5,0);
公共静态INT灰色= Color.argb(255,129,128,127);
公共静态INT PINK_RED = Color.argb(255,255,4,139);
公共静态INT NEAVYBLUE = Color.argb(255,51,204,255);
公共静态INT ADVANCE_GREEN = Color.argb(255,102,255,204);
私人路径路径=新路径();
私人的ArrayList<路径> undonePaths =新的ArrayList<路径>();
私人的ArrayList<路径>路径=新的ArrayList<路径>();
INT strok;
@覆盖
保护无效的onCreate(包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.play_screen);
捆绑额外= getIntent()getExtras()。
字节[]的字节数组= extras.getByteArray(图片);
BMP = BitmapFactory.de codeByteArray(字节数组,0,byteArray.length);
相对=(RelativeLayout的)findViewById(R.id.relative);
图像=(ImageView的)findViewById(R.id.imageView1);
// image.setImageBitmap(BMP);
// image.setOnTouchListener(本);
seekBar1 =(搜索栏)findViewById(R.id.seekBar1);
seekBar1.setVisibility(View.INVISIBLE);
strok = GlobalVars.getSeekBarValue();
位= bmp.copy(Bitmap.Config.ARGB_8888,真正的);
帆布=新的Canvas(位);
油漆=新的油漆();
paint.setColor(DARK_PINK);
paint.setAntiAlias(真正的);
paint.setDither(真正的);
paint.setStrokeWidth(30);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setXfermode(新PorterDuffXfermode(PorterDuff.Mode.DST_OVER));
//油漆=新的油漆(Paint.DITHER_FLAG);
paths.add(路径);
GlobalVars.setBm(位);
image.setImageBitmap(位);
image.setOnTouchListener(本);
/ ***** /
DisplayMetrics指标=新DisplayMetrics();
。getWindowManager()getDefaultDisplay()getMetrics(度量)。
btn_color_one =(按钮)findViewById(R.id.btn_color_one);
btn_color_one.setOnClickListener(本);
btn_color_two =(按钮)findViewById(R.id.btn_color_two);
btn_color_two.setOnClickListener(本);
btn_color_three =(按钮)findViewById(R.id.btn_color_three);
btn_color_three.setOnClickListener(本);
btn_color_four =(按钮)findViewById(R.id.btn_color_four);
btn_color_four.setOnClickListener(本);
btn_color_five =(按钮)findViewById(R.id.btn_color_five);
btn_color_five.setOnClickListener(本);
btn_color_six =(按钮)findViewById(R.id.btn_color_six);
btn_color_six.setOnClickListener(本);
btn_color_seven =(按钮)findViewById(R.id.btn_color_seven);
btn_color_seven.setOnClickListener(本);
btn_color_eight =(按钮)findViewById(R.id.btn_color_eight);
btn_color_eight.setOnClickListener(本);
btn_color_nine =(按钮)findViewById(R.id.btn_color_nine);
btn_color_nine.setOnClickListener(本);
btn_color_ten =(按钮)findViewById(R.id.btn_color_ten);
btn_color_ten.setOnClickListener(本);
btn_color_elevan =(按钮)findViewById(R.id.btn_color_elevan);
btn_color_elevan.setOnClickListener(本);
btn_color_twelve =(按钮)findViewById(R.id.btn_color_twelve);
btn_color_twelve.setOnClickListener(本);
btn_color_thirteen =(按钮)findViewById(R.id.btn_color_thirteen);
btn_color_thirteen.setOnClickListener(本);
btn_color_fourteen =(按钮)findViewById(R.id.btn_color_fourteen);
btn_color_fourteen.setOnClickListener(本);
btn_color_fifteen =(按钮)findViewById(R.id.btn_color_fifteen);
btn_color_fifteen.setOnClickListener(本);
btn_color_sixteen =(按钮)findViewById(R.id.btn_color_sixteen);
btn_color_sixteen.setOnClickListener(本);
btn_paintbrush =(按钮)findViewById(R.id.btn_paintbrush);
btn_paintbrush.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
initializeMP();
playsound.start();
如果(seekBar1.getVisibility()== View.INVISIBLE){
seekBar1.setVisibility(View.VISIBLE);
seekBar1.setMax(100);
seekBar1.setProgress(30);
// INT currLevel = getPaintAlpha();
// seekBar1.setProgress(currLevel);
}否则,如果(seekBar1.getVisibility()== View.VISIBLE){
seekBar1.setVisibility(View.INVISIBLE);
}
}
});
seekBar1.setOnSeekBarChangeListener(新OnSeekBarChangeListener(){
@覆盖
公共无效onStopTrackingTouch(搜索栏搜索栏){
// TODO自动生成方法存根
preFS = getApplicationContext()。getShared preferences(
myShared prefsFilename,Context.MODE_PRIVATE);
//不要忘记调用commit()改变preferences时。
prefs.edit()。putInt(seekBarValue,seekBar.getProgress())
。承诺();
}
@覆盖
公共无效onStartTrackingTouch(搜索栏搜索栏){
// TODO自动生成方法存根
}
@覆盖
公共无效onProgressChanged(搜索栏搜索栏,INT进步,
布尔FROMUSER){
// TODO自动生成方法存根
GlobalVars.setSeekBarValue(进度);
paint.setStrokeWidth(进度);
}
});
btn_home =(按钮)findViewById(R.id.btn_home);
btn_home.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
initializeMP();
playsound.start();
意图I =新的意图(Play_Screen.this,Level_Screen.class);
startActivity(ⅰ);
}
});
btn_cam =(按钮)findViewById(R.id.btn_cam);
btn_cam.setOnClickListener(新OnClickListener(){
@燮pressWarnings(德precation)
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
initializeMP();
playsound.start();
查看查看= findViewById(R.id.relative);
view.setDrawingCacheEnabled(真正的);
//位图bitmap2 = view.getDrawingCache();
最后的位图bitmap2 = bitmap.copy(Bitmap.Config.ARGB_8888,
真正);
最后BitmapDrawable bitmapDrawable =新BitmapDrawable(
bitmap2);
image.setBackground(bitmapDrawable);
LayoutInflater充气=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
查看布局= inflater.inflate(R.layout.horizon,
(ViewGroup中)findViewById(R.id.main_relative_output));
//查看布局= inflater.inflate(R.layout.horizon,(的ViewGroup)
// findViewById(R.id.imageview_output));
RelativeLayout的RL =(RelativeLayout的)布局
.findViewById(R.id.main_relative_output);
// ImageView的imgview_output =
//(ImageView的)layout.findViewById(R.id.imageview_output);
AlertDialog.Builder建设者=新AlertDialog.Builder(
Play_Screen.this).setView(布局);
rl.setBackground(bitmapDrawable);
// imgview_output.setBackground(bitmapDrawable);
//店面形象
按钮btn_camera_output =(按钮)布局
.findViewById(R.id.btn_camera_output);
btn_camera_output.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
如果(Environment.MEDIA_MOUNTED.equals(环境
.getExternalStorageState())){
//我们检查,如果外部存储可用,
//否则显示错误信息给用户
文件SD卡=环境
.getExternalStorageDirectory();
文件目录=新的文件(sdCard.getAbsolutePath()
+/小孩子的世界);
directory.mkdirs();
字符串文件名=Painting.jpg;
文件yourFile =新的文件(目录,文件名);
如果(directory.canWrite()){
尝试 {
FileOutputStream中出=新的FileOutputStream(
yourFile);
bitmap2.com preSS(Bitmap.Com pressFormat.PNG,
90,出);
了out.flush();
out.close();
Toast.makeText(
getApplicationContext(),
文件输出到/ SD卡/小孩子的世界/ Painting.jpg
Toast.LENGTH_SHORT).show();
}赶上(IOException异常E){
e.printStackTrace();
}
}
} 其他 {
Toast.makeText(getApplicationContext(),
SD卡不可用!,
Toast.LENGTH_SHORT).show();
}
}
});
按钮btn_email_output =(按钮)布局
.findViewById(R.id.btn_email_output);
btn_email_output.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
文件jpegfile =新的文件(,Painting.jpg);
位图bitmap_output = bitmapDrawable.getBitmap();
//保存此位图文件。
文件缓存= getApplicationContext()
.getExternalCacheDir();
文件sharefile =新的文件(缓存,Painting.jpg);
尝试 {
FileOutputStream中出=新的FileOutputStream(
sharefile);
bitmap_output.com preSS(Bitmap.Com pressFormat.PNG,
100,出);
了out.flush();
out.close();
}赶上(IOException异常E){
}
//现在发送出去分享
意图份额=新的意图(
android.content.Intent.ACTION_SEND);
share.setType(图像/ *);
share.putExtra(Intent.EXTRA_STREAM,
Uri.parse(文件://+ sharefile));
share.putExtra(Intent.EXTRA_SUBJECT,
小孩子的世界VARMORA);
share.putExtra(
Intent.EXTRA_TEXT,
小孩子的世界VARMORA
+\ N
+ share.putExtra(
Intent.EXTRA_STREAM,
Uri.parse(文件://+ sharefile)));
尝试 {
startActivity(Intent.createChooser(份额,
分享图片));
}赶上(例外五){
}
}
});
按钮btn_facebook_output =(按钮)布局
.findViewById(R.id.btn_facebook_output);
btn_facebook_output.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
WindowManager.LayoutParams LP =新WindowManager.LayoutParams();
lp.copyFrom(alertDialog.getWindow()的getAttributes());
lp.width = 800;
lp.height = 480;
lp.x = -170;
lp.y = 100;
。alertDialog.getWindow()setAttributes(LP);
}
});
btn_cancel =(按钮)findViewById(R.id.btn_cancel);
btn_cancel.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
initializeMP();
playsound.start();
位= bmp.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}
});
btn_undo =(按钮)findViewById(R.id.btn_undo);
btn_undo.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
initializeMP();
playsound.start();
onClickUndo();
}
});
btn_redo =(按钮)findViewById(R.id.btn_redo);
btn_redo.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
initializeMP();
playsound.start();
onClickRedo();
}
});
btn_eraser =(按钮)findViewById(R.id.btn_eraser);
btn_eraser.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
initializeMP();
playsound.start();
setErase(真正的);
}
});
btn_ preV =(按钮)findViewById(R.id.btn_ preV);
btn_ prev.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
initializeMP();
playsound.start();
Toast.makeText(getApplicationContext(),previous,
Toast.LENGTH_SHORT).show();
}
});
btn_next =(按钮)findViewById(R.id.btn_next);
btn_next.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
initializeMP();
playsound.start();
位图img_A = BitmapFactory.de codeResource(getResources()
R.drawable.img_a);
位图img_B = BitmapFactory.de codeResource(getResources()
R.drawable.img_b);
// BitmapFactory.Options选项=新BitmapFactory.Options();
// options.inSampleSize = 4;
//位图img_B = BitmapFactory.de codeFILE(R.drawable.img_b
//选件);
位图img_C = BitmapFactory.de codeResource(getResources()
R.drawable.img_c);
//位图img_C = BitmapFactory.de codeFILE(R.drawable.img_c
//选件);
位图img_D = BitmapFactory.de codeResource(getResources()
R.drawable.img_d);
位图img_E = BitmapFactory.de codeResource(getResources()
R.drawable.img_e);
位图img_F = BitmapFactory.de codeResource(getResources()
R.drawable.img_f);
位图img_G = BitmapFactory.de codeResource(getResources()
R.drawable.img_g);
位图img_H = BitmapFactory.de codeResource(getResources()
R.drawable.img_h);
位图img_I = BitmapFactory.de codeResource(getResources()
R.drawable.img_i);
位图img_J = BitmapFactory.de codeResource(getResources()
R.drawable.img_j);
位图img_K = BitmapFactory.de codeResource(getResources()
R.drawable.img_k);
位图img_L = BitmapFactory.de codeResource(getResources()
R.drawable.img_l);
位图img_M = BitmapFactory.de codeResource(getResources()
R.drawable.img_m);
位图img_N = BitmapFactory.de codeResource(getResources()
R.drawable.img_n);
位图img_O = BitmapFactory.de codeResource(getResources()
R.drawable.img_o);
位图img_P = BitmapFactory.de codeResource(getResources()
R.drawable.img_p);
位图img_Q = BitmapFactory.de codeResource(getResources()
R.drawable.img_q);
位图img_R = BitmapFactory.de codeResource(getResources()
R.drawable.img_r);
位图img_S = BitmapFactory.de codeResource(getResources()
R.drawable.img_s);
位图img_T = BitmapFactory.de codeResource(getResources()
R.drawable.img_t);
位图img_U = BitmapFactory.de codeResource(getResources()
R.drawable.img_u);
位图img_V = BitmapFactory.de codeResource(getResources()
R.drawable.img_v);
位图img_W = BitmapFactory.de codeResource(getResources()
R.drawable.img_w);
位图img_X = BitmapFactory.de codeResource(getResources()
R.drawable.img_x);
位图img_Y = BitmapFactory.de codeResource(getResources()
R.drawable.img_y);
位图img_Z = BitmapFactory.de codeResource(getResources()
R.drawable.img_z);
如果(bitmapequals(位图,img_A)){
位= img_B.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_B)){
位= img_C.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
100));
}否则,如果(bitmapequals(位图,img_C)){
位= img_D.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
00,100));
}否则,如果(bitmapequals(位图,img_D)){
位= img_E.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
100,100));
}否则,如果(bitmapequals(位图,img_E)){
位= img_F.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
/ 100,100));
}否则,如果(bitmapequals(位图,img_F)){
位= img_G.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_G)){
位= img_H.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_H)){
位= img_I.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_I)){
位= img_J.copy(Bitmap.Config.ARGB_8888,真正的);
}否则,如果(bitmapequals(位图,img_J)){
位= img_K.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_K)){
位= img_L.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_L)){
位= img_M.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_M)){
位= img_N.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_N)){
位= img_O.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_O)){
位= img_P.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_P)){
位= img_Q.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_Q)){
位= img_R.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_R)){
位= img_S.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_S)){
位= img_T.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_T)){
位= img_U.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_U)){
位= img_V.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_V)){
位= img_W.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_W)){
位= img_X.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_X)){
位= img_Y.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
}否则,如果(bitmapequals(位图,img_Y)){
位= img_Z.copy(Bitmap.Config.ARGB_8888,真正的);
image.setImageBitmap(位);
btn_next.setVisibility(View.INVISIBLE);
}否则,如果(bitmapequals(位图,img_Z)){
}
}
});
}
@覆盖
公共布尔onTouch(视图V,MotionEvent事件){
// TODO自动生成方法存根
// INT行动= event.getAction();
浮eventX = event.getX();
浮eventY = event.getY();
开关(event.getAction()){
案例MotionEvent.ACTION_DOWN:
path.moveTo(eventX,eventY);
paths.add(路径);
打破;
案例MotionEvent.ACTION_MOVE:
path.lineTo(eventX,eventY);
canvas.drawPath(路径,油漆);
paths.add(路径);
打破;
案例MotionEvent.ACTION_UP:
UPX = event.getX();
upy = event.getY();
// canvas.drawLine(downx,柔和,UPX,upy,油漆);
path.lineTo(eventX,eventY);
canvas.drawPath(路径,油漆);
paths.add(路径);
path.reset();
打破;
案例MotionEvent.ACTION_CANCEL:
打破;
默认:
打破;
}
image.invalidate();
v.invalidate();
返回true;
}
//设置擦除真的还是假的
@燮pressWarnings(德precation)
公共无效setErase(布尔isErase){
擦除= isErase;
如果(删除){
paint.setXfermode(空);
油漆=新的油漆(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
paint.setXfermode(新AvoidXfermode(Color.WHITE,215,
AvoidXfermode.Mode.TARGET));
paint.setMaskFilter(新BlurMaskFilter(15,Blur.SOLID));
} 其他 {
paint.setXfermode(空);
}
}
@燮pressWarnings(德precation)
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
而(btn_cancel.isClickable()){
帆布=新的Canvas(位);
油漆=新的油漆();
paint.setColor(DARK_PINK);
paint.setAntiAlias(真正的);
paint.setDither(真正的);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
路径=新路径();
image.setImageBitmap(位);
打破;
}
开关(v.getId()){
案例R.id.btn_color_one:{
//做一下按钮1点击
initializeMP();
playsound.start();
setupDrawing();
paint.setColor(DARK_PINK);
打破;
}
案例R.id.btn_color_two:{
//做一下按钮1点击
initializeMP();
playsound.start();
setupDrawing();
paint.setColor(LIGHT_YELLOW);
打破;
}
案例R.id.btn_color_three:{
//做一下按钮1点击
initializeMP();
playsound.start();
setupDrawing();
paint.setColor(DARK_MARUN);
打破;
}
案例R.id.btn_color_four:{
//做一下按钮1点击
initializeMP();
playsound.start();
setupDrawing();
打破;
}
案例R.id.btn_color_five:{
//做一下按钮1点击
initializeMP();
playsound.start();
setupDrawing();
paint.setColor(RED);
打破;
}
}
}
公共无效onClickUndo(){
如果(paths.size()大于0){
undonePaths.add(paths.remove(paths.size() - 1));
Toast.makeText(getApplicationContext(),
将String.valueOf(paths.size()),2).show();
image.refreshDrawableState();
image.invalidate();
} 其他 {
//敬酒用户
Toast.makeText(getApplicationContext(),不工作撤消
Toast.LENGTH_SHORT).show();
}
}
公共无效onClickRedo(){
如果(undonePaths.size()大于0){
paths.add(undonePaths.remove(undonePaths.size() - 1));
} 其他 {
//敬酒用户
Toast.makeText(getApplicationContext(),不工作重做,
Toast.LENGTH_SHORT).show();
}
}
私人无效initializeMP(){
// TODO自动生成方法存根
playsound = MediaPlayer.create(这一点,R.raw.playsound);
}
公共布尔bitmapequals(位图bitmap1,位图bitmap2){
ByteBuffer的缓冲器1 = ByteBuffer.allocate(bitmap1.getHeight()
* bitmap1.getRowBytes());
bitmap1.copyPixelsToBuffer(缓冲器1);
ByteBuffer的缓冲器2 = ByteBuffer.allocate(bitmap2.getHeight()
* bitmap2.getRowBytes());
// bitmap2.copyPixelsFromBuffer(缓冲器1);
bitmap2.copyPixelsToBuffer(缓冲器2);
返回满足Arrays.equals(buffer1.array(),buffer2.array());
}
公共无效setupDrawing(){
initializeMP();
playsound.start();
帆布=新的Canvas(位);
paint.setAntiAlias(真正的);
paint.setDither(假);
paint.setStrokeWidth(30);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setXfermode(新PorterDuffXfermode(PorterDuff.Mode.DST_OVER));
// paint.setXfermode(新PorterDuffXfermode(Mode.SRC_IN));
}
布尔imagesAreEqual(位图I1,I2位图){
如果(i1.getHeight()!= i2.getHeight())
返回false;
如果(i1.getWidth()!= i2.getWidth())
返回false;
对于(INT Y = 0; Y< i1.getHeight(); ++ Y)
为(中间体X = 0 X - 其中; i1.getWidth(); ++ x)的
如果(i1.getPixel(X,Y)!= i2.getPixel(X,Y))
返回false;
返回true;
}
}
您已经是你画你所有的路径与PorterDuff.Mode的问题。你真正想要做的是画没有任何PorterDuff.Mode你的所有路径,然后采取最终渲染并将其与PorterDuff.Mode适用于您的形状。由于有更多的时间我应该可以写一个例子给你。你也有很多其他的问题,你的code。
解决方案: https://github.com/slightfoot/android-painter-example
I have one imageview and i set image for filling the different colors. But when i fill color then other color is not fill on same area on imageview which previous color is filled. I use color pallet button for getting different color for fill on imageview. Below is my code and image description.
public class Play_Screen extends Activity implements OnTouchListener,
OnClickListener {
private Thread thread;
private boolean running = false;
// DrawImageView iv;
// ImageView imageView;
private Context context = this;
private int paintAlpha = 255;
// initial color
private int paintColor;
MediaPlayer playsound = null;
SeekBar seekBar1;
Button btn_paintbrush, btn_home, btn_cam, btn_cancel, btn_undo, btn_redo,
btn_eraser, btn_prev, btn_next, btn_color_one, btn_color_two,
btn_color_three, btn_color_four, btn_color_five, btn_color_six,
btn_color_seven, btn_color_eight, btn_color_nine, btn_color_ten,
btn_color_elevan, btn_color_twelve, btn_color_thirteen,
btn_color_fourteen, btn_color_fifteen, btn_color_sixteen;
ImageView image;
Bitmap bitmap,bitmap2;
Bitmap bmp;
Canvas canvas;
Paint paint;
float downx = 0, downy = 0, upx = 0, upy = 0;
RelativeLayout relative;
SharedPreferences prefs;
private boolean erase = false;
// custom drawing view
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);
private Path path = new Path();
private ArrayList<Path> undonePaths = new ArrayList<Path>();
private ArrayList<Path> paths = new ArrayList<Path>();
int strok;
@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.play_screen);
Bundle extras = getIntent().getExtras();
byte[] byteArray = extras.getByteArray("picture");
bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
relative = (RelativeLayout)findViewById(R.id.relative);
image = (ImageView) findViewById(R.id.imageView1);
// image.setImageBitmap(bmp);
// image.setOnTouchListener(this);
seekBar1 = (SeekBar) findViewById(R.id.seekBar1);
seekBar1.setVisibility(View.INVISIBLE);
strok = GlobalVars.getSeekBarValue();
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);
GlobalVars.setBm(bitmap);
image.setImageBitmap(bitmap);
image.setOnTouchListener(this);
/*****/
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
btn_color_one = (Button) findViewById(R.id.btn_color_one);
btn_color_one.setOnClickListener(this);
btn_color_two = (Button) findViewById(R.id.btn_color_two);
btn_color_two.setOnClickListener(this);
btn_color_three = (Button) findViewById(R.id.btn_color_three);
btn_color_three.setOnClickListener(this);
btn_color_four = (Button) findViewById(R.id.btn_color_four);
btn_color_four.setOnClickListener(this);
btn_color_five = (Button) findViewById(R.id.btn_color_five);
btn_color_five.setOnClickListener(this);
btn_color_six = (Button) findViewById(R.id.btn_color_six);
btn_color_six.setOnClickListener(this);
btn_color_seven = (Button) findViewById(R.id.btn_color_seven);
btn_color_seven.setOnClickListener(this);
btn_color_eight = (Button) findViewById(R.id.btn_color_eight);
btn_color_eight.setOnClickListener(this);
btn_color_nine = (Button) findViewById(R.id.btn_color_nine);
btn_color_nine.setOnClickListener(this);
btn_color_ten = (Button) findViewById(R.id.btn_color_ten);
btn_color_ten.setOnClickListener(this);
btn_color_elevan = (Button) findViewById(R.id.btn_color_elevan);
btn_color_elevan.setOnClickListener(this);
btn_color_twelve = (Button) findViewById(R.id.btn_color_twelve);
btn_color_twelve.setOnClickListener(this);
btn_color_thirteen = (Button) findViewById(R.id.btn_color_thirteen);
btn_color_thirteen.setOnClickListener(this);
btn_color_fourteen = (Button) findViewById(R.id.btn_color_fourteen);
btn_color_fourteen.setOnClickListener(this);
btn_color_fifteen = (Button) findViewById(R.id.btn_color_fifteen);
btn_color_fifteen.setOnClickListener(this);
btn_color_sixteen = (Button) findViewById(R.id.btn_color_sixteen);
btn_color_sixteen.setOnClickListener(this);
btn_paintbrush = (Button) findViewById(R.id.btn_paintbrush);
btn_paintbrush.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
initializeMP();
playsound.start();
if (seekBar1.getVisibility() == View.INVISIBLE) {
seekBar1.setVisibility(View.VISIBLE);
seekBar1.setMax(100);
seekBar1.setProgress(30);
// int currLevel = getPaintAlpha();
// seekBar1.setProgress(currLevel);
} else if (seekBar1.getVisibility() == View.VISIBLE) {
seekBar1.setVisibility(View.INVISIBLE);
}
}
});
seekBar1.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
prefs = getApplicationContext().getSharedPreferences(
"mySharedPrefsFilename", Context.MODE_PRIVATE);
// Don't forget to call commit() when changing preferences.
prefs.edit().putInt("seekBarValue", seekBar.getProgress())
.commit();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
GlobalVars.setSeekBarValue(progress);
paint.setStrokeWidth(progress);
}
});
btn_home = (Button) findViewById(R.id.btn_home);
btn_home.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
initializeMP();
playsound.start();
Intent i = new Intent(Play_Screen.this, Level_Screen.class);
startActivity(i);
}
});
btn_cam = (Button) findViewById(R.id.btn_cam);
btn_cam.setOnClickListener(new OnClickListener() {
@SuppressWarnings("deprecation")
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
initializeMP();
playsound.start();
View view = findViewById(R.id.relative);
view.setDrawingCacheEnabled(true);
// Bitmap bitmap2 = view.getDrawingCache();
final Bitmap bitmap2 = bitmap.copy(Bitmap.Config.ARGB_8888,
true);
final BitmapDrawable bitmapDrawable = new BitmapDrawable(
bitmap2);
image.setBackground(bitmapDrawable);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.horizon,
(ViewGroup) findViewById(R.id.main_relative_output));
// View layout = inflater.inflate(R.layout.horizon, (ViewGroup)
// findViewById(R.id.imageview_output));
RelativeLayout rl = (RelativeLayout) layout
.findViewById(R.id.main_relative_output);
// ImageView imgview_output =
// (ImageView)layout.findViewById(R.id.imageview_output);
AlertDialog.Builder builder = new AlertDialog.Builder(
Play_Screen.this).setView(layout);
rl.setBackground(bitmapDrawable);
// imgview_output.setBackground(bitmapDrawable);
// store image
Button btn_camera_output = (Button) layout
.findViewById(R.id.btn_camera_output);
btn_camera_output.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (Environment.MEDIA_MOUNTED.equals(Environment
.getExternalStorageState())) {
// we check if external storage is available,
// otherwise display an error message to the user
File sdCard = Environment
.getExternalStorageDirectory();
File directory = new File(sdCard.getAbsolutePath()
+ "/Kiddy World");
directory.mkdirs();
String filename = "Painting.jpg";
File yourFile = new File(directory, filename);
if (directory.canWrite()) {
try {
FileOutputStream out = new FileOutputStream(
yourFile);
bitmap2.compress(Bitmap.CompressFormat.PNG,
90, out);
out.flush();
out.close();
Toast.makeText(
getApplicationContext(),
"File exported to /sdcard/Kiddy World/Painting.jpg",
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
Toast.makeText(getApplicationContext(),
"SD Card not available!",
Toast.LENGTH_SHORT).show();
}
}
});
Button btn_email_output = (Button) layout
.findViewById(R.id.btn_email_output);
btn_email_output.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
File jpegfile = new File("", "Painting.jpg");
Bitmap bitmap_output = bitmapDrawable.getBitmap();
// Save this bitmap to a file.
File cache = getApplicationContext()
.getExternalCacheDir();
File sharefile = new File(cache, "Painting.jpg");
try {
FileOutputStream out = new FileOutputStream(
sharefile);
bitmap_output.compress(Bitmap.CompressFormat.PNG,
100, out);
out.flush();
out.close();
} catch (IOException e) {
}
// Now send it out to share
Intent share = new Intent(
android.content.Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file://" + sharefile));
share.putExtra(Intent.EXTRA_SUBJECT,
"Kiddy World VARMORA");
share.putExtra(
Intent.EXTRA_TEXT,
"Kiddy World VARMORA"
+ "\n"
+ share.putExtra(
Intent.EXTRA_STREAM,
Uri.parse("file://" + sharefile)));
try {
startActivity(Intent.createChooser(share,
"Share photo"));
} catch (Exception e) {
}
}
});
Button btn_facebook_output = (Button) layout
.findViewById(R.id.btn_facebook_output);
btn_facebook_output.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(alertDialog.getWindow().getAttributes());
lp.width = 800;
lp.height = 480;
lp.x = -170;
lp.y = 100;
alertDialog.getWindow().setAttributes(lp);
}
});
btn_cancel = (Button) findViewById(R.id.btn_cancel);
btn_cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
initializeMP();
playsound.start();
bitmap = bmp.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
}
});
btn_undo = (Button) findViewById(R.id.btn_undo);
btn_undo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
initializeMP();
playsound.start();
onClickUndo();
}
});
btn_redo = (Button) findViewById(R.id.btn_redo);
btn_redo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
initializeMP();
playsound.start();
onClickRedo();
}
});
btn_eraser = (Button) findViewById(R.id.btn_eraser);
btn_eraser.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
initializeMP();
playsound.start();
setErase(true);
}
});
btn_prev = (Button) findViewById(R.id.btn_prev);
btn_prev.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
initializeMP();
playsound.start();
Toast.makeText(getApplicationContext(), "Previous",
Toast.LENGTH_SHORT).show();
}
});
btn_next = (Button) findViewById(R.id.btn_next);
btn_next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
initializeMP();
playsound.start();
Bitmap img_A = BitmapFactory.decodeResource(getResources(),
R.drawable.img_a);
Bitmap img_B = BitmapFactory.decodeResource(getResources(),
R.drawable.img_b);
// BitmapFactory.Options options = new BitmapFactory.Options();
// options.inSampleSize = 4;
// Bitmap img_B = BitmapFactory.decodeFile("R.drawable.img_b",
// options);
Bitmap img_C = BitmapFactory.decodeResource(getResources(),
R.drawable.img_c);
// Bitmap img_C = BitmapFactory.decodeFile("R.drawable.img_c",
// options);
Bitmap img_D = BitmapFactory.decodeResource(getResources(),
R.drawable.img_d);
Bitmap img_E = BitmapFactory.decodeResource(getResources(),
R.drawable.img_e);
Bitmap img_F = BitmapFactory.decodeResource(getResources(),
R.drawable.img_f);
Bitmap img_G = BitmapFactory.decodeResource(getResources(),
R.drawable.img_g);
Bitmap img_H = BitmapFactory.decodeResource(getResources(),
R.drawable.img_h);
Bitmap img_I = BitmapFactory.decodeResource(getResources(),
R.drawable.img_i);
Bitmap img_J = BitmapFactory.decodeResource(getResources(),
R.drawable.img_j);
Bitmap img_K = BitmapFactory.decodeResource(getResources(),
R.drawable.img_k);
Bitmap img_L = BitmapFactory.decodeResource(getResources(),
R.drawable.img_l);
Bitmap img_M = BitmapFactory.decodeResource(getResources(),
R.drawable.img_m);
Bitmap img_N = BitmapFactory.decodeResource(getResources(),
R.drawable.img_n);
Bitmap img_O = BitmapFactory.decodeResource(getResources(),
R.drawable.img_o);
Bitmap img_P = BitmapFactory.decodeResource(getResources(),
R.drawable.img_p);
Bitmap img_Q = BitmapFactory.decodeResource(getResources(),
R.drawable.img_q);
Bitmap img_R = BitmapFactory.decodeResource(getResources(),
R.drawable.img_r);
Bitmap img_S = BitmapFactory.decodeResource(getResources(),
R.drawable.img_s);
Bitmap img_T = BitmapFactory.decodeResource(getResources(),
R.drawable.img_t);
Bitmap img_U = BitmapFactory.decodeResource(getResources(),
R.drawable.img_u);
Bitmap img_V = BitmapFactory.decodeResource(getResources(),
R.drawable.img_v);
Bitmap img_W = BitmapFactory.decodeResource(getResources(),
R.drawable.img_w);
Bitmap img_X = BitmapFactory.decodeResource(getResources(),
R.drawable.img_x);
Bitmap img_Y = BitmapFactory.decodeResource(getResources(),
R.drawable.img_y);
Bitmap img_Z = BitmapFactory.decodeResource(getResources(),
R.drawable.img_z);
if (bitmapequals(bitmap, img_A)) {
bitmap = img_B.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_B)) {
bitmap = img_C.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
100));
} else if (bitmapequals(bitmap, img_C)) {
bitmap = img_D.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
00, 100));
} else if (bitmapequals(bitmap, img_D)) {
bitmap = img_E.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
100, 100));
} else if (bitmapequals(bitmap, img_E)) {
bitmap = img_F.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
/ 100, 100));
} else if (bitmapequals(bitmap, img_F)) {
bitmap = img_G.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_G)) {
bitmap = img_H.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_H)) {
bitmap = img_I.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_I)) {
bitmap = img_J.copy(Bitmap.Config.ARGB_8888, true);
} else if (bitmapequals(bitmap, img_J)) {
bitmap = img_K.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_K)) {
bitmap = img_L.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_L)) {
bitmap = img_M.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_M)) {
bitmap = img_N.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_N)) {
bitmap = img_O.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_O)) {
bitmap = img_P.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_P)) {
bitmap = img_Q.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_Q)) {
bitmap = img_R.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_R)) {
bitmap = img_S.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_S)) {
bitmap = img_T.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_T)) {
bitmap = img_U.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_U)) {
bitmap = img_V.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_V)) {
bitmap = img_W.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_W)) {
bitmap = img_X.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_X)) {
bitmap = img_Y.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
} else if (bitmapequals(bitmap, img_Y)) {
bitmap = img_Z.copy(Bitmap.Config.ARGB_8888, true);
image.setImageBitmap(bitmap);
btn_next.setVisibility(View.INVISIBLE);
} else if (bitmapequals(bitmap, img_Z)) {
}
}
});
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
// int action = event.getAction();
float eventX = event.getX();
float eventY = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(eventX, eventY);
paths.add(path);
break;
case MotionEvent.ACTION_MOVE:
path.lineTo(eventX, eventY);
canvas.drawPath(path, paint);
paths.add(path);
break;
case MotionEvent.ACTION_UP:
upx = event.getX();
upy = event.getY();
// canvas.drawLine(downx, downy, upx, upy, paint);
path.lineTo(eventX, eventY);
canvas.drawPath(path, paint);
paths.add(path);
path.reset();
break;
case MotionEvent.ACTION_CANCEL:
break;
default:
break;
}
image.invalidate();
v.invalidate();
return true;
}
// set erase true or false
@SuppressWarnings("deprecation")
public void setErase(boolean isErase) {
erase = isErase;
if (erase) {
paint.setXfermode(null);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
paint.setXfermode(new AvoidXfermode(Color.WHITE, 215,
AvoidXfermode.Mode.TARGET));
paint.setMaskFilter(new BlurMaskFilter(15, Blur.SOLID));
} else {
paint.setXfermode(null);
}
}
@SuppressWarnings("deprecation")
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
while (btn_cancel.isClickable()) {
canvas = new Canvas(bitmap);
paint = new Paint();
paint.setColor(DARK_PINK);
paint.setAntiAlias(true);
paint.setDither(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
path = new Path();
image.setImageBitmap(bitmap);
break;
}
switch (v.getId()) {
case R.id.btn_color_one: {
// do something for button 1 click
initializeMP();
playsound.start();
setupDrawing();
paint.setColor(DARK_PINK);
break;
}
case R.id.btn_color_two: {
// do something for button 1 click
initializeMP();
playsound.start();
setupDrawing();
paint.setColor(LIGHT_YELLOW);
break;
}
case R.id.btn_color_three: {
// do something for button 1 click
initializeMP();
playsound.start();
setupDrawing();
paint.setColor(DARK_MARUN);
break;
}
case R.id.btn_color_four: {
// do something for button 1 click
initializeMP();
playsound.start();
setupDrawing();
break;
}
case R.id.btn_color_five: {
// do something for button 1 click
initializeMP();
playsound.start();
setupDrawing();
paint.setColor(RED);
break;
}
}
}
public void onClickUndo() {
if (paths.size() > 0) {
undonePaths.add(paths.remove(paths.size() - 1));
Toast.makeText(getApplicationContext(),
String.valueOf(paths.size()), 2).show();
image.refreshDrawableState();
image.invalidate();
} else {
// toast the user
Toast.makeText(getApplicationContext(), "Not Work Undo",
Toast.LENGTH_SHORT).show();
}
}
public void onClickRedo() {
if (undonePaths.size() > 0) {
paths.add(undonePaths.remove(undonePaths.size() - 1));
} else {
// toast the user
Toast.makeText(getApplicationContext(), "Not Work Redo",
Toast.LENGTH_SHORT).show();
}
}
private void initializeMP() {
// TODO Auto-generated method stub
playsound = MediaPlayer.create(this, R.raw.playsound);
}
public boolean bitmapequals(Bitmap bitmap1, Bitmap bitmap2) {
ByteBuffer buffer1 = ByteBuffer.allocate(bitmap1.getHeight()
* bitmap1.getRowBytes());
bitmap1.copyPixelsToBuffer(buffer1);
ByteBuffer buffer2 = ByteBuffer.allocate(bitmap2.getHeight()
* bitmap2.getRowBytes());
// bitmap2.copyPixelsFromBuffer(buffer1);
bitmap2.copyPixelsToBuffer(buffer2);
return Arrays.equals(buffer1.array(), buffer2.array());
}
public void setupDrawing() {
initializeMP();
playsound.start();
canvas = new Canvas(bitmap);
paint.setAntiAlias(true);
paint.setDither(false);
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.setXfermode (new PorterDuffXfermode (Mode.SRC_IN));
}
boolean imagesAreEqual(Bitmap i1, Bitmap i2) {
if (i1.getHeight() != i2.getHeight())
return false;
if (i1.getWidth() != i2.getWidth())
return false;
for (int y = 0; y < i1.getHeight(); ++y)
for (int x = 0; x < i1.getWidth(); ++x)
if (i1.getPixel(x, y) != i2.getPixel(x, y))
return false;
return true;
}
}
The problem you have is your drawing all your Paths with a PorterDuff.Mode. What you really want to do is to draw all your paths without any PorterDuff.Mode and then take that final render and apply it to your A shape with a PorterDuff.Mode. Given more time I should be able to write an example for you. You also have many other issues with your code.
Solution: https://github.com/slightfoot/android-painter-example
这篇关于如何填充不同的颜色ImageView的(颜色在另一种颜色上的ImageView的同一区域)的同一区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!