[英]Get image from loaded ImageView
I had a problem where some of my images are loaded inside imageview rotated. 我有一个问题,其中某些图像加载到旋转的imageview内。 I solved the problem by loading an image using Glide.
我通过使用Glide加载图像解决了问题。
The image is loaded inside 100 x 100 imageview. 图像加载到100 x 100 imageview内部。 Can I retrieve the image which is stored inside that imageview as 100 x 100 and upload it to the server instead of sending the original image?
我可以检索存储在该imageview中的图像为100 x 100并将其上传到服务器,而不是发送原始图像吗?
Yes you can 是的你可以
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;
}
Then upload file to server or you can create RequestBody
and send it to server if you using Retrofit. 然后将文件上传到服务器,或者如果使用Retrofit,则可以创建
RequestBody
并将其发送到服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.