android:如何在下载时压缩位图

时间:2014-02-08 15:00:41

标签: java android bitmap

我的应用程序下载位图:

public byte[] getUrlImgContent(String urlstring) throws IOException
{
    byte[] imageRaw = null;
    URL url = new URL(urlstring);

    HttpURLConnection urlConnection = (HttpURLConnection) url
            .openConnection();
    urlConnection.setUseCaches(false);
    urlConnection.connect();
    if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK)
    {
        try
        {
            InputStream in = new BufferedInputStream(
                    urlConnection.getInputStream());
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            int c;
            while ((c = in.read()) != -1)
            {
                out.write(c);
            }
            out.flush();

            imageRaw = out.toByteArray();

            urlConnection.disconnect();
            in.close();
            out.close();
        } catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return imageRaw;
    }
    return null;
}

我直接将其转换为位图并在zoomable-imageview中显示

问题:如果文件太大,应用程序崩溃

我应该怎么做才能缩小图片尺寸? (格式:jpg)

0 个答案:

没有答案