这是我的Bitmap代码
// Bitmap VIEwpublic class MyVIEw extends VIEw implements OnClickListener{ public int height; public int wIDth; private Bitmap mBitmap; private Path mPath; private Paint mBitmapPaint; public MyVIEw(Context c) { super(c); mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); } @OverrIDe protected voID onSizeChanged(int w,int h,int olDW,int oldh) { super.onSizeChanged(w,h,olDW,oldh); WID = w; Ht = h; mBitmap = Bitmap.createBitmap(w,Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @OverrIDe protected voID onDraw(final Canvas canvas) { canvas.drawcolor(0xFFFFFFFF); canvas.drawBitmap(mBitmap,mBitmapPaint); canvas.drawPath(mPath,mPaint); // onclick Listner for SAVE button savebutton.setonClickListener(new OnClickListener() { public voID onClick(VIEw v) { //capture the image try { saveAsJpg(mBitmap); startActivity(new Intent(Paint.this,SignatureActivity.class)); finish(); } catch (IOException e) { e.printstacktrace(); } } }); } private float mX,mY; private static final float touch_TolERANCE = 4; private voID touch_start(float x,float y) { mPath.reset(); mPath.moveto(x,y); mX = x; mY = y; System.out.println("---- " +mX); } private voID touch_move(float x,float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= touch_TolERANCE || dy >= touch_TolERANCE) { mPath.quadTo(mX,mY,(x + mX)/2,(y + mY)/2); mX = x; mY = y; } } private voID touch_up() { mPath.lineto(mX,mY); // commit the path to our offscreen mCanvas.drawPath(mPath,mPaint); // kill this so we don't double draw mPath.reset(); } @OverrIDe public boolean ontouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_start(x,y); invalIDate(); break; case MotionEvent.ACTION_MOVE: touch_move(x,y); invalIDate(); break; case MotionEvent.ACTION_UP: touch_up(); invalIDate(); break; } return true; }
我可以在创建签名时看到绿色背景,但它保存在黑色背景上.请帮帮我,谢谢你
解决方法 @rahul你也可以在onDraw中使用它canvas.drawcolor(color.GREEN);
请检查我的代码的更新
@OverrIDeprotected voID onSizeChanged(int w,int oldh) { mBitmap = Bitmap.createBitmap(w,Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); mCanvas.drawcolor(color.GREEN); super.onSizeChanged(w,oldh);}总结
以上是内存溢出为你收集整理的Android:Bitmap:如何在Android中保存带绿色背景的画布?全部内容,希望文章能够帮你解决Android:Bitmap:如何在Android中保存带绿色背景的画布?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)