我已经制作了与油漆相关的应用程序..在那个应用程序中,我试图应用原始图像效果,就像我们在图像上绘制一样。 但是当我将原始颜色应用到图像后我绘制另一种颜色时会出现问题。一旦应用了原始颜色,我就无法将任何其他颜色应用于图像。我拍摄了两张图片:一张用于加载图片,另一张用于在图像上绘画。如果有人能帮助我,我将感激不尽。提前致谢。 这是我的代码..
public class Draw extends Activity implements OnTouchListener
{
ImageView imagesave, imagepaint, clear, back, done, cayan, purple, green, red, yellow, pink, orange, blue,
gray, violet, rose, gold, chocolate;
Button original;
SeekBar s1;
RelativeLayout rltop;
Bitmap bitmap;
Canvas canvas;
Paint paint;
float downx = 0, downy = 0, upx = 0, upy = 0;
int a, r, g, b;
int pixel;
int x, y;
int h = Glob.bmp.getWidth();
int w = Glob.bmp.getHeight();
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState)
{
try
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.draw);
imagesave = (ImageView) findViewById(R.id.imagesave);
imagesave.setImageBitmap(Glob.bmp);
s1 = (SeekBar) findViewById(R.id.seekBar1);
done = (ImageView) findViewById(R.id.ivdone);
clear = (ImageView) findViewById(R.id.ivclear);
back = (ImageView) findViewById(R.id.ivback);
rltop = (RelativeLayout) findViewById(R.id.rltop);
original = (Button) this.findViewById(R.id.original);
cayan = (ImageView) this.findViewById(R.id.cayan);
purple = (ImageView) this.findViewById(R.id.purple);
green = (ImageView) this.findViewById(R.id.green);
red = (ImageView) this.findViewById(R.id.red);
yellow = (ImageView) this.findViewById(R.id.yellow);
pink = (ImageView) this.findViewById(R.id.pink);
orange = (ImageView) this.findViewById(R.id.orange);
blue = (ImageView) this.findViewById(R.id.blue);
gray = (ImageView) this.findViewById(R.id.gray);
violet = (ImageView) this.findViewById(R.id.violet);
rose = (ImageView) this.findViewById(R.id.rosegold);
gold = (ImageView) this.findViewById(R.id.gold);
chocolate = (ImageView) this.findViewById(R.id.chocolate);
imagepaint = (ImageView) this.findViewById(R.id.imagepaint);
Display currentDisplay = getWindowManager().getDefaultDisplay();
float dw = currentDisplay.getWidth();
float dh = currentDisplay.getHeight();
bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
paint = new Paint();
paint.setAntiAlias(true);
paint.setDither(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeWidth(10f);
paint.setStrokeMiter(50);
imagepaint.setImageBitmap(bitmap);
imagepaint.setOnTouchListener(this);
imagepaint.setAlpha(150);
clear.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
bitmap.eraseColor(android.graphics.Color.TRANSPARENT);
}
});
done.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
rltop = (RelativeLayout) findViewById(R.id.rltop);
rltop.setDrawingCacheEnabled(true);
Bitmap bitmap = rltop.getDrawingCache();
Glob.bmp1 = bitmap;
Intent i = new Intent(getApplicationContext(), Show.class);
startActivity(i);
}
});
back.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(getApplicationContext(), Main.class);
startActivity(i);
}
});
s1.setMax(255);
s1.setProgress((10));
s1.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar arg0)
{
}
@Override
public void onStartTrackingTouch(SeekBar arg0)
{
}
@Override
public void onProgressChanged(SeekBar arg0, int progress,boolean arg2)
{
paint.setStrokeWidth(progress);
}
});
original.setOnClickListener(new OnClickListener() {
@SuppressLint("NewApi")
public void onClick(View v)
{
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
}
});
cayan.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
paint.setColor(Color.CYAN);
}
});
purple.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
paint.setColor(Color.rgb(153, 50, 205));
}
});
green.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
paint.setColor(Color.GREEN);
}
});
red.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
paint.setColor(Color.RED);
}
});
yellow.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
paint.setColor(Color.YELLOW);
}
});
pink.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
paint.setColor(Color.rgb(255, 0, 204));
}
});
orange.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
paint.setColor(Color.rgb(255, 69, 0));
}
});
blue.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
paint.setColor(Color.BLUE);
}
});
gray.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
paint.setColor(Color.rgb(169,169,169));
}
});
violet.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
paint.setColor(Color.rgb(216, 191, 216));
}
});
rose.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
paint.setColor(Color.rgb(246, 217, 213));
}
});
gold.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
paint.setColor(Color.rgb(255, 215, 0));
}
});
chocolate.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
paint.setColor(Color.rgb(85, 42, 12));
}
});
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public boolean onTouch(View v, MotionEvent event) {
try {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
downx = event.getX();
downy = event.getY();
break;
case MotionEvent.ACTION_MOVE:
upx = event.getX();
upy = event.getY();
canvas.drawLine(downx, downy, upx, upy, paint);
imagepaint.invalidate();
downx = upx;
downy = upy;
break;
case MotionEvent.ACTION_UP:
upx = event.getX();
upy = event.getY();
canvas.drawLine(downx, downy, upx, upy, paint);
imagepaint.invalidate();
break;
case MotionEvent.ACTION_CANCEL:
break;
default:
break;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
void onbackpressed()
{
try
{
Intent i = new Intent(getApplicationContext(), Main.class);
startActivity(i);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}