2
所以我的問題與標題狀態完全一樣。我正在下載許多不同的圖像並縮放它們,然後將它們設置爲視圖。我的問題是,似乎只有.gif
圖像在創建的視圖中可見,並且應該包含.jpg
圖像的視圖幾乎爲空。我之所以說,幾乎是因爲在不同形狀的每一個視圖上似乎都有一個奇怪的小黑點,而我意思是一段時間的大小,所以那些圖像可能是圖像,但尺寸太小了。任何幫助... p.s雖然輸出,我相信圖像正在通過我的位圖,並使其setImageBitmap()。設置位圖雖然setImageBitmap()結果只有GIFs在視圖中可見
我的位圖創建方法:
@Override
protected Bitmap doInBackground(String... url) {
String url1 = url[0];
InputStream s = null;
try {
s = (new URL(url1)).openStream();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
final BufferedInputStream is = new BufferedInputStream(s, 32*1024);
try {
final Options decodeBitmapOptions = new Options();
// For further memory savings, you may want to consider using this option
// decodeBitmapOptions.inPreferredConfig = Config.RGB_565; // Uses 2-bytes instead of default 4 per pixel
if(parent.getResources().getDisplayMetrics().widthPixels >0) {
final Options decodeBoundsOptions = new Options();
decodeBoundsOptions.inJustDecodeBounds = true;
is.mark(32*1024); // 32k is probably overkill, but 8k is insufficient for some jpgs
BitmapFactory.decodeStream(is,null,decodeBoundsOptions);
is.reset();
final int originalWidth = decodeBoundsOptions.outWidth;
final int originalHeight = decodeBoundsOptions.outHeight;
Debug.out("Inbound image preview for : "+url1);
Debug.out(originalWidth);
Debug.out(originalHeight);
// inSampleSize prefers multiples of 2, but we prefer to prioritize memory savings
decodeBitmapOptions.inSampleSize= Math.max(1,Math.min(originalWidth/2, originalHeight/2));
}
return BitmapFactory.decodeStream(is,null,decodeBitmapOptions);
} catch(IOException e) {
throw new RuntimeException(e); // this shouldn't happen
} finally {
try {
is.close();
} catch(IOException ignored) {}
}
}
而且這裏是我下載後把我的新形象:
protected void onPostExecute(Bitmap map) {
//image is a object of type ImageView that has already been added to to the grand scheme of things
image.setImageBitmap(map);
}
我是否需要更新視圖或東西嗎?如果是這樣,爲什麼我的gif加載得很好?