List of usage examples for android.graphics Matrix Matrix
public Matrix()
From source file:cn.djangoogle.pull2load.internal.IndicatorLayout.java
public IndicatorLayout(Context context, Pull2LoadBase.Mode mode) { super(context); mArrowImageView = new ImageView(context); Drawable arrowD = ContextCompat.getDrawable(context, R.drawable.indicator_arrow); mArrowImageView.setImageDrawable(arrowD); final int padding = getResources().getDimensionPixelSize(R.dimen.indicator_internal_padding); mArrowImageView.setPadding(padding, padding, padding, padding); addView(mArrowImageView);/*from w w w. j av a 2 s .c o m*/ int inAnimResId, outAnimResId; switch (mode) { case PULL_FROM_END: inAnimResId = R.anim.slide_in_from_bottom; outAnimResId = R.anim.slide_out_to_bottom; setBackgroundResource(R.drawable.indicator_bg_bottom); // Rotate Arrow so it's pointing the correct way mArrowImageView.setScaleType(ScaleType.MATRIX); Matrix matrix = new Matrix(); matrix.setRotate(180f, arrowD.getIntrinsicWidth() / 2f, arrowD.getIntrinsicHeight() / 2f); mArrowImageView.setImageMatrix(matrix); break; default: case PULL_FROM_START: inAnimResId = R.anim.slide_in_from_top; outAnimResId = R.anim.slide_out_to_top; setBackgroundResource(R.drawable.indicator_bg_top); break; } mInAnim = AnimationUtils.loadAnimation(context, inAnimResId); mInAnim.setAnimationListener(this); mOutAnim = AnimationUtils.loadAnimation(context, outAnimResId); mOutAnim.setAnimationListener(this); final Interpolator interpolator = new LinearInterpolator(); mRotateAnimation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mRotateAnimation.setInterpolator(interpolator); mRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION); mRotateAnimation.setFillAfter(true); mResetRotateAnimation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mResetRotateAnimation.setInterpolator(interpolator); mResetRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION); mResetRotateAnimation.setFillAfter(true); }
From source file:com.artioml.practice.activities.LicenseActivity.java
public BitmapDrawable drawParallelogramLine(int width) { Matrix matrix = new Matrix(); Path path = new Path(); path.addRect(0, 0, (4 * width) / 40, (4 * width) / 200, Path.Direction.CW); Path pathStamp = new Path(); Paint p;/*ww w .j av a 2 s . c o m*/ Bitmap bitmap; p = new Paint(Paint.ANTI_ALIAS_FLAG); p.setStyle(Paint.Style.FILL); bitmap = Bitmap.createBitmap(width / 4, width / 80 * 2 + (4 * width) / 200, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); p.setColor(ContextCompat.getColor(this, R.color.colorPrimaryLight)); matrix.reset(); matrix.setTranslate(0, 0); matrix.postSkew(-1f, 0.0f, 0, (4 * width) / 200); path.transform(matrix, pathStamp); canvas.drawPath(pathStamp, p); p.setColor(ContextCompat.getColor(this, R.color.colorAccent)); matrix.reset(); matrix.setTranslate(width / 8, 0); matrix.postSkew(-1f, 0.0f, width / 8, (4 * width) / 200); path.transform(matrix, pathStamp); canvas.drawPath(pathStamp, p); BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap); bitmapDrawable.setTileModeX(Shader.TileMode.REPEAT); return bitmapDrawable; }
From source file:Main.java
private static Bitmap rotateBitmap(Bitmap bitmap, int rotate) { if (bitmap == null) return null; int w = bitmap.getWidth(); int h = bitmap.getHeight(); // Setting post rotate to 90 Matrix mtx = new Matrix(); mtx.postRotate(rotate);// www. j ava 2 s.co m return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); }
From source file:Main.java
public static Bitmap rotatingImageView(int degree, Bitmap source) { Matrix matrix = new Matrix(); matrix.postRotate((float) degree); return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true); }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VideoObj.java
public static DbObject from(Context context, Uri videoUri) throws IOException { // Query gallery for camera picture via // Android ContentResolver interface ContentResolver cr = context.getContentResolver(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 1;// w w w.j ava2s .c o m long videoId = Long.parseLong(videoUri.getLastPathSegment()); Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(cr, videoId, MediaStore.Video.Thumbnails.MINI_KIND, options); int targetSize = 200; int width = curThumb.getWidth(); int height = curThumb.getHeight(); int cropSize = Math.min(width, height); float scaleSize = ((float) targetSize) / cropSize; Matrix matrix = new Matrix(); matrix.postScale(scaleSize, scaleSize); curThumb = Bitmap.createBitmap(curThumb, 0, 0, width, height, matrix, true); JSONObject base = new JSONObject(); String localIp = ContentCorral.getLocalIpAddress(); if (localIp != null) { try { // TODO: Security breach hack? base.put(Contact.ATTR_LAN_IP, localIp); base.put(LOCAL_URI, videoUri.toString()); base.put(MIME_TYPE, cr.getType(videoUri)); } catch (JSONException e) { Log.e(TAG, "impossible json error possible!"); } } ByteArrayOutputStream baos = new ByteArrayOutputStream(); curThumb.compress(Bitmap.CompressFormat.JPEG, 90, baos); byte[] data = baos.toByteArray(); return from(base, data); }
From source file:Main.java
public static Bitmap rotateBitmap(Bitmap src, int degree) { Bitmap ret = null;//from w w w .ja v a 2s . c om Matrix matrix = new Matrix(); matrix.postRotate(degree); try { ret = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); } catch (OutOfMemoryError ignore) { } if (ret == null) { ret = src; } if (src != ret) { src.recycle(); } return ret; }
From source file:Main.java
private static Bitmap setProperOrientation(int orientation, Bitmap srcBitmap) { if (orientation > 0) { Matrix matrix = new Matrix(); matrix.postRotate(orientation);//from w w w . j a va 2s .c o m srcBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(), srcBitmap.getHeight(), matrix, true); } return srcBitmap; }
From source file:Main.java
/** * //from w w w.ja v a 2 s. c o m * @param filePath * @param targetWidth * @param targetHeight * @param recycle * @return */ public static Bitmap resizeAndCropCenter(Bitmap bitmap, int targetWidth, int targetHeight, boolean recycle) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); int scaleWidth = w / targetWidth; int scaleHeight = h / targetHeight; int scale = scaleWidth < scaleHeight ? scaleWidth : scaleHeight; if (scale < 1) { scale = 1; } //get scalebitmap float fScaleWidth = targetWidth / ((float) w); float fScaleHeight = targetHeight / ((float) h); float fScale = fScaleWidth > fScaleHeight ? fScaleWidth : fScaleHeight; if (fScale > 1) fScale = 1; Matrix matrix = new Matrix(); matrix.postScale(fScale, fScale); Bitmap scaleBitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true); //get targetBitmap int bitmapX = (scaleBitmap.getWidth() - targetWidth) / 2; bitmapX = bitmapX > 0 ? bitmapX : 0; int bitmapY = (scaleBitmap.getHeight() - targetHeight) / 2; bitmapY = bitmapY > 0 ? bitmapY : 0; targetWidth = targetWidth < (scaleBitmap.getWidth()) ? targetWidth : (scaleBitmap.getWidth()); targetHeight = targetHeight < (scaleBitmap.getHeight()) ? targetHeight : (scaleBitmap.getHeight()); Bitmap targetBitmap = Bitmap.createBitmap(scaleBitmap, bitmapX, bitmapY, targetWidth, targetHeight); if (recycle) bitmap.recycle(); return targetBitmap; }
From source file:Main.java
/** * // www . jav a 2s . c o m * @param filePath * @param targetWidth * @param targetHeight * @param recycle * @return */ public static Bitmap resizeAndCropCenter(Bitmap bitmap, int targetWidth, int targetHeight, boolean recycle) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); int scaleWidth = w / targetWidth; int scaleHeight = h / targetHeight; int scale = scaleWidth < scaleHeight ? scaleWidth : scaleHeight; if (scale < 1) { scale = 1; } //get scalebitmap float fScaleWidth = targetWidth / ((float) w); float fScaleHeight = targetHeight / ((float) h); float fScale = fScaleWidth > fScaleHeight ? fScaleWidth : fScaleHeight; if (fScale > 1) fScale = 1; Matrix matrix = new Matrix(); matrix.postScale(fScale, fScale); Bitmap scaleBitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true); //get targetBitmap int bitmapX = (scaleBitmap.getWidth() - targetWidth) / 2; bitmapX = bitmapX > 0 ? bitmapX : 0; int bitmapY = (scaleBitmap.getHeight() - targetHeight) / 2; bitmapY = bitmapY > 0 ? bitmapY : 0; targetWidth = targetWidth < (scaleBitmap.getWidth()) ? targetWidth : (scaleBitmap.getWidth()); targetHeight = targetHeight < (scaleBitmap.getHeight()) ? targetHeight : (scaleBitmap.getHeight()); Bitmap targetBitmap = Bitmap.createBitmap(scaleBitmap, bitmapX, bitmapY, targetWidth, targetHeight); // if (recycle) bitmap.recycle(); if (targetBitmap != bitmap && recycle) { bitmap.recycle(); } return targetBitmap; }
From source file:Main.java
/** * //from w w w. j a v a 2 s.c om * @param filePath * @param targetWidth * @param targetHeight * @param recycle * @return */ public static Bitmap resizeAndCropCenter(Bitmap bitmap, int targetWidth, int targetHeight, boolean recycle) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); int scaleWidth = w / targetWidth; int scaleHeight = h / targetHeight; int scale = scaleWidth < scaleHeight ? scaleWidth : scaleHeight; if (scale < 1) { scale = 1; } //get scalebitmap float fScaleWidth = targetWidth / ((float) w); float fScaleHeight = targetHeight / ((float) h); float fScale = fScaleWidth > fScaleHeight ? fScaleWidth : fScaleHeight; if (fScale > 1) fScale = 1; Matrix matrix = new Matrix(); matrix.postScale(fScale, fScale); Bitmap scaleBitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true); //get targetBitmap int bitmapX = (scaleBitmap.getWidth() - targetWidth) / 2; bitmapX = bitmapX > 0 ? bitmapX : 0; int bitmapY = (scaleBitmap.getHeight() - targetHeight) / 2; bitmapY = bitmapY > 0 ? bitmapY : 0; targetWidth = targetWidth < (scaleBitmap.getWidth()) ? targetWidth : (scaleBitmap.getWidth()); targetHeight = targetHeight < (scaleBitmap.getHeight()) ? targetHeight : (scaleBitmap.getHeight()); if (bitmapX == 0 && bitmapY == 0 && targetWidth == w && targetHeight == h) { return bitmap; } Bitmap targetBitmap = Bitmap.createBitmap(scaleBitmap, bitmapX, bitmapY, targetWidth, targetHeight); if (recycle) bitmap.recycle(); return targetBitmap; }