是否可以通过在文件中滑动来保存调整大小的图像?
@H_403_2@我正在使用此代码:
Glide .with(context) .load(path) .override(600,200) .centerCrop() .into(imageViewResizeCenterCrop);
我该怎么办?
谢谢
解决方法
是的,这是可能的.我正在使用我为此特定目的创建的SimpleTarget(在Glide用语中为
custom target)后代.它使用起来非常简单.这是目标代码:
import android.graphics.Bitmap; import com.bumptech.glide.request.animation.GlideAnimation; import com.bumptech.glide.request.target.SimpleTarget; import java.io.FileOutputStream; import java.io.IOException; public class FileTarget extends SimpleTarget<Bitmap> { public FileTarget(String fileName,int width,int height) { this(fileName,width,height,Bitmap.CompressFormat.JPEG,70); } public FileTarget(String fileName,int height,Bitmap.CompressFormat format,int quality) { super(width,height); this.fileName = fileName; this.format = format; this.quality = quality; } String fileName; Bitmap.CompressFormat format; int quality; public void onResourceReady(Bitmap bitmap,GlideAnimation anim) { try { FileOutputStream out = new FileOutputStream(fileName); bitmap.compress(format,quality,out); out.flush(); out.close(); onFileSaved(); } catch (IOException e) { e.printStackTrace(); onSaveException(e); } } public void onFileSaved() { // do nothing,should be overriden (optional) } public void onSaveException(Exception e) { // do nothing,should be overriden (optional) } }
以下是您在自己的示例中使用它的方法:
Glide .with(context) .load(path) .asBitmap() .centerCrop() .into(new FileTarget(pathToDestination,600,200));