android glide默认图片大小,android – 使用Glide保存已调整大小的图像

是的,这是可能的.我正在使用我为此特定目的创建的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 {

public FileTarget(String fileName, int width, int height) {

this(fileName, width, height, Bitmap.CompressFormat.JPEG, 70);

}

public FileTarget(String fileName, int width, 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));

此代码不会在任何视图上显示图像,而是将其直接保存到目标.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值