-3

enter image description here

Hi everyone, I am new to android dev.

I have an app that will erase part of the bitmap. I am using matrix to scale rotate the image. Without scaling, the transparent eraser is same size with the circle, but when i scale the bitmap the eraser transparent is bigger than the circle size which is fixed. Can someone help me out?.. I am struggling this for 1 week now.

Here's the code I am using:

            RectF r = new RectF(); 
            matrix.mapRect(r);
            // sol1
            float scaledX = (lastX - r.left) + 48; // adjust to the tip of eraser
            float scaledY = (lastY - r.top) - 137; // adjust to the tip of eraser
            float[] values = new float[9];
            matrix.getValues(values);
            float scalex = values[Matrix.MSCALE_X];
            float skewy = values[Matrix.MSKEW_Y];
            float scale = (float) Math.sqrt(scalex * scalex + skewy * skewy);
            scaledX /= scale;
            scaledY /= scale;

            Bitmap bmOverlay = Bitmap.createBitmap(bitmap.getWidth(), 
                                                   bitmap.getHeight(), 
                                                   Bitmap.Config.ARGB_8888);
            System.out.println("bitmap.getWidth() " + bitmap.getWidth() + 
                               " bitmap.getHeight() " + bitmap.getHeight());
            Canvas c = new Canvas(bmOverlay);
            c.drawColor(Color.TRANSPARENT, Mode.CLEAR);


            c.drawBitmap(bitmap, 0, 0, null);
            c.drawCircle(scaledX, scaledY, 13.0f, mPaint); // punch a hole
            bitmap = bmOverlay; // update the main bitmap
donmj
  • 379
  • 7
  • 13
  • hi pskink :) I have followed your code on the image layering. Thanks for this answer again. I have figured it out :). Thanks man – donmj Nov 07 '15 at 13:49
  • mage layering? what mage layering? did `13.0f / scale` work? – pskink Nov 07 '15 at 13:50
  • Yeah it work now. Yes you have tutorial this post [link](http://stackoverflow.com/questions/16729169/how-to-maintain-multi-layers-of-imageviews-and-keep-their-aspect-ratio-based-on/16800944#16800944). :). I have been using – donmj Nov 07 '15 at 13:56
  • hmm. Without rotating on matrix the scaledX and scaledY works fine. But when i rotate the bitmap the scaledX and scaledY now is not sync to my finder point. :( – donmj Nov 07 '15 at 14:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/94487/discussion-between-donmj-and-pskink). – donmj Nov 07 '15 at 14:05

1 Answers1

0

Finally I am able to achieved:

I just comment the below lines :).

// cursor
    paintCursorRed.setColor(0xffff0000);
    paintCursorRed.setStyle(Style.STROKE);
    paintCursorBlackdraw.setColor(0xffffff00);
    paintCursorBlackdraw.setStyle(Style.STROKE); 
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaint.setStrokeJoin(Paint.Join.BEVEL);
    mPaint.setStrokeCap(Paint.Cap.SQUARE);
    //mPaint.setStrokeWidth(15);
    //mPaint.setTextSize(15);
    mPaint.setAlpha(0);
    mPaint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
    mPaint.setAntiAlias(true);
    // mPaint.setMaskFilter(new BlurMaskFilter(5, Blur.NORMAL));
donmj
  • 379
  • 7
  • 13