how to compress Uri image to bitmap

半世苍凉 提交于 2019-12-04 10:03:10

Try to use this code hope it help you

Uri selectedImage = imageReturnedIntent.getData();

InputStream imageStream = null;
try {
    imageStream = getContentResolver().openInputStream(
            selectedImage);
} catch (FileNotFoundException e) {
    e.printStackTrace();
}

Bitmap bmp = BitmapFactory.decodeStream(imageStream);

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
try {
    stream.close();
    stream = null;
} catch (IOException e) {

    e.printStackTrace();
}
Mohan

Try this one.

try {

url = new URL("Image URL");
InputStream is = url.openConnection().getInputStream();
bitmap = BitmapFactory.decodeStream(is);
iv.setImageBitmap(bitmap);

} catch (Exception e) {
e.printStackTrace();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!