开发者

image issue on android

开发者 https://www.devze.com 2023-01-21 02:19 出处:网络
I have downloaded the image from given url,and displayed in the imageview,which works fine in the emulator .but not works in real device... whats the problem?

I have downloaded the image from given url,and displayed in the imageview,which works fine in the emulator .but not works in real device... whats the problem?

Here my code

final String url = urlStr;
            InputStream inputStream = null;

            try {
                inputStream = httpRequest.openHttpConnection(url);
    开发者_JAVA百科            if(inputStream!=null)
                {
                bitmap = BitmapFactory.decodeStream(inputStream);
               if(bitmap!=null)
                {
                width=bitmap.getWidth();
                height=bitmap.getHeight();
                int newWidth = 50;
                int newHeight = 50;
             // calculate the scale - in this case = 0.4f
                float scaleWidth = ((float) newWidth) / width;
                float scaleHeight = ((float) newHeight) / height;
                // create matrix for the manipulation
                Matrix matrix = new Matrix();
                // resize the bit map
                matrix.postScale(scaleWidth, scaleHeight);
               // recreate the new Bitmap
               resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,width, height, matrix, true);
                }
               inputStream.close();
            } 
            }
            catch (IOException e1)
            {
                e1.printStackTrace();
            }
            return  resizedBitmap;


why dont you resize it the easy way?

Bitmap scaledImage = Bitmap.createScaledBitmap(bitmap, intWidth, intHeight, false);
0

精彩评论

暂无评论...
验证码 换一张
取 消