List of usage examples for android.graphics Matrix reset
public void reset()
From source file:Main.java
public static Matrix get() { Matrix matrix = objects.get(); matrix.reset(); return matrix; }
From source file:Main.java
public static boolean setBitmapToDisplayMatrix(Matrix m, RectF imageBounds, RectF displayBounds) { m.reset(); return m.setRectToRect(imageBounds, displayBounds, Matrix.ScaleToFit.CENTER); }
From source file:Main.java
/** * Gets straighten matrix for the given bounds and degrees. *//*from w ww. j a v a 2s. c om*/ public static void getStraightenMatrix(RectF bounds, float degrees, Matrix matrix) { matrix.reset(); if ((degrees != 0) && !bounds.isEmpty()) { float w = bounds.width() / 2; float h = bounds.height() / 2; float adjustAngle; if ((degrees < 0 && w > h) || (degrees > 0 && w <= h)) { // The top left point is the boundary. adjustAngle = (float) Math.atan(h / -w) + MATH_PI + degrees * DEGREES_TO_RADIAN; } else { // The top right point is the boundary. adjustAngle = (float) Math.atan(h / w) - MATH_PI + degrees * DEGREES_TO_RADIAN; } float radius = (float) Math.hypot(w, h); float scaleX = (float) Math.abs(radius * Math.cos(adjustAngle)) / w; float scaleY = (float) Math.abs(radius * Math.sin(adjustAngle)) / h; float scale = Math.max(scaleX, scaleY); postRotateMatrix(degrees, new RectF(bounds), matrix); matrix.postScale(scale, scale); } }
From source file:Main.java
public static boolean saveMyBitmap(File f, Bitmap mBitmap) throws IOException { boolean saveComplete = true; try {/*from w w w . ja va2 s. c o m*/ f.createNewFile(); FileOutputStream fOut = null; fOut = new FileOutputStream(f); int width = mBitmap.getWidth(); int height = mBitmap.getHeight(); int finalWidth = 800; int finalHeight = (int) (finalWidth * 1.0 * (height * 1.0 / width * 1.0)); double x = width * finalHeight; double y = height * finalWidth; if (x > y) { finalHeight = (int) (y / (double) width); } else if (x < y) { finalWidth = (int) (x / (double) height); } if (finalWidth > width && finalHeight > height) { finalWidth = width; finalHeight = height; } Matrix matrix = new Matrix(); matrix.reset(); float scaleWidth = ((float) finalWidth) / (float) width; float scaleHeight = ((float) finalHeight) / (float) height; matrix.postScale(scaleWidth, scaleHeight); mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, (int) width, (int) height, matrix, true); mBitmap.compress(Bitmap.CompressFormat.JPEG, 80, fOut); fOut.flush(); fOut.close(); mBitmap.recycle(); System.gc(); } catch (FileNotFoundException e) { saveComplete = false; e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); saveComplete = false; } return saveComplete; }
From source file:Main.java
public static boolean storeImage(Context context, Bitmap bmp, boolean isRotate) { // use the current data&time for image file name String takenTime_YYMMDD_HHMMSS = new SimpleDateFormat(DATA_FORMAT).format(new Date()); // saved bitmap: full path String path = PIC_ROOT_PATH + takenTime_YYMMDD_HHMMSS; File f = new File(path); if (f != null && !f.getParentFile().exists()) { f.getParentFile().mkdirs();/*from w w w .ja v a 2 s. c o m*/ } if (isRotate) { Matrix matrix = new Matrix(); matrix.reset(); matrix.postRotate(90); bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true); } try { FileOutputStream out = new FileOutputStream(f); bmp.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } return updateGallery(context, bmp, takenTime_YYMMDD_HHMMSS); }
From source file:Main.java
public static void offsetDescendantRect(ViewGroup group, View child, Rect rect) { Matrix m = sMatrix.get(); if (m == null) { m = new Matrix(); sMatrix.set(m);//from w w w . j a va2 s . c o m } else { m.reset(); } offsetDescendantMatrix(group, child, m); RectF rectF = sRectF.get(); if (rectF == null) { rectF = new RectF(); sRectF.set(rectF); } rectF.set(rect); m.mapRect(rectF); rect.set((int) (rectF.left + 0.5f), (int) (rectF.top + 0.5f), (int) (rectF.right + 0.5f), (int) (rectF.bottom + 0.5f)); }
From source file:at.wada811.imageviewscaling.ImageViewFragment.java
public ParameterDelegate getParameterDelegate() { return new ParameterDelegate() { @Override/*from w w w.j a v a 2 s .c o m*/ public ScaleType getScaleType() { return mImageView.getScaleType(); } @Override public void setScaleType(ScaleType scaleType) { mImageView.setScaleType(scaleType); } @Override public int getLayoutParamsWidth() { return mImageView.getLayoutParams().width; } @Override public void setLayoutParamsWidth(int width) { LayoutParams params = mImageView.getLayoutParams(); params.width = width; mImageView.setLayoutParams(params); } @Override public int getLayoutParamsHeight() { return mImageView.getLayoutParams().height; } @Override public void setLayoutParamsHeight(int height) { LayoutParams params = mImageView.getLayoutParams(); params.height = height; mImageView.setLayoutParams(params); } @Override public boolean getAdjustViewBounds() { return mImageView.getAdjustViewBounds(); } @Override public void setAdjustViewBounds(boolean adjustViewBounds) { mImageView.setAdjustViewBounds(adjustViewBounds); } @Override public void setFitDisplayInside() { Bitmap bitmap = BitmapUtils.createBitmapFromDrawable(mImageView.getDrawable()); float factor = (float) DisplayUtils.getWidth(getActivity()) / bitmap.getWidth(); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( DisplayUtils.getWidth(getActivity()), (int) (bitmap.getHeight() * factor)); mImageView.setLayoutParams(params); Matrix matrix = mImageView.getImageMatrix(); matrix.reset(); matrix.postScale(factor, factor); mImageView.setImageMatrix(matrix); } }; }
From source file:com.actionbarsherlock.internal.nineoldandroids.view.animation.AnimatorProxy.java
private void computeRect(final RectF r, View view) { // compute current rectangle according to matrix transformation final float w = view.getWidth(); final float h = view.getHeight(); // use a rectangle at 0,0 to make sure we don't run into issues with scaling r.set(0, 0, w, h);/*from w ww .j a va 2 s . com*/ 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; r.bottom = f; } }
From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java
private Bitmap fillUpperLeft(final Drawable drawable, ImageView imageView, Bitmap prevBm) { // Compute matrix to fill viewer with drawable starting with upper left // Stretching till 2nd edge is crossed (filling screen) with correct aspect ratio. Matrix m = new Matrix(); m.reset(); int imgWidth = drawable.getIntrinsicWidth(); int imgHeight = drawable.getIntrinsicHeight(); int viewWidth = imageView.getWidth(); int viewHeight = imageView.getHeight(); float xScale = (float) viewWidth / imgWidth; float yScale = (float) viewHeight / imgHeight; float maxScale = Math.max(xScale, yScale); m.postScale(maxScale, maxScale);// w ww. j a v a2 s . c o m imageView.setScaleType(ImageView.ScaleType.MATRIX); imageView.setImageMatrix(m); imageView.setImageDrawable(drawable); return prevBm; }
From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java
private Bitmap fillLowerLeft(final Drawable drawable, ImageView imageView, Bitmap prevBm) { // Compute matrix to fill viewer with drawable starting with upper left // Stretching till 2nd edge is crossed (filling screen) with correct aspect ratio. Matrix m = new Matrix(); m.reset(); int imgWidth = drawable.getIntrinsicWidth(); int imgHeight = drawable.getIntrinsicHeight(); int viewWidth = imageView.getWidth(); int viewHeight = imageView.getHeight(); float xScale = (float) viewWidth / imgWidth; float yScale = (float) viewHeight / imgHeight; float maxScale = Math.max(xScale, yScale); float dy = (imgHeight * maxScale - viewHeight) / maxScale; // dy = imgHeight / 2; m.preTranslate(0, -dy);/*from w w w. j av a 2 s. co m*/ m.postScale(maxScale, maxScale); imageView.setScaleType(ImageView.ScaleType.MATRIX); imageView.setImageMatrix(m); imageView.setImageDrawable(drawable); return prevBm; }