cats-oss / android-gpuimage

Android filters based on OpenGL (idea from GPUImage for iOS)
8.98k stars 2.26k forks source link

convertToBitmap() does not draw the picture in full size #453

Open codenia opened 5 years ago

codenia commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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.

Aw0k3n commented 4 years ago

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?

MrShashankBisht commented 3 years ago

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;
                }
super963883929 commented 2 years ago

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