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

save the gpuimage to file is not correct

Open MoliByte opened this issue 7 years ago • 8 comments

when i set type of gpuImageView.setScaleType(GPUImage.ScaleType.CENTER_INSIDE); gpuImageView.saveToPictures("GUP_IMG", "IMG_" + new SimpleDateFormat("yyyyMMdd_HHmmssSSS").format(new Date()) + ".jpg", new GPUImageView.OnPictureSavedListener() { @Override public void onPictureSaved(Uri uri) {

                    }
                });

then, the ouput file is not correct, the picture is with black edge between left and right? how could figure it out about it?

MoliByte avatar Sep 08 '16 13:09 MoliByte

I solved this problem . for save image , use this :

private void saveImage() {

    String FileName = System.currentTimeMillis() + ".jpg";
    File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File file = new File(path, "GPUImage" + "/" + FileName);
    file.getParentFile().mkdirs();`

    FileOutputStream out = null;
    Bitmap bitmap = mGPUImageView.getGPUImage().getBitmapWithFilterApplied();
    try {
        out = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}`

Hitexroid avatar Oct 13 '16 20:10 Hitexroid

@Hitexroid ,that's perfect,it's worked well, thanks

MoliByte avatar Oct 15 '16 02:10 MoliByte

@ceozhu After a period of research and testing, This is my code was used to be solve:

private void startSavePhoto() {
        final String TEMP_FOLDER = AppConst.PATH_FILE_SAVE_PHOTO + AppConst.PATH_FILE_SAVE_TEMP;
        ExtraUtils.createFolder(TEMP_FOLDER);
        final String TEMP_FILE_NAME = ".ImageEffect.png";

        // Save Photo based on original file
        Bitmap source = BitmapFactory.decodeFile(this.mPhotoFilePath);
        String pathFile = TEMP_FOLDER + File.separator + TEMP_FILE_NAME;
        Bitmap bitmap = gpuImage.getGPUImage().getBitmapWithFilterApplied(source);

        // Bitmap to File
        if (ExtraUtils.saveBitmapToPNG(bitmap, pathFile)) {
            showSaveWithAdsDialog(pathFile);
        } else {
            T.show(R.string.error_save_image);
        }
    }

HungTDO avatar Apr 26 '17 09:04 HungTDO

@Hitexroid it's worked well, but i'll get a filter image with black mask or even a black image chanciness

hpuhsp avatar Nov 05 '18 04:11 hpuhsp

@Hitexroid it's worked well, but i'll get a filter image with black mask or even a black image chanciness

I always have this problem when I save the filter image. Do you have solved it?

bongro avatar Jul 10 '19 03:07 bongro

Anyone found a good solution to this? :D

andreiverdes avatar Apr 16 '20 18:04 andreiverdes

@andreiverdes You can save the Bitmap image after applying a filter effect as below.

public synchronized void getBitmapGL(final Bitmap bitmap, final BitmapReadyCallbacks bitmapReadyCallbacks){
        mGLSurfaceView.queueEvent(() -> {
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            int[] mFrameBuffers = new int[1];
            int[] mFrameBufferTextures = new int[1];
            GLES20.glGenFramebuffers(1, mFrameBuffers, 0);
            GLES20.glGenTextures(1, mFrameBufferTextures, 0);
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mFrameBufferTextures[0]);
            GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
            GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
            GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
            GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
            GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
            GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBuffers[0]);
            GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, mFrameBufferTextures[0], 0);
            GLES20.glViewport(0, 0, width, height);
            mFilter.onOutputSizeChanged(width, height);
            //mFilter.onDisplaySizeChanged(mImageWidth, mImageHeight);
            int texture = OpenGlUtils.loadTexture(bitmap, OpenGlUtils.NO_TEXTURE, true);
            mFilter.onDrawFrame(texture);
            IntBuffer ib = IntBuffer.allocate(width * height);
            GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ib);
            Bitmap mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mBitmap.copyPixelsFromBuffer(IntBuffer.wrap(ib.array()));
            GLES20.glDeleteTextures(1, new int[]{texture}, 0);
            GLES20.glDeleteFramebuffers(1, mFrameBuffers, 0);
            GLES20.glDeleteTextures(1, mFrameBufferTextures, 0);
            GLES20.glViewport(0, 0, mSurfaceWidth, mSurfaceHeight);
            mFilter.destroy();
            mFilter.init();
            mFilter.onOutputSizeChanged(mImageWidth, mImageHeight);

            if (bitmapReadyCallbacks != null) {
                bitmapReadyCallbacks.onBitmapReady(mBitmap);
            }
        });
    }
.....
public interface BitmapReadyCallbacks {
        void onBitmapReady(Bitmap bitmap);
    }

monxarat avatar Apr 17 '20 01:04 monxarat

@monxarat Thanks! I'll give it a try!

andreiverdes avatar Apr 17 '20 07:04 andreiverdes