0

我已经使用从 url 解码图像DecodeUrl()并且函数返回E_SUCCESS但后来日志显示为“HttpTransaction [0] 已关闭”。它也应该调用OnImageDecodeUrlReceived()ifDecodeUrl()成功并且这也没有发生。我继承IImageDecodeUrlEventListener了应用程序的 http 特权并验证了链接,但无法理解为什么日志显示“HttpTransaction 已关闭”并且OnImageDecodeUrlReceived()没有调用该函数。

4

2 回答 2

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);

按照此链接使请求成功 链接

您可以借助以下工具在 Tizen 中运行 bada 项目

看这里

于 2013-11-01T12:52:53.643 回答
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;
    }
于 2013-12-04T14:43:25.577 回答