Android中缩放图片

2015-01-11 0 704
Android中缩放图片
public static Drawable resizeImage(Bitmap bitmap, int w, int h) {

                // load the origial Bitmap
                Bitmap BitmapOrg = bitmap;

                int width = BitmapOrg.getWidth();
                int height = BitmapOrg.getHeight();
                int newWidth = w;
                int newHeight = h;

                // calculate the scale
                float scaleWidth = ((float) newWidth) / width;
                float scaleHeight = ((float) newHeight) / height;

                // create a matrix for the manipulation
                Matrix matrix = new Matrix();
                // resize the Bitmap
                matrix.postScale(scaleWidth, scaleHeight);
                // if you want to rotate the Bitmap
                // matrix.postRotate(45);

                // recreate the new Bitmap
                Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width,
                                height, matrix, true);

                // make a Drawable from Bitmap to allow to set the Bitmap
                // to the ImageView, ImageButton or what ever
                return new BitmapDrawable(resizedBitmap);

        }

遇见资源网 java Android中缩放图片 http://www.ox520.com/8311.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务