android-gpuimage
android-gpuimage copied to clipboard
save the gpuimage to file is not correct
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?
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 ,that's perfect,it's worked well, thanks
@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);
}
}
@Hitexroid it's worked well, but i'll get a filter image with black mask or even a black image chanciness
@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?
Anyone found a good solution to this? :D
@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 Thanks! I'll give it a try!