private RectF GetViewport() { RectF viewport = new RectF(); Matrix viewportMatrix = new Matrix(); translationMatrix.invert(viewportMatrix); viewportMatrix.mapRect(viewport, originalViewport); return viewport; }
Matrix matrix = new Matrix(); matrix.setRotate(mRotation,source.getWidth()/2,source.getHeight()/2); RectF rectF = new RectF(0, 0, source.getWidth(), source.getHeight()); matrix.mapRect(rectF); Bitmap targetBitmap = Bitmap.createBitmap(rectF.width(), rectF.height(), config); Canvas canvas = new Canvas(targetBitmap); canvas.drawBitmap(source, matrix, new Paint());
Bitmap bmpOriginal = BitmapFactory.decodeResource(this.getResources(), R.drawable.map_pin); Bitmap targetBitmap = Bitmap.createBitmap((bmpOriginal.getWidth()), (bmpOriginal.getHeight()), Bitmap.Config.ARGB_8888); Paint p = new Paint(); p.setAntiAlias(true); Matrix matrix = new Matrix(); matrix.setRotate((float) lock.getDirection(),(float) (bmpOriginal.getWidth()/2), (float)(bmpOriginal.getHeight()/2)); RectF rectF = new RectF(0, 0, bmpOriginal.getWidth(), bmpOriginal.getHeight()); matrix.mapRect(rectF); targetBitmap = Bitmap.createBitmap((int)rectF.width(), (int)rectF.height(), Bitmap.Config.ARGB_8888); Canvas tempCanvas = new Canvas(targetBitmap); tempCanvas.drawBitmap(bmpOriginal, matrix, p);
Bitmap bmp; //Get the scale factors for both vertical and horizontal since we're dealing with a square inside of a rectangle float scalefactorH = (float)mOriginalBitmap.getWidth() / (float)mBmpScaledForView.getWidth(); float scalefactorV = (float)mOriginalBitmap.getHeight() / (float)mBmpScaledForView.getHeight(); //Create a matrix and apply the scale factors Matrix m = new Matrix(); m.postScale(scalefactorH, scalefactorV); //Apply the matrix to a RectF RectF crop = new RectF(mCropBoxRect); m.mapRect(crop); //And finally hit the bitmap with this diddy bmp = Bitmap.createBitmap(this.mOriginalBitmap, (int)crop.left - mOffsetX, (int)crop.top - mOffsetY, (int)crop.width() - mOffsetX, (int)crop.height() - mOffsetY);
Bitmap bmpOriginal = BitmapFactory.decodeResource(this.getResources(), R.drawable.map_pin); Bitmap targetBitmap = Bitmap.createBitmap((bmpOriginal.getWidth()), (bmpOriginal.getHeight()), Bitmap.Config.ARGB_8888); Paint p = new Paint(); p.setAntiAlias(true); p.setDither(true); p.setFilterBitmap(true); Matrix matrix = new Matrix(); matrix.setRotate((float) lock.getDirection(),(float) (bmpOriginal.getWidth()/2), (float)(bmpOriginal.getHeight()/2)); RectF rectF = new RectF(0, 0, bmpOriginal.getWidth(), bmpOriginal.getHeight()); matrix.mapRect(rectF); targetBitmap = Bitmap.createBitmap((int)rectF.width(), (int)rectF.height(), Bitmap.Config.ARGB_8888); Canvas tempCanvas = new Canvas(targetBitmap); tempCanvas.drawBitmap(bmpOriginal, matrix, p);
// Here previewRect is a rectangle which holds the camera's preview size, // pictureRect and nativeResRect hold the camera's picture size and its // native resolution, respectively. RectF previewRect = new RectF(0, 0, 480, 800), pictureRect = new RectF(0, 0, 1080, 1920), nativeResRect = new RectF(0, 0, 1952, 2592), resultRect = new RectF(0, 0, 480, 800); final Matrix scaleMatrix = new Matrix(); // create a matrix which scales coordinates of preview size rectangle into the // camera's native resolution. scaleMatrix.setRectToRect(previewRect, nativeResRect, Matrix.ScaleToFit.CENTER); // map the result rectangle to the new coordinates scaleMatrix.mapRect(resultRect); // create a matrix which scales coordinates of picture size rectangle into the // camera's native resolution. scaleMatrix.setRectToRect(pictureRect, nativeResRect, Matrix.ScaleToFit.CENTER); // invert it, so that we get the matrix which downscales the rectangle from // the native resolution to the actual picture size scaleMatrix.invert(scaleMatrix); // and map the result rectangle to the coordinates in the picture size rectangle scaleMatrix.mapRect(resultRect);
Matrix m = new Matrix(); // point is the point about which to rotate. m.setRotate(degrees, point.x, point.y); m.mapRect(r);
private void resetPreviewSize() { final boolean widthIsMax = mWidth > mHeight; final Camera.Size size = mCamera.getNativeCamera().getParameters().getPreviewSize(); final RectF rectDisplay = new RectF(); final RectF rectPreview = new RectF(); rectDisplay.set(0, 0, mWidth, mHeight); final int width = widthIsMax ? size.width : size.height; final int height = widthIsMax ? size.height : size.width; rectPreview.set(0, 0, width, height); final Matrix matrix = new Matrix(); matrix.setRectToRect(rectDisplay, rectPreview, Matrix.ScaleToFit.START); matrix.invert(matrix); matrix.mapRect(rectPreview); mCameraView.getLayoutParams().height = (int) (rectPreview.bottom); mCameraView.getLayoutParams().width = (int) (rectPreview.right); mCameraView.requestLayout(); }
private void setupMatrix(int width, int height, int degrees, boolean isHorizontal) { Log.d(TAG, "setupMatrix for " + degrees + " degrees"); Matrix matrix = new Matrix(); //The video will be streched if the aspect ratio is in 1,5(recording at 480) RectF src; if (isHorizontal) //In my case, I changed this line, cause with my onMeasure() and onLayout() methods my container view is already rotated and scaled, so I need to sent the inverted params to the src. src = new RectF(0, 0,mThumbnailContainer.getmWidth(), mThumbnailContainer.getmHeight()); else src = new RectF(0, 0, mThumbnailContainer.getmWidth(),mThumbnailContainer.getmHeight()); RectF dst = new RectF(0, 0, width, height); RectF screen = new RectF(dst); Log.d(TAG, "Matrix: " + width + "x" + height); Log.d(TAG, "Matrix: " + mThumbnailContainer.getmWidth() + "x" + mThumbnailContainer.getmHeight()); matrix.postRotate(degrees, screen.centerX(), screen.centerY()); matrix.mapRect(dst); matrix.setRectToRect(src, dst, Matrix.ScaleToFit.CENTER); matrix.mapRect(src); matrix.setRectToRect(screen, src, Matrix.ScaleToFit.FILL); matrix.postRotate(degrees, screen.centerX(), screen.centerY()); mVideoView.setTransform(matrix); }
Matrix matrix = new Matrix(); matrix.setRotate(180, (rect.right - rect.left) / 2, (tallestRect.top - tallestRect.bottom) / 2); matrix.mapRect(rect);
Matrix m = new Matrix(); //creates identity matrix m.setRotate(tilt_angle); //rotate it by the tilt angle m.mapRect(ovalBounds); //transform the rect
Bitmap bitmap = yourBitmap; Matrix matrix = new Matrix(); matrix.postRotate(angle); Rect srcR = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); RectF dstR = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight()); RectF deviceR = new RectF(); matrix.mapRect(deviceR, dstR); int neww = Math.round(deviceR.width()); int newh = Math.round(deviceR.height()); Bitmap result = Bitmap.createBitmap(neww, newh, Bitmap.Config.ARGB_8888); result.eraseColor(Color.TRANSPARENT); Canvas canvas = new Canvas(); canvas.translate(-deviceR.left, -deviceR.top); canvas.concat(matrix); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); canvas.setBitmap(result); canvas.drawBitmap(bitmap, srcR, dstR, paint); canvas.setBitmap(null);
btn_matrix.mapRect(btn_rect);
shader.setLocalMatrix(m); mPaint.setShader(shader); m.mapRect(mOval, src);
shader.setLocalMatrix(m); mPaint.setShader(shader); m.mapRect(mOval, src);
shader.setLocalMatrix(matrix); mPaint.setShader(shader); matrix.mapRect(mOval, src);
RectF rectF = new RectF(face.rect); Matrix matrix = new Matrix(); matrix.setScale(1, 1); matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f); matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f); matrix.mapRect(rectF);
shader.setLocalMatrix(matrix); maskPaint.setShader(shader); matrix.mapRect(src); radius = src.width() / 2f;
layoutRectF.set(0, 0, r - l, b - t); layoutTransitionMatrix.setRotate(angle, layoutRectF.centerX(), layoutRectF.centerY()); layoutTransitionMatrix.mapRect(layoutRectFRotated, layoutRectF); layoutRectFRotated.round(viewRectRotated); angleChanged = false;
rotateMatrix.setRotate(angle, layoutRect.centerX(), layoutRect.centerY()); rotateMatrix.postScale(-1, 1); rotateMatrix.mapRect(layoutRectRotated, layoutRect); layoutRectRotated.round(viewRectRotated); angleChanged = false;