android - 如何更改图像背景颜色并使用新背景颜色保存
问题描述
我有一个应用程序可以删除图像背景并设置新的蓝色背景颜色并保存它,但是当我打开图像时它显示黑色背景。
我怎样才能用蓝色背景保存这个?
imageView.setBackgroundColor(ContextCompat.getColor(this, R.color.blue));
BitmapDrawable draw = (BitmapDrawable) imageView.getDrawable();
BitmapDrawable draw = (BitmapDrawable) imageView.getDrawable();
Bitmap bitmap = draw.getBitmap();
FileOutputStream outStream = null;
File file = Environment.getExternalStorageDirectory();
File dir = new File(file.getAbsolutePath() + "/Passport Photo123");
dir.mkdirs();
String fileName = String.format("%d.jpg", System.currentTimeMillis());
File outFile = new File(dir, fileName);
try {
outStream = new FileOutputStream(outFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
try {
outStream.flush();
outStream.close();
Toast.makeText(this, "Photo Saved at: " + outFile, Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
解决方案
试试这行代码:-
imageView.setBackgroundColor(Color.rgb(100, 100, 50));
如果它不起作用,那么问题必须在其他地方。
推荐阅读
- ruby-on-rails - 如果帐户未在 Rails 中激活,则转到特定页面
- html - div在角度6中切换显示/隐藏父子关系
- python - Python - ModuleNotFoundError:没有名为“pyown”的模块
- r - 使用 dplyr 改变多列中的数据
- csv - 我们可以比较多个输入文件的列以在 SSIS 中派生一个新列吗
- android - 自动创建新表与巨型表
- r - 如何加载本地存在于我的硬盘上的 R 包?
- r - 组合框示例:找不到 tk2list.configure
- ios - iOS 上的 Safari 在调用 canvas.toDataURL 时抛出 SECURITY_ERR: DOM Exception 18
- python - 为什么设置 `random.seed(42)` 在 pytorch 中没有给我相同的结果?