decode returned false"-6ren"> decode returned false"-我尝试使用 FlushedInputStream :Android decoder->decode returned false for Bitmap download 但没有任何变化,因为我使用:B-6ren">
gpt4 book ai didi

android - 下载图片并在ImageView中查看时为"decoder->decode returned false"

转载 作者:行者123 更新时间:2023-11-30 04:20:35 28 4
gpt4 key购买 nike

我尝试使用 FlushedInputStream :Android decoder->decode returned false for Bitmap download

但没有任何变化,因为我使用:BitmapFactory.decodeFile(path_of_my_downloaded_file), 不使用 BitmapFactory.decodeStream

这是我的下载文件代码:

  public static boolean downloadFile(String url, String dir, String name){
Log.i("Start Downloading ", "=");
// Create download folder:
File f = new File(dir);
if(!f.exists()){
f.mkdirs();
}
try {
File fTo = new File(dir, name);
URL downloadUrl = new URL(url);
//create the new connection
HttpURLConnection urlConnection = (HttpURLConnection) downloadUrl.openConnection();
//set up some things on the connection
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
//and connect!
urlConnection.connect();
FlushedInputStream in = new FlushedInputStream(downloadUrl.openStream());

// in = new FlushedInputStream(in);

byte[] buffer= new byte[4096];
// Write file to toFolder
FileOutputStream os = new FileOutputStream(fTo);
try {
do{
int numread = in.read(buffer);
if (numread <= 0) {
break;
}
os.write(buffer, 0, numread);
}while(true);
} catch (ConnectTimeoutException e) {
e.printStackTrace();
return false;

}
if (os != null) {
os.close();
}
if (in != null) {
in.close();
}
} catch (IOException e) {
Log.e("Error reading file", e.toString());
return false;
}
return true;
}

这是我将位图设置为 ImageView 的代码:

Bitmap bitmap = BitmapFactory.decodeFile(my_file);
mImageView.setImageBitmap(bitmap);

我总是"decoder->decode returned false"

注意:我必须先下载这张图片。

最佳答案

这是图像的问题。

关于android - 下载图片并在ImageView中查看时为"decoder->decode returned false",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9306034/

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