我使用DecodeUrl()
从网址解码了图像,函数返回E_SUCCESS
但稍后日志显示“HttpTransaction [0]已经关闭”。如果OnImageDecodeUrlReceived()
成功并且也没有发生,它应该调用DecodeUrl()
。我已经继承了IImageDecodeUrlEventListener
,给了应用程序的http privilage并验证了链接,但是无法理解为什么日志显示“HttpTransaction已经关闭”并且函数OnImageDecodeUrlReceived()
没有被调用。
答案 0 :(得分: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项目
答案 1 :(得分: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;
}