Matrix postScale - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Matrix postScale method.

This code example shows how to use the following methods:mapRect, postScale, postTranslate, preTranslate, reset
 
        // use a rectangle at 0,0 to make sure we don't run into issues with scaling 
        r.set(0, 0, w, h);
 
        final Matrix m = mTempMatrix;
        m.reset();
        transformMatrix(m, view);
        mTempMatrix.mapRect(r);
 
        r.offset(view.getLeft(), view.getTop());
 
        // Straighten coords if rotations flipped them 
        if (r.right < r.left) {
            final float f = r.right;
            r.right = r.left;
            r.left = f;
        } 
        if (r.bottom < r.top) {
            final float f = r.top;
            r.top = r.bottom;

8
CodeRank
This code example shows how to use the following methods:createBitmap, postScale
			int bmpHeight = bitmap.getHeight();
 
			scaleWidth = (float) (scaleWidth * ZOOM_IN_SCALE);
			scaleHeight = (float) (scaleHeight * ZOOM_IN_SCALE);
 
			Matrix matrix = new Matrix();
			matrix.postScale(scaleWidth, scaleHeight);
			zoomedBMP = Bitmap.createBitmap(bitmap, 0, 0, bmpWidth, bmpHeight,
					matrix, true);
			imgView.setImageBitmap(zoomedBMP);
		} catch (Exception e) {
			// can't zoom because of memory issue, just ignore, no big deal 
		} 
	} 
} 
9
CodeRank
This code example shows how to use the following methods:createBitmap, postRotate, postScale
 
	public static Bitmap decode(final InputStream is, final BitmapFactory.Options opts) {
		if (is == null) return null;
		final int orientation = Exif.getOrientation(is);
		final Bitmap bm = BitmapFactory.decodeStream(is, null, opts);
		final Matrix m = new Matrix();
		switch (orientation) {
			case 270: 
			case 90: 
				m.postRotate(orientation);
				return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), m, true);
			case 180: 
				m.postRotate(orientation);
				m.postScale(bm.getWidth(), bm.getHeight());
				return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), m, true);
		} 
		return bm;
	} 
 
	public static Bitmap decode(final String path, final BitmapFactory.Options opts) {
8
CodeRank
This code example shows how to use the following methods:mapRect, postScale, postTranslate, reset
 
        // use a rectangle at 0,0 to make sure we don't run into issues with scaling 
        r.set(0, 0, w, h);
 
        final Matrix m = mTempMatrix;
        m.reset();
        transformMatrix(m, view);
        mTempMatrix.mapRect(r);
 
        r.offset(view.getLeft(), view.getTop());
 
        // Straighten coords if rotations flipped them 
        if (r.right < r.left) {
            final float f = r.right;
            r.right = r.left;
            r.left = f;
        } 
        if (r.bottom < r.top) {
            final float f = r.top;
            r.top = r.bottom;

8
CodeRank
This code example shows how to use the following methods:createBitmap, postRotate, postScale
			Bitmap output;
 
			if ( rotation == 0 ) {
				output = Bitmap.createScaledBitmap( input, dstWidth, dstHeight, true );
			} else { 
				Matrix matrix = new Matrix();
				matrix.postScale( (float) dstWidth / srcWidth, (float) dstHeight / srcHeight );
				matrix.postRotate( rotation );
				output = Bitmap.createBitmap( input, 0, 0, srcWidth, srcHeight, matrix, true );
			} 
			return output;
		} else 
			return input;
	} 
 
} 
8
CodeRank
This code example shows how to use the following methods:mapRect, postRotate, postScale, postTranslate, reset
     * @see android.widget.ImageView#setImageBitmap(android.graphics.Bitmap) 
     */ 
    @Override 
    public void setImageBitmap(Bitmap bitmap)
    { 
        Matrix matrix = new Matrix();
        matrix.reset();
        // apply the camera display characteristics. First mirror the image... 
        if (mbMirror)
        { 
            matrix.postScale(-1f, 1f);
        } 
        // then rotate it... 
        matrix.postRotate(mnDisplayOrientation);
        /** 
         * Math is hard!  
         *         -- Barbie 
         *  
         * We could calculate the matrix that will map the rotated and possibly 
         * mirrored image to the display, but it is much easier to compose a 

8
CodeRank
This code example shows how to use the following methods:createBitmap, postScale
		int height = bm.getHeight();
		float scaleWidth = ((float) newWidth) / width;
		float scaleHeight = ((float) newHeight) / height;
 
		// create a matrix for the manipulation 
		Matrix matrix = new Matrix();
		// resize the bit map 
		matrix.postScale(scaleWidth, scaleHeight);
 
		// recreate the new Bitmap 
		Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
		return resizedBitmap;
	} 
 
	protected Bitmap getAppIcon(JSONObject app) {
		Bitmap img = BitmapFactory.decodeResource(mact.getResources(), R.drawable.soup);
		try { 
			JSONObject icons = app.getJSONObject("icons");
			switch (icons.length()) {
			case 0: 
8
CodeRank
This code example shows how to use the following methods:postRotate, postScale, postTranslate, preTranslate
			if (bitmap != null) {
				float bitmapWidth = bitmap.getWidth();
				float bitmapHeight = bitmap.getHeight();
				float scale = 1.0f;
 
				Matrix matrix = new Matrix();
				if (width != bitmapWidth || height != bitmapHeight) {
					if (width == bitmapHeight || height == bitmapWidth) {
						if (width > height) {
							matrix.postRotate(-90, width / 2, height / 2);
						} else if (bitmapWidth != bitmapHeight) {
							matrix.postRotate(90, width / 2, height / 2);
						} else { 
							if (painter.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
								matrix.postRotate(-90, width / 2, height / 2);
							} 
						} 
					} else { 
						if (painter.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
							if (bitmapWidth > bitmapHeight

8
CodeRank
This code example shows how to use the following methods:postScale
            } 
 
            if (origWidth * saveScale <= viewWidth || origHeight * saveScale <= viewHeight)
                matrix.postScale(mScaleFactor, mScaleFactor, viewWidth / 2, viewHeight / 2);
            else 
                matrix.postScale(mScaleFactor, mScaleFactor, detector.getFocusX(), detector.getFocusY());
 
            fixTrans(); 
            return true; 
        } 
    } 
 
    void fixTrans() { 
        matrix.getValues(m);
        float transX = m[Matrix.MTRANS_X];
        float transY = m[Matrix.MTRANS_Y];
         
        float fixTransX = getFixTrans(transX, viewWidth, origWidth * saveScale);
        float fixTransY = getFixTrans(transY, viewHeight, origHeight * saveScale);
 
7
CodeRank
This code example shows how to use the following methods:postScale, postTranslate, setTranslate
        Bitmap.Config config = Bitmap.Config.ARGB_8888;
        Bitmap background = Bitmap.createBitmap(vwidth, vheight, config);
 
        Canvas canvas = new Canvas(background);
 
        Matrix matrix = new Matrix();
        matrix.setTranslate(-bwidth / 2, -bheight / 2);
        matrix.postScale(scale, scale);
        matrix.postTranslate(vwidth / 2, vheight / 2);
 
        canvas.drawBitmap(bitmap, matrix, null);
 
        view.setBackgroundDrawable(new BitmapDrawable(view.getResources(), background));
    } 
 
    /** 
     * @param view 
     * @param bitmap This is to avoid Bitmap's IllegalArgumentException 
     */ 
    public static void runnableBackground(final ImageView view, final Bitmap bitmap) {
7
CodeRank

Related Matrix postScale Questions & Answers:

postScale Method Overview
Postconcats the matrix with the specified scale.
See Code Examples for other Android Matrix Methods: