嗨,我試圖保存圖片下載設備存儲我有這種方法來保存圖片在存儲中,但保存後,我發現圖片質量不好,請幫我我想保存圖片與同一部開拓創新的質量保存後使用Glide庫後圖像質量不佳
Glide.with(mContext)
.load("YOUR_URL")
.asBitmap()
.into(new SimpleTarget<Bitmap>(100,100) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
saveImage(resource);
}});
private String saveImage(Bitmap image) {
String savedImagePath = null;
String imageFileName = "JPEG_" + "FILE_NAME" + ".jpg";
File storageDir = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
+ "/YOUR_FOLDER_NAME");
boolean success = true;
if (!storageDir.exists()) {
success = storageDir.mkdirs();
}
if (success) {
File imageFile = new File(storageDir, imageFileName);
savedImagePath = imageFile.getAbsolutePath();
try {
OutputStream fOut = new FileOutputStream(imageFile);
image.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.close();
} catch (Exception e) {
e.printStackTrace();
}
// Add the image to the system gallery
galleryAddPic(savedImagePath);
Toast.makeText(mContext, "IMAGE SAVED"), Toast.LENGTH_LONG).show();
}
return savedImagePath;
}
private void galleryAddPic(String imagePath) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(imagePath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
sendBroadcast(mediaScanIntent);
}
嘗試使用'.dontTransform()'。參考https://github.com/bumptech/glide/issues/1227 –
@ wick.ed不工作:( – pic
aww :('.into(new SimpleTarget(100,100)'這可能是問題嗎?增加它看看它是否有幫助,使它600,600或更多的測試,並嘗試改變'Bitmap.CompressFormat.JPEG'爲PNG。 –