我已經使用DecodeUrl()
解碼了url的圖像,函數返回E_SUCCESS
,但日後顯示「HttpTransaction [0]已經關閉」。如果DecodeUrl()
成功,那麼它也應該調用OnImageDecodeUrlReceived()
,這也沒有發生。我已繼承IImageDecodeUrlEventListener
,給予HTTP權限的應用程序,並驗證了鏈接,但不明白爲什麼日誌顯示「HttpTransaction已關閉」,並且函數OnImageDecodeUrlReceived()
沒有被調用。如何顯示圖片url的位圖?
0
A
回答
1
String path = L"http://www.test.gr/images/23101212121.png";
Image* pImage = new Image();
pImage->Construct();
// Set a URL
Uri uri;
RequestId reqId;
uri.SetUri(path);
// Choose the bitmap pixel format
BitmapPixelFormat format;
if(path.EndsWith(L"jpg") or path.EndsWith(L"bmp") or path.EndsWith(L"gif"))
{
format = BITMAP_PIXEL_FORMAT_RGB565;
}
else if(path.EndsWith(L"png"))
{
format = BITMAP_PIXEL_FORMAT_ARGB8888;
}
// Request image
pImage->DecodeUrl(uri, format, 224, 127, reqId, *this, 5000);
請點擊此鏈接,使請求成功 link
您可以在Tizen與下面的工具的幫助下運行的bada項目
0
非常快速的方法:
private Bitmap getBitmap(String url)
{
File f=fileCache.getFile(url);
//from SD cache
Bitmap b = decodeFile(f);
if(b!=null)
return b;
//from web
try {
Bitmap bitmap=null;
URL imageUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setInstanceFollowRedirects(true);
InputStream is=conn.getInputStream();
OutputStream os = new FileOutputStream(f);
Utils.CopyStream(is, os);
os.close();
bitmap = decodeFile(f);
return bitmap;
} catch (Exception ex){
ex.printStackTrace();
return null;
}
}
//decodes image and scales it to reduce memory consumption
private Bitmap decodeFile(File f){
try {
//decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f),null,o);
//Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE=70;
int width_tmp=o.outWidth, height_tmp=o.outHeight;
int scale=1;
while(true){
if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
break;
width_tmp/=2;
height_tmp/=2;
scale*=2;
}
//decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
} catch (FileNotFoundException e) {}
return null;
}
相關問題
- 1. 圖片標記不顯示圖片,而圖片url很好。 MVC
- 2. Android如何在片段中顯示來自URL的圖片
- 3. 無法顯示URL圖像(位圖)
- 4. 無法顯示背景圖片的URL
- 5. 在xml文件中顯示圖片url中的圖片
- 6. 圖片URL的位置
- 7. 如何在片段中使用位圖和AsyncTask顯示圖像?
- 8. 得到位圖的碎片,無顯示
- 9. 如何讀取URL的圖片,並顯示我的
- 10. 從URL顯示圖片到wxPython
- 11. 圖片顯示
- 12. 顯示圖片
- 13. 顯示圖片
- 14. 顯示圖片
- 15. 圖片干預URL操縱顯示空白圖片
- 16. 如何在黑莓中顯示來自URL的圖片?
- 17. 沒有顯示圖片的圖片
- 18. 懸停顯示圖片上的圖片
- 19. 九貼片位圖不顯示
- 20. 如何通過點擊圖片來顯示圖片的名稱?
- 21. 如何在uiwebview ios swift上顯示圖片庫中的圖片?
- 22. 如何顯示來自url的圖像
- 23. 如何顯示來自url的圖像
- 24. 如何顯示圖庫中的照片?
- 25. 的Response.Write - 如何顯示圖片
- 26. 如何顯示上傳的圖片?
- 27. 如何正確形成的URL顯示位圖
- 28. 顯示位圖
- 29. 圖片URL創建位圖android
- 30. 如何在地圖上顯示位圖之前縮放位圖?