【发布时间】:2017-05-17 14:37:33
【问题描述】:
我的一些图像加载到旋转的 imageview 中时遇到了问题。我通过使用 Glide 加载图像解决了这个问题。
图像在 100 x 100 的图像视图中加载。我可以检索存储在该图像视图中的图像为 100 x 100 并将其上传到服务器而不是发送原始图像吗?
【问题讨论】:
我的一些图像加载到旋转的 imageview 中时遇到了问题。我通过使用 Glide 加载图像解决了这个问题。
图像在 100 x 100 的图像视图中加载。我可以检索存储在该图像视图中的图像为 100 x 100 并将其上传到服务器而不是发送原始图像吗?
【问题讨论】:
是的,你可以
public byte[] getImageFromImageView(ImageView imageView,String filePath) {
Drawable imageDrawable = imageView.getDrawable();
Bitmap imageBitmap = ((BitmapDrawable)imageDrawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
return byteArray;
}
然后上传文件到服务器,或者你可以创建RequestBody如果你使用Retrofit将它发送到服务器。
【讨论】:
getCacheDir() 并将存在标志上的删除设置为 true