Scaling bitmap to fill rect with centering. Method keep aspect ratio.

@param src source bitmap
@param w   width of result
@param h   height of result
@return scaled bitmap
346327
public static Bitmap scaleFill(Bitmap src, int w, int h) {
        Bitmap res = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        scaleFill(src, res);
        return res;
    }
564007
public static BufferedImage compression(BufferedImage src, int widthScale, int heightScale) {
        int oldWidth = src.getWidth();
        int oldHeight = src.getHeight();
        int width = oldWidth / widthScale + ((oldWidth % widthScale) > 0 ? 1 : 0);
        int height = oldHeight / heightScale + ((oldHeight % heightScale) > 0 ? 1 : 0);

        BufferedImage dest = new BufferedImage(width, height, src.getType());

        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                int rgb = src.getRGB(x * widthScale, y * heightScale);
                dest.setRGB(x, y, rgb);
            }
        }

        return dest;
    }
392555
public static Bitmap scale(ContentResolver contentResolver, Uri uri, int maxWidth, int maxHeight) {
        String tag = "SCALE";
        LogUtils.v(tag, "uri=" + uri.toString());
        try {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            InputStream input = contentResolver.openInputStream(uri);
            BitmapFactory.decodeStream(input, null, options);

            int sourceWidth = options.outWidth;
            int sourceHeight = options.outHeight;

            LogUtils.v(tag, "sourceWidth=" + sourceWidth + ", sourceHeight=" + sourceHeight);
            LogUtils.v(tag, "maxWidth=" + maxWidth + ", maxHeight=" + maxHeight);

            input.close();

            float rate = Math.max(sourceWidth / (float) maxWidth, sourceHeight / (float) maxHeight);
            options.inJustDecodeBounds = false;
            options.inSampleSize = (int) rate;
            LogUtils.v(tag, "rate=" + rate + ", inSampleSize=" + options.inSampleSize);

            input = contentResolver.openInputStream(uri);
            Bitmap bitmap = BitmapFactory.decodeStream(input, null, options);

            int w0 = bitmap.getWidth();
            int h0 = bitmap.getHeight();

            LogUtils.v(tag, "w0=" + w0 + ", h0=" + h0);


            float scaleWidth = maxWidth / (float) w0;
            float scaleHeight = maxHeight / (float) h0;
            float maxScale = Math.min(scaleWidth, scaleHeight);
            LogUtils.v(tag, "scaleWidth=" + scaleWidth + ", scaleHeight=" + scaleHeight);

            Matrix matrix = new Matrix();
            matrix.reset();
            if (maxScale < 1)
                matrix.postScale(maxScale, maxScale);

            Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, w0, h0, matrix, true);


            input.close();
            // bitmap.recycle();

            return resizedBitmap;

        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }

    }
527678
@Override
    public void setPixelSize(final int wide, final int high)
    {
        super.setPixelSize(wide, high);

        getViewport().setPixelSize(wide, high);

        getViewport().draw();
    }
660209
public void scaleAbsolute(float newWidth, float newHeight) {
		plainWidth = newWidth;
		plainHeight = newHeight;
		float[] matrix = matrix();
		scaledWidth = matrix[DX] - matrix[CX];
		scaledHeight = matrix[DY] - matrix[CY];
		setWidthPercentage(0);
	}
179843
def resize(self, w, h):
        
        self.plane_w = w
        self.plane_h = h
        self.plane_ratio = self.char_ratio * w / h

        if self.crosshairs:
            self.crosshairs_coord = ((w + 2) // 2, (h + 2) // 2)
1057999
function(maxW, maxH, curW, curH){
			var ratio	= curH / curW;
			if( curW >= maxW && ratio <= 1 ){ 
				curW	= maxW;
				curH	= maxW * ratio;
			}else if(curH >= maxH){
				curH	= maxH;
				curW	= maxH / ratio;
			}
			return { width: curW, height: curH };
		}
106270
public function resize_image($w, $h, $crop = false)
    {
        list($width, $height) = getimagesize($this->file);
        $r = $width / $height;
        if ($crop) {
            if ($width > $height) {
                $width = ceil($width - ($width * abs($r - $w / $h)));
            } else {
                $height = ceil($height - ($height * abs($r - $w / $h)));
            }
            $newwidth = $w;
            $newheight = $h;
        } else {
            if ($w / $h > $r) {
                $newwidth = $h * $r;
                $newheight = $h;
            } else {
                $newheight = $w / $r;
                $newwidth = $w;
            }
        }
        $dst = imagecreatetruecolor($newwidth, $newheight);
        imagecopyresampled($dst, $this->image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
        $this->image = $dst;
    }
482491
static function resizeIgnoringAspectRatio(\Intervention\Image\Image $img, $w, $h) {
        return $img->resize($w, $h);
    }
259750
void setPixelSize(final int wide, final int high)
    {
        m_wide = wide;

        m_high = high;

        if (LienzoCore.IS_CANVAS_SUPPORTED)
        {
            if (false == isSelection())
            {
                getElement().getStyle().setWidth(wide, Unit.PX);

                getElement().getStyle().setHeight(high, Unit.PX);
            }

            final CanvasElement element = getCanvasElement();

            element.setWidth(wide);

            element.setHeight(high);

            if (false == isSelection())
            {
                getContext().getNativeContext().initDeviceRatio();
            }

            if ((false == isSelection()) && (null != m_select))
            {
                m_select.setPixelSize(wide, high);
            }
        }
    }
41196
public BufferedImage getBufferedImage(int width, int height, int type) {
        int wDif,
                hDif,
                fWidth = 0,
                fHeight = 0;

        double imgWidth,
                imgHeight;

        double factor;
        imgWidth = image.getWidth();
        imgHeight = image.getHeight();


        switch (type) {
            case PROPORTIONAL:
                wDif = (int) imgWidth - width;
                hDif = (int) imgHeight - height;
                if (wDif > hDif) {
                    factor = width / imgWidth;
                } else {
                    factor = height / imgHeight;
                }
                fWidth = (int) Math.floor(imgWidth * factor);
                fHeight = (int) Math.floor(imgHeight * factor);
                break;
        }
        return getBufferedImage(fWidth, fHeight);
    }
400569
public void setBounds(float w, float h)
    {
        this.glyph.getBbox().setW(w);
        this.glyph.getBbox().setH(h);
    }
295277
private BufferedImage create_HI_INDICATOR_Image(final int WIDTH) {
        if (WIDTH <= 0) {
            return null;
        }

        // Define the size of the indicator
        int indicatorSize = (int) (0.015 * WIDTH);
        if (indicatorSize < 4) {
            indicatorSize = 4;
        }
        if (indicatorSize > 8) {
            indicatorSize = 8;
        }

        final BufferedImage IMAGE = UTIL.createImage(indicatorSize, indicatorSize, Transparency.TRANSLUCENT);
        final Graphics2D G2 = IMAGE.createGraphics();
        G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        G2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
        G2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
        G2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
        G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
        G2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

        final int IMAGE_WIDTH = IMAGE.getWidth();
        final int IMAGE_HEIGHT = IMAGE.getHeight();

        final GeneralPath THRESHOLD_TRIANGLE = new GeneralPath();
        THRESHOLD_TRIANGLE.setWindingRule(Path2D.WIND_EVEN_ODD);
        THRESHOLD_TRIANGLE.moveTo(IMAGE_WIDTH * 0.5, 0);
        THRESHOLD_TRIANGLE.lineTo(0, IMAGE_HEIGHT);
        THRESHOLD_TRIANGLE.lineTo(IMAGE_WIDTH, IMAGE_HEIGHT);
        THRESHOLD_TRIANGLE.lineTo(IMAGE_WIDTH * 0.5, 0);
        THRESHOLD_TRIANGLE.closePath();
        final Point2D THRESHOLD_TRIANGLE_START = new Point2D.Double(0, THRESHOLD_TRIANGLE.getBounds2D().getMinY());
        final Point2D THRESHOLD_TRIANGLE_STOP = new Point2D.Double(0, THRESHOLD_TRIANGLE.getBounds2D().getMaxY());
        final float[] THRESHOLD_TRIANGLE_FRACTIONS = {
            0.0f,
            0.3f,
            0.59f,
            1.0f
        };
        final Color[] THRESHOLD_TRIANGLE_COLORS = {
            new Color(82, 0, 0, 255),
            new Color(252, 29, 0, 255),
            new Color(252, 29, 0, 255),
            new Color(82, 0, 0, 255)
        };
        final LinearGradientPaint THRESHOLD_TRIANGLE_GRADIENT = new LinearGradientPaint(THRESHOLD_TRIANGLE_START, THRESHOLD_TRIANGLE_STOP, THRESHOLD_TRIANGLE_FRACTIONS, THRESHOLD_TRIANGLE_COLORS);
        G2.setPaint(THRESHOLD_TRIANGLE_GRADIENT);
        G2.fill(THRESHOLD_TRIANGLE);
        G2.setColor(Color.RED);
        G2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
        G2.draw(THRESHOLD_TRIANGLE);

        G2.dispose();

        return IMAGE;
    }
902506
function (redraw) {
            var imgDim = this._image.getDimensions();
            var vFactor = (this._container.clientHeight - this._margin * 2) / imgDim.h;
            var hFactor = (this._container.clientWidth - this._margin * 2) / imgDim.w;

            // Set correct zoom level
            if (vFactor < hFactor && vFactor < 1 && this._zoomLevel > vFactor) {
                // Fill vertical
                this._zoomLevel = vFactor;
                this.centerImage(false);
            }
            else if (hFactor < 1 && this._zoomLevel > hFactor) {
                // Fill horizontal
                this._zoomLevel = hFactor;
                this.centerImage(false);
            }
            else {
                // No need to redraw
                return;
            }

            if (redraw === true) {
                this.redraw();
            }
        }
85836
public BufferedImage getScaledImage()
    {
        RawScale3x scaler = new RawScale3x(srcData,width,height);
        
        BufferedImage image = new BufferedImage(width*3,height*3,BufferedImage.TYPE_INT_ARGB);
        image.setRGB(0,0,width*3,height*3,scaler.getScaledData(),0,width*3);
        
        return image;
    }
162740
protected function fillArea(&$w, &$h, $width, $height)
    {
        extract($this->getInfo());

        $ratio = $this->ratio($width, $height);

        $minW = min($w, $width);
        $minH = min($h, $height);
        $minB = min($w, $h);

        if ($minB === 0 or ($minW > $width and $minH > $height)) {
            return;
        }

        $ratioC = $this->ratio($w, $h);

        list($w, $h) = $ratio > $ratioC ? [(int)ceil($h * $ratio), $h] : [$w, (int)ceil($w / $ratio)];
    }
362097
public static BufferedImage getSubimage( BufferedImage image, int x, int y, int w, int h ) {
		BufferedImage newImage = new BufferedImage( w, h, BufferedImage.TYPE_INT_ARGB );
		Graphics2D g = newImage.createGraphics();
		g.drawRenderedImage( image, AffineTransform.getTranslateInstance(-x, -y) );
		g.dispose();
		return newImage;
	}