0

I'm trying to develop a drawing app and it has a function to let user crop and share the drawing. mBitmap is what I used to create my Canvas.

mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);

I managed to save what user draws, but I can't figure out how to crop the background as well. So I created a new Canvas and

Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);

canvas.drawBitmap(mBitmap, 0, 0, null); 

crop = Bitmap.createBitmap(bitmap, 
            mRect.left,
            mRect.top,
            mRect.width(),
            mRect.height());

saveCropScreenShot(crop));

the above saves my drawing with the crop area but background is missing. My app lets user to change background so it makes more sense to save both drawing and background together. Can anyone help? Thanks!!

Henry
  • 2,953
  • 2
  • 21
  • 34
user1865027
  • 3,505
  • 6
  • 33
  • 71
  • Have you looked into [Porter-Duff](http://stackoverflow.com/questions/8280027/what-does-porterduff-mode-mean-in-android-graphics-what-does-it-do) to 'add' your background back in when you save? – Morrison Chang Apr 06 '17 at 00:55
  • hummm not quite sure how that can be done. i tried to get the background then redraw it before drawing `mBitmap` but when I called `getBackground()` it gives me the original image with different width and height of what user see on the screen – user1865027 Apr 06 '17 at 01:15
  • You probably should explain how are you setting the background. If you are letting the system scale it for you - well you'll need to scale it if you want it to appear the same as what the user sees. – Morrison Chang Apr 06 '17 at 01:40
  • I don't scale it. i only do background="@drawble/background". i don't think this is the right way to crop background tho...scaling to what user see then capture a region then sounds like a lot of work for crop. – user1865027 Apr 06 '17 at 04:49

0 Answers0