그림 크기 조정 방법

2182 단어 그림
코드 1:
 
public Bitmap ResizeBitmap(Bitmap bitmap, int newWidth) { 
            int width = bitmap.getWidth(); 
            int height = bitmap.getHeight(); 
            float temp = ((float) height) / ((float) width); 
            int newHeight = (int) ((newWidth) * temp); 
            float scaleWidth = ((float) newWidth) / width; 
            float scaleHeight = ((float) newHeight) / height; 
            Matrix matrix = new Matrix(); 
            // resize the bit map 
            matrix.postScale(scaleWidth, scaleHeight); 
            // matrix.postRotate(45); 
            Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); 
            bitmap.recycle(); 
            return resizedBitmap; 
       }    

코드 2:
   public Bitmap resizeBitmap(Bitmap bitmap, int maxWidth, int maxHeight) {
            int originWidth  = bitmap.getWidth();
            int originHeight = bitmap.getHeight();

            // no need to resize
            if (originWidth < maxWidth && originHeight < maxHeight) {
                return bitmap;
            }

            int width  = originWidth;
            int height = originHeight;

            //      ,           
            if (originWidth > maxWidth) {
                width = maxWidth;

                double i = originWidth * 1.0 / maxWidth;
                height = (int) Math.floor(originHeight / i);

                bitmap = Bitmap.createScaledBitmap(bitmap, width, height, false);
            }

            //      ,       
            if (height > maxHeight) {
                height = maxHeight;
                bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height);
            }

//            Log.i(TAG, width + " width");
//            Log.i(TAG, height + " height");
              
            return bitmap;
        }
        

좋은 웹페이지 즐겨찾기