Java BitmapFactory在.png图像上工作得非常好,但从url加载jpeg图像时返回null
BitmapFactory在.png图像上工作得非常好,但从url加载jpeg图像时返回nullJava BitmapFactory在.png图像上工作得非常好,但从url加载jpeg图像时返回null,java,android,Java,Android,BitmapFactory在.png图像上工作得非常好,但从url加载jpeg图像时返回null BitmapFactory.decodeStream( (InputStream) new URL(URL).getContent(), null, options); 我使用这段代码,但当我提供一个jpeg图像url时,它返回null 我该怎么办?检查您的jpg中是否设置了颜色配置文件。 Android位图解码器因此让我失望。 遗憾的是,我没有时间或资源来找到解决办法 要知道jpg中是否设置了颜
BitmapFactory.decodeStream( (InputStream) new URL(URL).getContent(), null, options);
我使用这段代码,但当我提供一个jpeg图像url时,它返回null
我该怎么办?检查您的jpg中是否设置了颜色配置文件。 Android位图解码器因此让我失望。 遗憾的是,我没有时间或资源来找到解决办法
要知道jpg中是否设置了颜色配置文件,请尝试使用photoshop打开它,如果有,它会提示您询问如何处理配置文件。检查jpg中是否设置了颜色配置文件。 Android位图解码器因此让我失望。 遗憾的是,我没有时间或资源来找到解决办法
要知道jpg中是否设置了颜色配置文件,请尝试使用photoshop打开它,如果有,则会提示您询问如何处理配置文件。尝试这种方法。它是否适用于.jpg图像
Bitmap bitmaps = LoadImage(strMainImageLink, new BitmapFactory.Options()); where **LoadImage** method is as shown below
加载图像方法
private Bitmap LoadImage(String URL, BitmapFactory.Options options)
{
Bitmap bitmap = null;
InputStream in = null;
try {
// in = OpenHttpConnection(URL);
bitmap = BitmapFactory.decodeStream(OpenHttpConnection(URL), null, options);
// in.close();
} catch (IOException e1) {
Log.e("erererere", e1.toString());
}
return bitmap;
}
private InputStream OpenHttpConnection(String strURL) throws IOException{
InputStream inputStream = null;
URL url = new URL(strURL);
URLConnection conn = url.openConnection();
try{
HttpURLConnection httpConn = (HttpURLConnection)conn;
httpConn.setRequestMethod("GET");
httpConn.connect();
if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
inputStream = httpConn.getInputStream();
}
}
catch (Exception ex)
{
Log.e("error",ex.toString());
}
return inputStream;
}
试试这个方法,它可能对我有用.jpg图像
Bitmap bitmaps = LoadImage(strMainImageLink, new BitmapFactory.Options()); where **LoadImage** method is as shown below
加载图像方法
private Bitmap LoadImage(String URL, BitmapFactory.Options options)
{
Bitmap bitmap = null;
InputStream in = null;
try {
// in = OpenHttpConnection(URL);
bitmap = BitmapFactory.decodeStream(OpenHttpConnection(URL), null, options);
// in.close();
} catch (IOException e1) {
Log.e("erererere", e1.toString());
}
return bitmap;
}
private InputStream OpenHttpConnection(String strURL) throws IOException{
InputStream inputStream = null;
URL url = new URL(strURL);
URLConnection conn = url.openConnection();
try{
HttpURLConnection httpConn = (HttpURLConnection)conn;
httpConn.setRequestMethod("GET");
httpConn.connect();
if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
inputStream = httpConn.getInputStream();
}
}
catch (Exception ex)
{
Log.e("error",ex.toString());
}
return inputStream;
}
URL唯一地标识web上的资源。测试url的一个好方法是使用浏览器。我不知道新的URL(URL)应该做什么。URL接受一个字符串参数,但其他构造函数是可用的。如果您将字符串传递给构造函数,您可能希望为该字符串指定一个值,或者仅使用文本字符串示例新URL(“google.com”),至少您将获得除空指针以外的内容。我无法知道你的图片是什么url,因为网络是一个很大的地方 URL唯一地标识web上的资源。测试url的一个好方法是使用浏览器。我不知道新的URL(URL)应该做什么。URL接受一个字符串参数,但其他构造函数是可用的。如果您将字符串传递给构造函数,您可能希望为该字符串指定一个值,或者仅使用文本字符串示例新URL(“google.com”),至少您将获得除空指针以外的内容。我无法知道你的图片是什么url,因为网络是一个很大的地方 但图像随机来自互联网。有同样的问题。第一件事。下载不起作用的文件并检查颜色配置文件。然后,对您知道没有颜色配置文件的图像尝试相同的代码。如果它加载正确,你就找到了罪魁祸首。但图像随机来自互联网。也有同样的问题。第一件事。下载不起作用的文件并检查颜色配置文件。然后,对您知道没有颜色配置文件的图像尝试相同的代码。如果装载正确,你就找到了罪犯。