[英]Image saved in sdcard shows only black screen using GPUImageView in android
我正在开发一个项目,用于对图像应用一些效果,这些效果将从图库中选择或通过相机捕获。
我已经使用GPUImageView库对图像应用不同的效果,并且还实现了搜索栏以增加和减少效果。 一切都很好。
问题是现在我想将效果应用图像保存到SD卡中。 我已经为它编写了代码并且它的工作成功但是保存的图像仍然是黑色的。 每当我检查SD卡中的图像时,除了黑屏外,它不会显示修改后的图像。
我不知道它为什么显示黑色图像。
这是我将GPUImageView
作为drawingcachedenabled设为true并将其保存为图像的代码。
mGPUImageView.setDrawingCacheEnabled(true);
Bitmap bitmap = mGPUImageView.getDrawingCache();
String path = Environment.getExternalStorageDirectory()
.getAbsolutePath();
File fil = new File(path + "/MyPics");
fil.mkdir();
Random rand = new Random();
int aa = rand.nextInt();
String filename = "Photo" + aa+".jpg";
File newImg = new File(fil, filename);
try {
FileOutputStream out = new FileOutputStream(newImg);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
}
Toast.makeText(this,"File Saved at Path---->" + newImg.getAbsolutePath(),
Toast.LENGTH_LONG).show();
mGPUImageView.setDrawingCacheEnabled(false);
请帮我解决这个问题。
您可以为GPUImage
创建对象并应用您的过滤器..
final GPUImage mGpuImage = new GPUImage(getApplicationContext());
mGpuImage.setFilter(new GPUImageSharpenFilter());//Your filter here
Bitmap effectsBItamap=mGpuImage.getBitmapWithFilterApplied(your bitmap);
我已经使用解决了我的问题saveToPictures()
的方法GPUImageView.java
。 我只是将File newImg
转换为Uri
并将其传递给OnPictureSavedListener
类的onPictureSaved
方法的Listener,如下所示:
mGPUImageView.setDrawingCacheEnabled(true);
File fil = new File(path);
fil.mkdir();
Random rand = new Random();
int aa = rand.nextInt();
mGPUImageView.setDrawingCacheEnabled(false);
mGPUImageView.saveToPictures("MyPics", "Photo"+aa+".jpg", picSaveListener);
picSaveListener.onPictureSaved(Uri.fromFile(newImg));
OnPictureSavedListener picSaveListener = new OnPictureSavedListener() {
@Override
public void onPictureSaved(Uri uri) {
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.