[英]Bitmap quality bad after sending (Android/Java)
我正在使用以下位圖:
View v1 = (View) wpm.getParent().getParent();
Bitmap cs = null;
v1.setDrawingCacheEnabled(true);
v1.buildDrawingCache(true);
cs = Bitmap.createBitmap(v1.getDrawingCache(true));
Canvas canvas = new Canvas(cs);
v1.draw(canvas);
canvas.save();
v1.setDrawingCacheEnabled(false);
String path = Images.Media.insertImage(getContext().getContentResolver(), cs, "MyImage", null);
Uri file = Uri.parse(path);
OutputStream outStream = null;
try {
outStream = getContext().getContentResolver().openOutputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
cs.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
//file senden
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, file);
sharingIntent.setType("image/jpeg");
getContext().startActivity(Intent.createChooser(sharingIntent,"Erfolg teilen!"));
當我通過Facebook,Whatsapp發送郵件時,...質量很差。 但是,如果我將其復制到PC上,它看起來正常,那么在通過Facebook發送之前,我可以檢查它的外觀以及那里的外觀。 僅在發送后看起來很糟糕。 我該如何更改?
嘗試設置:
yourView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
如果您的起始位有品質不好,你不能使它與bitmap.compress更好。
請記住 ,更好的質量需要更多的內存。
問題來自以下行:
cs.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
質量100太高,並生成JPG文件的大小過大,無法通過Facebook的被接受。 因此,Facebook的這個壓縮圖像,並減少其質量。 使用以下代碼可以解決您的問題:
cs.compress(Bitmap.CompressFormat.JPEG, 70, outStream);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.