float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1}; Matrix matrix = new Matrix(); Matrix matrixMirrorY = new Matrix(); matrixMirrorY.setValues(mirrorY); matrix.postConcat(matrixMirrorY); image = Bitmap.createBitmap(mBitmap, 0, 0, frame.getWidth(), frame.getHeight(), matrix, true)
matrixMirrorY.setValues(mirrorY);
Matrix rotateRight = new Matrix(); rotateRight.preRotate(90); if(android.os.Build.VERSION.SDK_INT>13 && CameraActivity.frontCamera) { float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1}; rotateRight = new Matrix(); Matrix matrixMirrorY = new Matrix(); matrixMirrorY.setValues(mirrorY); rotateRight.postConcat(matrixMirrorY); rotateRight.preRotate(270); } final Bitmap rImg= Bitmap.createBitmap(img, 0, 0, img.getWidth(), img.getHeight(), rotateRight, true);
Matrix m = new Matrix(); m.setValues(new float[]{2,3,4,5,6,7,0,0,1});
Matrix m = new Matrix(); m.setValues(new float[] { q0, q2, q4, q1, q3, q5, 0, 0, 1 }
float containerToOutputRatioWidth = outputWidth / containerWidth; float containerToOutputRatioHeight = outputHeight / containerHeight; float[] values = new float[9]; transformedImageView.getMatrix().getValues(values); values[2] = values[2] * containerToOutputRatioWidth; values[5] = values[5] * containerToOutputRatioHeight; Matrix outputMatrix = new Matrix(); outputMatrix.setValues(values);
final Matrix m = new Matrix(); m.setValues(new float[] { -1, 0, 0, 0, 1, 0, 0, 0, 1}); final Bitmap normalBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.arrow); final Bitmap flippedBitmap = Bitmap.createBitmap(normalBitmap, 0, 0, normalBitmap.getWidth(), normalBitmap.getHeight(), m, true);
float[] values = getIntent().getFloatArrayExtra("matrix_values"); Matrix matrix = new Matrix(); matrix.setValues(values);
float rotate; // rotation in degrees float vcx; // center of rotation of view float vcy; float gcx; // center of rotation of graphic float gcy; float theta = (float) (Math.PI/180.0*rotate); float sin = (float) Math.sin(theta); float cos = (float) Math.cos(theta); float[] a = new float[9]; a[Matrix.MSCALE_X] = cos; a[Matrix.MSKEW_X] = sin; a[Matrix.MTRANS_X] = vcx-gcx*cos-gcy*sin; a[Matrix.MSCALE_Y] = cos; a[Matrix.MSKEW_Y] = -sin; a[Matrix.MTRANS_Y] = vcy-gcy*cos+gcx*sin; a[Matrix.MPERSP_0] = 0.0f; a[Matrix.MPERSP_1] = 0.0f; a[Matrix.MPERSP_2] = 1.0f; Matrix m = new Matrix(); m.setValues(a); view.setImageMatrix(m); // or setMatrix or whatever you're using.
public static Matrix createMatrixObj(AffineTransform Tx) { Matrix m = new Matrix(); m.reset(); m.setValues(createMatrix(Tx)); return m; }
public Bitmap rotateBitmap(Bitmap source, float angle) { Matrix matrix = new Matrix(); // Perform matrix rotations/mirrors depending on camera that took the photo if (cameraCurrentID == Camera.CameraInfo.CAMERA_FACING_FRONT) { float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1}; Matrix matrixMirrorY = new Matrix(); matrixMirrorY.setValues(mirrorY); matrix.postConcat(matrixMirrorY); } matrix.postRotate(angle); return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, false); }
float[] mirrorY = {-1, 0, 0, 0, 1, 0, 0, 0, 1}; Matrix matrixMirrorY = new Matrix(); matrixMirrorY.setValues(mirrorY); matrix.postConcat(matrixMirrorY); matrix.postRotate(90);
m.setValues(new float[] { 0, 0, 0, -1, 1, 0,
private Bitmap rotateBitmap(Bitmap bitmap){ Matrix rotateRight = new Matrix(); rotateRight.preRotate(90); if(android.os.Build.VERSION.SDK_INT > 13 && CameraActivity.frontCamera) { float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1}; rotateRight = new Matrix(); Matrix matrixMirrorY = new Matrix(); matrixMirrorY.setValues(mirrorY); rotateRight.postConcat(matrixMirrorY); rotateRight.preRotate(270); } final Bitmap rImg= Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), rotateRight, true); return rImg; }
Matrix matrixA = new Matrix(); matrixA.postTranslate(-bitmapWidth/2, -bitmapHeight/2); matrixA.postScale(screenWidth/320, screenWidth/320); Matrix matrixB = new Matrix(); matrixB.setValues(new float[]{scale, -rotate, tX, rotate, scale, tY, 0.0F, 0.0F, 1.0F}); matrixA.postConcat(matrixB); canvas.drawBitmap(bitmap, matrixA, null);
m.setValues(initial); float[] tmp = new float[9]; //Debug array of floats m.setRotate(90, 4.0f, 3.0f); //Rotating by 90 degrees around the (4, 3) point
Matrix rotateRight = new Matrix(); rotateRight.preRotate(90); if(android.os.Build.VERSION.SDK_INT>13 && CameraActivity.frontCamera) { float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1}; rotateRight = new Matrix(); Matrix matrixMirrorY = new Matrix(); matrixMirrorY.setValues(mirrorY); rotateRight.postConcat(matrixMirrorY); rotateRight.preRotate(270); } final Bitmap rImg= Bitmap.createBitmap(img, 0, 0, img.getWidth(), img.getHeight(), rotateRight, true);
float[] mirrorY = {-1, 0, 0, 0, 1, 0, 0, 0, 1}; Matrix matrixMirrorY = new Matrix(); matrixMirrorY.setValues(mirrorY); matrix.postConcat(matrixMirrorY);
static Matrix cvMat2Matrix(Mat source) { if (source == null || source.empty()) { return null; } float[] matrixValuesF = new float[source.cols()*source.rows()]; if (CvType.depth(source.type()) == CvType.CV_32F) { source.get(0,0, matrixValuesF); } else { double[] matrixValuesD = new double[matrixValuesF.length]; source.get(0, 0, matrixValuesD); //will throw an java.lang.UnsupportedOperationException if type is not CvType.CV_64F for (int i=0; i<matrixValuesD.length; i++) { matrixValuesF[i] = (float) matrixValuesD[i]; } } Matrix result = new Matrix(); result.setValues(matrixValuesF); return result; }
value[5] = -(scaleHeight-10); matrix.setValues(value); savedMatrix2.set(matrix);