android-gpuimage icon indicating copy to clipboard operation
android-gpuimage copied to clipboard

convertToBitmap() does not draw the picture in full size

Open codenia opened this issue 5 years ago • 5 comments

The convertToBitmap() does not draw the picture in full size.

The source picture looks like this:

Bildschirmfoto 2019-03-31 um 15 03 27

If I use getBitmapWithFilterApplied with or without filters then the image is returned incorrectly drawn.

In the file PixelBuffer.java in the function convertToBitmap an empty image is created in the correct size. After the line GPUImageNativeLibrary.adjustBitmap(bitmap); the picture is unfortunately drawn wrong:

Bildschirmfoto 2019-03-31 um 15 03 57

The source image has the width 1777 pixels and height 2666 pixels. Density is 444 DPI.

codenia avatar Mar 31 '19 13:03 codenia

It has something to do with density. If I set Density to 320, then the picture is almost right, but only almost. On the right is a line with empty pixels.

codenia avatar Mar 31 '19 13:03 codenia

The problem with the empty line is because of the odd number of width. Why is it so? If the width is 1778, then this line does not exist.

codenia avatar Mar 31 '19 13:03 codenia

Same Problem here. Setting a Image with an odd number of pixels returns a zoomed in Picture.. setImageBitmap should handle it.

public void setImageBitmap(final Bitmap bitmap, final boolean recycle) {
        if (bitmap == null) {
            return;
        }

        runOnDraw(new Runnable() {

            @Override
            public void run() {
                Bitmap resizedBitmap = null;
                if (bitmap.getWidth() % 2 == 1) {
                    resizedBitmap = Bitmap.createBitmap(bitmap.getWidth() + 1, bitmap.getHeight(),
                            Bitmap.Config.ARGB_8888);
                    Canvas can = new Canvas(resizedBitmap);
                    can.drawARGB(0x00, 0x00, 0x00, 0x00);
                    can.drawBitmap(bitmap, 0, 0, null);
                    mAddedPadding = 1;
                } else {
                    mAddedPadding = 0;
                }

                mGLTextureId = OpenGlUtils.loadTexture(
                        resizedBitmap != null ? resizedBitmap : bitmap, mGLTextureId, recycle);
                if (resizedBitmap != null) {
                    resizedBitmap.recycle();
                }
                mImageWidth = bitmap.getWidth();
                mImageHeight = bitmap.getHeight();
                adjustImageScaling();
            }
        });
    }

But its not working. If setImage is not handling that case. What does resizeBitmap and Padding do?

Aw0k3n avatar Apr 28 '20 12:04 Aw0k3n

Same problem with me @Aw0k3n . I have just Comment this line of code and it works well.

if (bitmap.getWidth() % 2 == 1) {
                    resizedBitmap = Bitmap.createBitmap(bitmap.getWidth() + 1, bitmap.getHeight(),
                            Bitmap.Config.ARGB_8888);
                    Canvas can = new Canvas(resizedBitmap);
                    can.drawARGB(0x00, 0x00, 0x00, 0x00);
                    can.drawBitmap(bitmap, 0, 0, null);
                    mAddedPadding = 1;
                } else {
                    mAddedPadding = 0;
                }

MrShashankBisht avatar Apr 19 '21 12:04 MrShashankBisht

Me too, using GPUImageView when it loads, when it saves the image it's not full size

super963883929 avatar Aug 20 '22 04:08 super963883929