List of usage examples for android.graphics Matrix setValues
public void setValues(float[] values)
From source file:Main.java
public static Bitmap GetMirror(Bitmap bm) { if (bm == null) return null; float[] mirrorM = { -1, 0, 0, 0, 1, 0, 0, 0, 1 }; Matrix m = new Matrix(); m.setValues(mirrorM); return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), m, false); }
From source file:Main.java
/** * Returns an android.graphics.Matrix resulting from a 9-float matrix array in row-major order. * Undefined behavior when the array is not of size 9 or is null. * * @param m3 9-float matrix array in row-major order */// w ww . ja v a 2 s . c o m private static Matrix createMatrixFrom3x3(float[] m3) { Matrix m = new Matrix(); m.setValues(m3); return m; }
From source file:Main.java
public static Bitmap fixRotateMirrorImage(Bitmap src) { Matrix rotateRight = new Matrix(); float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1 }; Matrix matrixMirrorY = new Matrix(); matrixMirrorY.setValues(mirrorY); rotateRight.postConcat(matrixMirrorY); rotateRight.preRotate(270);//from ww w. ja v a 2s .co m final Bitmap rotMirrorImg = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), rotateRight, true); src.recycle(); return rotMirrorImg; }
From source file:Main.java
/** * @return matrix with correct configuration for the front camera. * Function to set correct height orientation and rotation for saving the image * in sd card./*from www . j a va 2s. c o m*/ */ public static Matrix setOrientationForFrontCamera() { Matrix matrix = new Matrix(); matrix.postRotate(-90); //for mirror images float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1 }; Matrix matrixMirrorY = new Matrix(); matrixMirrorY.setValues(mirrorY); matrix.postConcat(matrixMirrorY); return matrix; }
From source file:Main.java
public static Bitmap makeSquare(File file, int cameraID) { int width;/*from w w w . j a v a 2 s . co m*/ int height; Matrix matrix = new Matrix(); Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraID, info); // Convert ByteArray to Bitmap Bitmap bitPic = decodeSampledBitmapFromFile(destinationFile.getAbsolutePath(), 800, 800);//BitmapFactory.decodeByteArray(data, 0, data.length); width = bitPic.getWidth(); height = bitPic.getHeight(); // Perform matrix rotations/mirrors depending on camera that took the photo if (info.facing == 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(90); // Create new Bitmap out of the old one Bitmap bitPicFinal = Bitmap.createBitmap(bitPic, 0, 0, width, height, matrix, true); bitPic.recycle(); int desWidth; int desHeight; desWidth = bitPicFinal.getWidth(); desHeight = desWidth; Bitmap croppedBitmap = Bitmap.createBitmap(bitPicFinal, 0, bitPicFinal.getHeight() / 2 - bitPicFinal.getWidth() / 2, desWidth, desHeight); croppedBitmap = Bitmap.createScaledBitmap(croppedBitmap, 528, 528, true); return croppedBitmap; }
From source file:Main.java
/** * MSCALE_X MSKEW_X MTRANS_X/*from ww w . j a va 2s .c om*/ * MSKEW_Y MSCALE_Y MTRANS_Y * MPERSP_0 MPERSP_1 MPERSP_2 * * @param mat * @param m00 MSCALE_X * @param m01 MSKEW_X * @param m10 MSKEW_Y * @param m11 MSCALE_Y * @param m02 MTRANS_X * @param m12 MTRANS_Y */ public static void setMatValues(Matrix mat, float m00, float m01, float m10, float m11, float m02, float m12) { float[] fs = { m00, m10, m02, m01, m11, m12, 0, 0, 1 }; // float[] fs = {m00, m01, m02, m10, m11, m12, 0,0,1}; mat.setValues(fs); }
From source file:it.mb.whatshare.Utils.java
/** * Decodes a matrix encoded using {@link #matrixToJson(Matrix)} from JSON * format to a {@link Matrix} object./*from www.j a v a 2s . c o m*/ * * @param array * the encoded matrix * @return a matrix containing values from the JSON string (probably not * 100% equal to the original because of the * <tt>float --> double --> float</tt> conversion) or * <code>null</code> if <tt>array</tt> is <code>null</code> or * doesn't contain a matrix */ public static Matrix jsonToMatrix(JSONArray array) { if (array == null) return null; float[] values = new float[9]; Matrix matrix = new Matrix(); for (int i = 0; i < array.length(); i++) { try { values[i] = (float) array.getDouble(i); } catch (JSONException e) { e.printStackTrace(); return null; } } matrix.setValues(values); return matrix; }
From source file:com.jiahuan.svgmapview.core.helper.map.SVGParser.java
private static Matrix parseTransformItem(String s, Matrix matrix) { if (s.startsWith("matrix(")) { NumberParse np = parseNumbers(s.substring("matrix(".length())); if (np.numbers.size() == 6) { Matrix mat = new Matrix(); mat.setValues(new float[] { // Row 1 np.numbers.get(0), np.numbers.get(2), np.numbers.get(4), // Row 2 np.numbers.get(1), np.numbers.get(3), np.numbers.get(5), // Row 3 0, 0, 1, });//from w w w .j av a 2 s . c o m matrix.preConcat(mat); } } else if (s.startsWith("translate(")) { NumberParse np = parseNumbers(s.substring("translate(".length())); if (np.numbers.size() > 0) { float tx = np.numbers.get(0); float ty = 0; if (np.numbers.size() > 1) { ty = np.numbers.get(1); } matrix.preTranslate(tx, ty); } } else if (s.startsWith("scale(")) { NumberParse np = parseNumbers(s.substring("scale(".length())); if (np.numbers.size() > 0) { float sx = np.numbers.get(0); float sy = sx; if (np.numbers.size() > 1) { sy = np.numbers.get(1); } matrix.preScale(sx, sy); } } else if (s.startsWith("skewX(")) { NumberParse np = parseNumbers(s.substring("skewX(".length())); if (np.numbers.size() > 0) { float angle = np.numbers.get(0); matrix.preSkew((float) Math.tan(angle), 0); } } else if (s.startsWith("skewY(")) { NumberParse np = parseNumbers(s.substring("skewY(".length())); if (np.numbers.size() > 0) { float angle = np.numbers.get(0); matrix.preSkew(0, (float) Math.tan(angle)); } } else if (s.startsWith("rotate(")) { NumberParse np = parseNumbers(s.substring("rotate(".length())); if (np.numbers.size() > 0) { float angle = np.numbers.get(0); float cx = 0; float cy = 0; if (np.numbers.size() > 2) { cx = np.numbers.get(1); cy = np.numbers.get(2); } matrix.preTranslate(-cx, -cy); matrix.preRotate(angle); matrix.preTranslate(cx, cy); } } else { Log.w(TAG, "Invalid transform (" + s + ")"); } return matrix; }
From source file:com.larvalabs.svgandroid.SVGParser.java
private static Matrix parseTransformItem(String s, Matrix matrix) { if (s.startsWith("matrix(")) { NumberParse np = parseNumbers(s.substring("matrix(".length())); if (np.numbers.size() == 6) { Matrix mat = new Matrix(); mat.setValues(new float[] { // Row 1 np.numbers.get(0), np.numbers.get(2), np.numbers.get(4), // Row 2 np.numbers.get(1), np.numbers.get(3), np.numbers.get(5), // Row 3 0, 0, 1, });//ww w . j av a 2s .c o m matrix.preConcat(mat); } } else if (s.startsWith("translate(")) { NumberParse np = parseNumbers(s.substring("translate(".length())); if (np.numbers.size() > 0) { float tx = np.numbers.get(0); float ty = 0; if (np.numbers.size() > 1) { ty = np.numbers.get(1); } matrix.preTranslate(tx, ty); } } else if (s.startsWith("scale(")) { NumberParse np = parseNumbers(s.substring("scale(".length())); if (np.numbers.size() > 0) { float sx = np.numbers.get(0); float sy = sx; if (np.numbers.size() > 1) { sy = np.numbers.get(1); } matrix.preScale(sx, sy); } } else if (s.startsWith("skewX(")) { NumberParse np = parseNumbers(s.substring("skewX(".length())); if (np.numbers.size() > 0) { float angle = np.numbers.get(0); matrix.preSkew((float) Math.tan(angle), 0); } } else if (s.startsWith("skewY(")) { NumberParse np = parseNumbers(s.substring("skewY(".length())); if (np.numbers.size() > 0) { float angle = np.numbers.get(0); matrix.preSkew(0, (float) Math.tan(angle)); } } else if (s.startsWith("rotate(")) { NumberParse np = parseNumbers(s.substring("rotate(".length())); if (np.numbers.size() > 0) { float angle = np.numbers.get(0); float cx = 0; float cy = 0; if (np.numbers.size() > 2) { cx = np.numbers.get(1); cy = np.numbers.get(2); } matrix.preTranslate(cx, cy); matrix.preRotate(angle); matrix.preTranslate(-cx, -cy); } } else { Log.i(TAG, "Invalid transform (" + s + ")"); } return matrix; }
From source file:com.example.PagerCoverFlow.PagerContainer.java
private void transformImageBitmap(ImageView child, Matrix imageMatrix, int rotationAngle) { mCamera.save();//from w w w . j a v a 2 s.c om // final Matrix imageMatrix = t.getMatrix();; final int imageHeight = child.getLayoutParams().height; final int imageWidth = child.getLayoutParams().width; final int rotation = Math.abs(rotationAngle); // mCamera.translate(0.0f, 0.0f, 100.0f); Log.i("Select", "imageWidth:" + imageWidth + " " + "imageHeight:" + imageHeight); //As the angle of the view gets less, zoom in // if ( rotation < mMaxRotationAngle ) { float zoomAmount = (float) (mMaxZoom + (rotation * 1.5)); Log.i("Select", "rotation:" + rotation + " zoomAmount:" + zoomAmount); mCamera.translate(0.0f, 0.0f, zoomAmount); } //Alpha int alphaVal = 255 - rotation * 3; // child.setAlpha(alphaVal); //[0,255] child.getDrawable().setAlpha(alphaVal); // mCamera.rotateY(rotationAngle); mCamera.getMatrix(imageMatrix); imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2)); imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2)); mCamera.restore(); float[] values = new float[9]; imageMatrix.getValues(values); float globalX = values[Matrix.MTRANS_X]; float globalY = values[Matrix.MTRANS_Y]; // float width = values[Matrix.MSCALE_X]*CommonValue.menuWidth ; // float height = values[Matrix.MSCALE_Y]*CommonValue.menuWidth; values[Matrix.MSCALE_X] = 2; values[Matrix.MSCALE_Y] = 2; imageMatrix.setValues(values); }