【发布时间】:2014-04-02 15:16:07
【问题描述】:
我正在使用以下代码截取我的布局:
View u = findViewById(R.id.mainL);
u.setDrawingCacheEnabled(true);
LinearLayout z = (LinearLayout) findViewById(R.id.mainL);
int totalHeight = z.getHeight();
int totalWidth = z.getWidth();
u.layout(0, 0, totalWidth, totalHeight);
u.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(u.getDrawingCache());
u.setDrawingCacheEnabled(false);
显然我没有在质量方面做任何事情,但结果位图(即 jpeg 图像)的质量非常差。
我做错了什么? 我觉得我应该以某种方式将其更改为 PNG 图像以获得更好的质量,但我不知道如何。 谢谢。
编辑:
对于那些问我在哪里保存位图的人,我不得不说我根本没有保存它。我只是用这段代码分享它:
String pathofBmp = MediaStore.Images.Media.insertImage(getContentResolver(), b , "title", null);
Uri bmpUri = Uri.parse(pathofBmp);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpeg");
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(shareIntent, "Share"));
【问题讨论】:
-
“我做错了什么?” -- 如果没有别的,您没有显示保存 JPEG 文件的代码。 “我认为我应该以某种方式将其更改为 PNG 图像以获得更好的质量,但我不知道如何”——由于您没有提供保存 JPEG 文件的代码,我们无法建议您如何更改该代码用于保存 PNG 文件。
-
看看我编辑的代码。
标签: android screenshot