- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 getDrawingCache()
方法捕获我的布局 View 并从中创建图像。代码工作正常并生成图像,但这里的问题是,生成的图像质量很低。我希望生成的图像的分辨率很高,这样无论何时将其设置为 ImageView
,它都不会被拉伸(stretch)。
这是我正在使用的代码:
RelativeLayout layout = (RelativeLayout) findViewById(R.id.layout);
layout.setDrawingCacheEnabled(true);
位图 bmp = layout.getDrawingCache();
File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + System.currentTimeMillis()+.jpg");
尝试 {
FileOutputStream out = new FileOutputStream(f);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
关闭();
} catch (IOException e){
e.printStackTrace();
}
附言- 在调用 layout.getDrawingCache() 之前,我还尝试使用
但没有发现质量变化。layout.buildDrawingCache(true);
和 layout.setDrawingCacheQuality(RelativeLayout.DRAWING_CACHE_QUALITY_HIGH);
;
谁能帮我解决这个问题,我怎样才能提高生成图像的质量?提前致谢。
最佳答案
经过很长时间的搜索和尝试不同的解决方案后,我终于获得了比之前更好的捕获图像质量。
我将代码更改为:
RelativeLayout layout = (RelativeLayout) findViewById(R.id.layout);
layout.setDrawingCacheEnabled(true);
layout.buildDrawingCache(true);
final Bitmap bmp = Bitmap.createBitmap(layout.getDrawingCache());
layout.setDrawingCacheEnabled(false);
Canvas c= new Canvas(bmp);
File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/" + System.currentTimeMillis()+".jpg");
try {
FileOutputStream out = new FileOutputStream(f);
c.drawBitmap(bmp, 0, 0, null);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
这对我有帮助。希望它也能帮助其他人。
关于android - 使用 getDrawingCache 提高图像质量 - android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22838387/
我正在尝试在特定图像上添加文本。它工作完美,但图像质量较低,尤其是 papyrus.ttf 字体。如何提高图像中文本的质量。但我需要高质量来打印输出。这是我的代码..它非常简单。 header("Co
是否可以获得现有图像的当前质量? 我想加载一个 JPEG 并在不改变质量和 DPI 的情况下再次保存它。 (我需要在保存前做一些像素操作) 最佳答案 JPEG 是一种有损格式。 这样做的直接方式,读取
我正在构建一个标签打印机。它由一个标志和一些文字组成,并不难。我已经花了 3 天时间尝试将原始 SVG Logo 绘制到屏幕上,但 SVG 太复杂,使用了太多渐变等。 所以我有一个高质量的位图 Log
我正在尝试以最快的方式以编程方式降低图像质量。现在,我能够从 byte[] 读取图像,然后作为 MemoryStream 将其读取到 Bitmap 并通过 Drawing。 Imaging.Encod
我允许用户上传图片。但是,我想保持 JPEG 质量不超过 90%。我打算做的是检测当前质量:- 如果少于 90% 什么都不做- 如果超过 90%,则使用 Image Magick 将图像重新压缩到 9
我正在制作一个 Android 应用程序,该应用程序通过使用内置摄像头作为 Intent 来使用摄像头。我正在逐个像素地对照片进行一些分析。我的 wildfire 在普通照片中返回 79000 像素,
我正在使用 python 程序生成一些数据,使用 matplotlib.pyplot 绘制数据,然后将图形显示在 latex 文件中。 我目前正在将图形保存为 .png 文件,但图像质量不是很好。我试
一直在尝试通过应用引擎将以下 png 文件上传到谷歌云存储: 在上传之前,我通过 PIL 运行它来处理任何图像旋转或背景颜色变化等 但是,即使在 python 命令行中运行相同的命令结果很好,但通过应
给定以下 Image 对象(它位于 ListView 对象的 DataTemplate 中): 我应该如何获得高质量的双三次插值图像? (在屏幕上,此图像的大小小于源 PNG,但默认调整大小似乎
如何在 PHP5 中压缩 GIF 图像文件? 我知道可以像这样处理 JPG imagejpeg($resource, $filename, $quality)根据 http://us.php.net/
我使用 html5 Canvas 元素在我的浏览器中调整图像大小。事实证明,质量非常低。我发现了这个:Disable Interpolation when Scaling a 但这无助于提高质量。 下
我正在使用 Visual Studio 2019 构建带有自定义任务 Pane 的 Excel 插件。 在用作自定义任务 Pane 的用户控件中,我添加了 imlNavigation (图片列表) 我
我是一名优秀的程序员,十分优秀!