在 Android 中从 Cloudinary 下载图像
Downloading images from Cloudinary in Android
我正在尝试弄清楚图像转换过程的最佳工作流程是什么,在该过程中将转换后的图像再次上传到另一个 API。
根据 Cloudinary (http://cloudinary.com/documentation/image_transformations#resizing_and_cropping_images),我可以访问具有以下类型 URL 结构的上传图像并同时转换它们:http://res.cloudinary.com/demo/image/upload/w_200,h_100/sample.jpg
.
假设 sample.jpg 已经存在于 Cloudinary 中,所提供的 link 将使用已经应用的图像调整大小转换来获取它。
我可以简单地将这个 link 提供给 Picasso 并将其转换为位图吗?
Picasso.with(this)
.load("http://res.cloudinary.com/demo/image/upload/w_200,h_100/sample.jpg")
.into(new Target() {
@Override
public void onBitmapLoaded (final Bitmap bitmap, Picasso.LoadedFrom from){
/* Save the bitmap or do something with it here */
UploadBitmap(bitmap);
}
});
抱歉,我真的不知道如何使用 Picasso 来完成,但是使用 Glide 您可以执行以下操作
Glide.with(this).load("path").asBitmap().listener(new RequestListener<String, Bitmap>() {
@Override
public boolean onException(Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Bitmap resource, String model, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
}).into(500/*output width*/,500/*output height*/);
是的,购买时在路径中指定 w
和 h
即可操作图像缩放
我正在尝试弄清楚图像转换过程的最佳工作流程是什么,在该过程中将转换后的图像再次上传到另一个 API。
根据 Cloudinary (http://cloudinary.com/documentation/image_transformations#resizing_and_cropping_images),我可以访问具有以下类型 URL 结构的上传图像并同时转换它们:http://res.cloudinary.com/demo/image/upload/w_200,h_100/sample.jpg
.
假设 sample.jpg 已经存在于 Cloudinary 中,所提供的 link 将使用已经应用的图像调整大小转换来获取它。
我可以简单地将这个 link 提供给 Picasso 并将其转换为位图吗?
Picasso.with(this)
.load("http://res.cloudinary.com/demo/image/upload/w_200,h_100/sample.jpg")
.into(new Target() {
@Override
public void onBitmapLoaded (final Bitmap bitmap, Picasso.LoadedFrom from){
/* Save the bitmap or do something with it here */
UploadBitmap(bitmap);
}
});
抱歉,我真的不知道如何使用 Picasso 来完成,但是使用 Glide 您可以执行以下操作
Glide.with(this).load("path").asBitmap().listener(new RequestListener<String, Bitmap>() {
@Override
public boolean onException(Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Bitmap resource, String model, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
}).into(500/*output width*/,500/*output height*/);
是的,购买时在路径中指定 w
和 h
即可操作图像缩放