BitmapFactory は .png 画像で完全に動作しますが、URL から jpeg 画像を読み込むと null を返します。
BitmapFactory.decodeStream( (InputStream) new URL(URL).getContent(), null, options);
このコードを使用しますが、jpeg 画像の URL を指定すると null が返されます。
私は何をすべきか?
この方法を試してみてください.jpg画像でうまくいくかもしれません
Bitmap bitmaps = LoadImage(strMainImageLink, new BitmapFactory.Options()); where **LoadImage** method is as shown below
LoadImageメソッド
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 にカラー プロファイルが設定されているかどうかを確認します。これが原因で、Android ビットマップ デコーダーに失敗しました。悲しいことに、これに対する解決策を見つける時間もリソースもありませんでした。
jpg にカラー プロファイルが設定されているかどうかを確認するには、Photoshop で開いてみてください。ある場合は、プロファイルをどうするかを尋ねるプロンプトが表示されます。