Android Paint PorterDuff.Mode.CLEAR

后端 未结 1 934
春和景丽
春和景丽 2021-02-09 02:04

I\'m working on application which is drawing on Canvas similar to Finger Paint demo from Android SDK. My problem is when I\'m using PorterDuff.Mode.CLEAR. When draw

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-09 02:35

    The problem with the fingerpaint code is that what you see is not the same that is compressed into the png. Look at onDraw(). First you draw the screen white. Then you add the Bitmap. Because you used Porter Duff Clear the erased part of the bitmap contains actually transparent black pixels (value 0x00000000). But because you have the white background these black pixels show as white.

    To fix this either change your save code to do the same thing as the draw code

     try {
                        fos = new FileOutputStream(file);
                        Bitmap saveBitmap = Bitmap.createBitmap(mBitmap);
                        Canvas c = new Canvas(saveBitmap);
                        c.drawColor(0xFFFFFFFF);
                        c.drawBitmap(mBitmap,0,0,null);
                        saveBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
                        saveBitmap.recycle();
    ...
    

    or don't use PortDuff.Clear:

        case ERASE_MENU_ID:
            mPaint.setColor(Color.WHITE);
    

    0 讨论(0)
提交回复
热议问题