gpt4 book ai didi

java - 从加载的 ImageView 获取图像

转载 作者:行者123 更新时间:2023-12-02 13:09:05 24 4
gpt4 key购买 nike

我遇到了一个问题,我的一些图像加载到旋转的 imageview 中。我通过使用 Glide 加载图像解决了这个问题。

图像加载到 100 x 100 ImageView 内。我可以检索存储在该 imageview 中的 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;
}

然后将文件上传到服务器,或者如果您使用 Retrofit,您可以创建 RequestBody 并将其发送到服务器。

关于java - 从加载的 ImageView 获取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44027916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com