@Override public boolean setDisplayMatrix(Matrix finalMatrix) { if (finalMatrix == null) throw new IllegalArgumentException("Matrix cannot be null"); ImageView imageView = getImageView(); if (null == imageView) return false; if (null == imageView.getDrawable()) return false; mSuppMatrix.set(finalMatrix); setImageViewMatrix(getDrawMatrix()); checkMatrixBounds(); return true; }
public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) { super(context, mode, scrollDirection, attrs); mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true); mHeaderImage.setScaleType(ScaleType.MATRIX); mHeaderImageMatrix = new Matrix(); mHeaderImage.setImageMatrix(mHeaderImageMatrix); mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR); mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION); mRotateAnimation.setRepeatCount(Animation.INFINITE); mRotateAnimation.setRepeatMode(Animation.RESTART); }
public void onPreviewSizeChosen(final Size size, final int rotation) { previewWidth = size.getWidth(); previewHeight = size.getHeight(); final Display display = getWindowManager().getDefaultDisplay(); final int screenOrientation = display.getRotation(); LOGGER.i("Sensor orientation: %d, Screen orientation: %d", rotation, screenOrientation); sensorOrientation = rotation + screenOrientation; LOGGER.i("Initializing at size %dx%d", previewWidth, previewHeight); rgbBytes = new int[previewWidth * previewHeight]; rgbFrameBitmap = Bitmap.createBitmap(previewWidth, previewHeight, Bitmap.Config.ARGB_8888); croppedBitmap = Bitmap.createBitmap(INPUT_SIZE, INPUT_SIZE, Bitmap.Config.ARGB_8888); frameToCropTransform = ImageUtils.getTransformationMatrix(previewWidth, previewHeight, INPUT_SIZE, INPUT_SIZE, sensorOrientation, MAINTAIN_ASPECT); Matrix cropToFrameTransform = new Matrix(); frameToCropTransform.invert(cropToFrameTransform); yuvBytes = new byte[3][]; }
/** * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`. * This method should be called after the camera preview size is determined in * setUpCameraOutputs and also the size of `mTextureView` is fixed. * * @param viewWidth The width of `mTextureView` * @param viewHeight The height of `mTextureView` */ private void configureTransform(final int viewWidth, final int viewHeight) { final Activity activity = getActivity(); if (null == textureView || null == previewSize || null == activity) { return; } final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); final Matrix matrix = new Matrix(); final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth()); final float centerX = viewRect.centerX(); final float centerY = viewRect.centerY(); if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); final float scale = Math.max( (float) viewHeight / previewSize.getHeight(), (float) viewWidth / previewSize.getWidth()); matrix.postScale(scale, scale, centerX, centerY); matrix.postRotate(90 * (rotation - 2), centerX, centerY); } else if (Surface.ROTATION_180 == rotation) { matrix.postRotate(180, centerX, centerY); } textureView.setTransform(matrix); }
@Override public void drawIcon(Canvas canvas, float fraction, Drawable drawable, int colorOfIcon, WidthAndHeightOfView widthAndHeightOfView) { int centerX = widthAndHeightOfView.getWidth() / 2; int centerY = widthAndHeightOfView.getHeight() / 2 - 150; canvas.save(); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); float newFraction = (fraction - 0.65f) / 0.35f; paint.setColor(Color.parseColor("#e53935")); canvas.drawCircle(centerX, centerY - 50, 100 * (1 - newFraction), paint); paint.setColor(Color.parseColor("#fdd835")); canvas.drawCircle(centerX -35, centerY + 35,100 * (1 - newFraction), paint); paint.setColor(Color.parseColor("#1e88e5")); canvas.drawCircle(centerX + 35, centerY + 35, 100 * (1 - newFraction), paint); canvas.restore(); canvas.save(); Path path = new Path(); Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); Matrix matrix = new Matrix(); matrix.postScale(1.7f, 1.7f, centerX, centerY); canvas.concat(matrix); path.addCircle(centerX, centerY, bitmap.getHeight() * 1.5f * newFraction, Path.Direction.CW); canvas.clipPath(path); canvas.drawBitmap(bitmap, centerX - bitmap.getWidth() / 2, centerY - bitmap.getHeight() / 2, paint); canvas.restore(); }
@Override protected void applyTransformation(float interpolatedTime, Transformation t) { final float fromDegrees = mFromDegrees; float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime); final Matrix matrix = t.getMatrix(); mCamera.save(); switch (mRollType) { case ROLL_BY_X: mCamera.rotateX(degrees); break; case ROLL_BY_Y: mCamera.rotateY(degrees); break; case ROLL_BY_Z: mCamera.rotateZ(degrees); break; } mCamera.getMatrix(matrix); mCamera.restore(); matrix.preTranslate(-mPivotX, -mPivotY); matrix.postTranslate(mPivotX, mPivotY); }
protected void zoomOut(float rate) { if (bitmapDisplayed.getBitmap() == null) { return; } float cx = getWidth() / 2F; float cy = getHeight() / 2F; // Zoom out to at most 1x Matrix tmp = new Matrix(suppMatrix); tmp.postScale(1F / rate, 1F / rate, cx, cy); if (getScale(tmp) < 1F) { suppMatrix.setScale(1F, 1F, cx, cy); } else { suppMatrix.postScale(1F / rate, 1F / rate, cx, cy); } setImageMatrix(getImageViewMatrix()); center(); }
/** * Limits the translation so that there are no empty spaces on the sides if possible. * * <p> The image is attempted to be centered within the view bounds if the transformed image is * smaller. There will be no empty spaces within the view bounds if the transformed image is * bigger. This applies to each dimension (horizontal and vertical) independently. * * @param limitTypes whether to limit translation along the specific axis. * @return whether limiting has been applied or not */ private boolean limitTranslation(Matrix transform, @LimitFlag int limitTypes) { if (!shouldLimit(limitTypes, LIMIT_TRANSLATION_X | LIMIT_TRANSLATION_Y)) { return false; } RectF b = mTempRect; b.set(mImageBounds); transform.mapRect(b); float offsetLeft = shouldLimit(limitTypes, LIMIT_TRANSLATION_X) ? getOffset(b.left, b.right, mViewBounds.left, mViewBounds.right, mImageBounds.centerX()) : 0; float offsetTop = shouldLimit(limitTypes, LIMIT_TRANSLATION_Y) ? getOffset(b.top, b.bottom, mViewBounds.top, mViewBounds.bottom, mImageBounds.centerY()) : 0; if (offsetLeft != 0 || offsetTop != 0) { transform.postTranslate(offsetLeft, offsetTop); return true; } return false; }
/** * Draws a VideoFrame.TextureBuffer. Calls either drawer.drawOes or drawer.drawRgb * depending on the type of the buffer. You can supply an additional render matrix. This is * used multiplied together with the transformation matrix of the frame. (M = renderMatrix * * transformationMatrix) */ static void drawTexture(RendererCommon.GlDrawer drawer, VideoFrame.TextureBuffer buffer, Matrix renderMatrix, int frameWidth, int frameHeight, int viewportX, int viewportY, int viewportWidth, int viewportHeight) { Matrix finalMatrix = new Matrix(buffer.getTransformMatrix()); finalMatrix.preConcat(renderMatrix); float[] finalGlMatrix = RendererCommon.convertMatrixFromAndroidGraphicsMatrix(finalMatrix); switch (buffer.getType()) { case OES: drawer.drawOes(buffer.getTextureId(), finalGlMatrix, frameWidth, frameHeight, viewportX, viewportY, viewportWidth, viewportHeight); break; case RGB: drawer.drawRgb(buffer.getTextureId(), finalGlMatrix, frameWidth, frameHeight, viewportX, viewportY, viewportWidth, viewportHeight); break; default: throw new RuntimeException("Unknown texture type."); } }
/** * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`. * This method should be called after the camera preview size is determined in * setUpCameraOutputs and also the size of `mTextureView` is fixed. * * @param viewWidth The width of `mTextureView` * @param viewHeight The height of `mTextureView` */ private void configureTransform(int viewWidth, int viewHeight) { Activity activity = getActivity(); if (null == mTextureView || null == mPreviewSize || null == activity) { return; } int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); Matrix matrix = new Matrix(); RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth()); float centerX = viewRect.centerX(); float centerY = viewRect.centerY(); if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); float scale = Math.max( (float) viewHeight / mPreviewSize.getHeight(), (float) viewWidth / mPreviewSize.getWidth()); matrix.postScale(scale, scale, centerX, centerY); matrix.postRotate(90 * (rotation - 2), centerX, centerY); } else if (Surface.ROTATION_180 == rotation) { matrix.postRotate(180, centerX, centerY); } mTextureView.setTransform(matrix); }
public static Bitmap scaleImage(Bitmap bitmap, int boxSize){ if (boxSize == 0) return null; // Determine how much to scale: the dimension requiring less scaling is // closer to the its side. This way the image always stays inside your // bounding box AND either x/y axis touches it. float xScale = ((float) boxSize) / bitmap.getWidth(); float yScale = ((float) boxSize) / bitmap.getHeight(); float scale = (xScale <= yScale) ? xScale : yScale; // Create a matrix for the scaling and add the scaling data Matrix matrix = new Matrix(); matrix.postScale(scale, scale); // Create a new bitmap and convert it to a format understood by the ImageView return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); }
/** * Rotate the given bitmap by the given degrees.<br> * New bitmap is created and the old one is recycled. */ private static Bitmap rotateAndFlipBitmapInt( Bitmap bitmap, int degrees, boolean flipHorizontally, boolean flipVertically) { if (degrees > 0 || flipHorizontally || flipVertically) { Matrix matrix = new Matrix(); matrix.setRotate(degrees); matrix.postScale(flipHorizontally ? -1 : 1, flipVertically ? -1 : 1); Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); if (newBitmap != bitmap) { bitmap.recycle(); } return newBitmap; } else { return bitmap; } }
/** * Configures the necessary {@link Matrix} transformation to `mTextureView`. * This method should not to be called until the camera preview size is determined in * openCamera, or until the size of `mTextureView` is fixed. * * @param viewWidth The width of `mTextureView` * @param viewHeight The height of `mTextureView` */ private void configureTransform(int viewWidth, int viewHeight) { Activity activity = getActivity(); if (null == mTextureView || null == mPreviewSize || null == activity) { return; } int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); Matrix matrix = new Matrix(); RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth()); float centerX = viewRect.centerX(); float centerY = viewRect.centerY(); if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); float scale = Math.max( (float) viewHeight / mPreviewSize.getHeight(), (float) viewWidth / mPreviewSize.getWidth()); matrix.postScale(scale, scale, centerX, centerY); matrix.postRotate(90 * (rotation - 2), centerX, centerY); } mTextureView.setTransform(matrix); }
/** * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`. * This method should be called after the camera preview size is determined in * setUpCameraOutputs and also the size of `mTextureView` is fixed. * * @param viewWidth The width of `mTextureView` * @param viewHeight The height of `mTextureView` */ private void configureTransform(final int viewWidth, final int viewHeight) { if (mPreviewSize == null) return; final int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation(); final Matrix matrix = new Matrix(); final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); final RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth()); final float centerX = viewRect.centerX(); final float centerY = viewRect.centerY(); if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); final float scale = Math.max((float) viewHeight / mPreviewSize.getHeight(), (float) viewWidth / mPreviewSize.getWidth()); matrix.postScale(scale, scale, centerX, centerY); matrix.postRotate(90 * (rotation - 2), centerX, centerY); } else if (Surface.ROTATION_180 == rotation) { matrix.postRotate(180, centerX, centerY); } mAutoFitTextureView.setTransform(matrix); }
/** * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`. * This method should be called after the camera preview size is determined in * setUpCameraOutputs and also the size of `mTextureView` is fixed. * * @param viewWidth The width of `mTextureView` * @param viewHeight The height of `mTextureView` */ private void configureTransform(int viewWidth, int viewHeight) { if (isViewAvailable()) { if (null == activityView.getTextureView()) { return; } int rotation = activityView.getWindowManager().getDefaultDisplay().getRotation(); Matrix matrix = new Matrix(); RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth()); float centerX = viewRect.centerX(); float centerY = viewRect.centerY(); if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); float scale = Math.max( (float) viewHeight / previewSize.getHeight(), (float) viewWidth / previewSize.getWidth()); matrix.postScale(scale, scale, centerX, centerY); matrix.postRotate(90 * (rotation - 2), centerX, centerY); } else if (Surface.ROTATION_180 == rotation) { matrix.postRotate(180, centerX, centerY); } activityView.getTextureView().setTransform(matrix); } }
private void popLayer(SvgElement obj) { // If this is masked content, apply the mask now if (state.style.mask != null && state.directRendering) { // The masked content has been drawn, now we have to render the mask // to a separate canvas SVG.SvgObject ref = document.resolveIRI(state.style.mask); duplicateCanvas(); renderMask((SVG.Mask) ref, obj); Bitmap maskedContent = processMaskBitmaps(); // Retrieve the real canvas canvas = canvasStack.pop(); canvas.save(); // Reset the canvas matrix so that we can draw the maskedContent // exactly over the top of the root bitmap canvas.setMatrix(new Matrix()); canvas.drawBitmap(maskedContent, 0, 0, state.fillPaint); maskedContent.recycle(); canvas.restore(); } statePop(); }
static void offsetDescendantMatrix(ViewParent target, View view, Matrix m) { final ViewParent parent = view.getParent(); if (parent instanceof View && parent != target) { final View vp = (View) parent; offsetDescendantMatrix(target, vp, m); m.preTranslate(-vp.getScrollX(), -vp.getScrollY()); } m.preTranslate(view.getLeft(), view.getTop()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { if (!view.getMatrix().isIdentity()) { m.preConcat(view.getMatrix()); } } }
/** * Creates a centered bitmap of the desired size. * @param source * @param recycle whether we want to recycle the input */ public static Bitmap extractMiniThumb( Bitmap source, int width, int height, boolean recycle) { if (source == null) { return null; } float scale; if (source.getWidth() < source.getHeight()) { scale = width / (float) source.getWidth(); } else { scale = height / (float) source.getHeight(); } Matrix matrix = new Matrix(); matrix.setScale(scale, scale); Bitmap miniThumbnail = transform(matrix, source, width, height, true, recycle); return miniThumbnail; }
/** * 执行当前outerMatrix到指定outerMatrix渐变的动画 * * 调用此方法会停止正在进行中的手势以及手势动画. * 当duration为0时,outerMatrix值会被立即设置而不会启动动画. * * @param endMatrix 动画目标矩阵 * @param duration 动画持续时间 * * @see #getOuterMatrix(Matrix) */ public void outerMatrixTo(Matrix endMatrix, long duration) { if (endMatrix == null) { return; } //将手势设置为PINCH_MODE_FREE将停止后续手势的触发 mPinchMode = PINCH_MODE_FREE; //停止所有正在进行的动画 cancelAllAnimator(); //如果时间不合法立即执行结果 if (duration <= 0) { mOuterMatrix.set(endMatrix); dispatchOuterMatrixChanged(); invalidate(); } else { //创建矩阵变化动画 mScaleAnimator = new ScaleAnimator(mOuterMatrix, endMatrix, duration); mScaleAnimator.start(); } }
public void run() { Bitmap bitmap; try { bitmap = captureView(view); } catch (Exception e) { return; } if (yflip) { Matrix matrix = new Matrix(); matrix.postScale(1, -1); boolean hasAlpha = bitmap.hasAlpha(); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); bitmap.setHasAlpha(hasAlpha); } int[] textures = new int[1]; glGenTextures(1, textures, 0); glBindTexture(GL_TEXTURE_2D, textures[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0); this.attachTexture(textures[0]); }
private static Bitmap matrixCompress(Bitmap bitmap, int baseline, boolean recycle) { if (bitmap == null) return null; int bitmapWidth = bitmap.getWidth(); int bitmapHeight = bitmap.getHeight(); int maxValue = Math.max(bitmapWidth, bitmapHeight); if (maxValue > baseline) { Matrix matrix = new Matrix(); float rate = (float) baseline / (float) maxValue; matrix.postScale(rate, rate); Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, bitmapWidth, bitmapHeight, matrix, true); if (recycle) { bitmap.recycle(); bitmap = null; } return result; } else { return bitmap; } }
private Bitmap rotatingImage(Bitmap bitmap) { if (srcExif == null) return bitmap; Matrix matrix = new Matrix(); int angle = 0; int orientation = srcExif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: angle = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: angle = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: angle = 270; break; } matrix.postRotate(angle); return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); }
/** * 对图片按照一些手势信息进行缩放 * * @param scaleCenter mScaleCenter * @param scaleBase mScaleBase * @param distance 手指两点之间距离 * @param lineCenter 手指两点之间中点 * * @see #mScaleCenter * @see #mScaleBase */ private void scaleAndRotate(PointF scaleCenter, float scaleBase, float distance, PointF lineCenter,float degree) { if (!isReady()) { return; } //计算图片从fit center状态到目标状态的缩放比例 float scale = scaleBase * distance; Matrix matrix = MathUtils.matrixTake(); //按照图片缩放中心缩放,并且让缩放中心在缩放点中点上 matrix.postScale(scale, scale, scaleCenter.x, scaleCenter.y); //按照图片缩放中心旋转,并且让缩放中心在缩放点中点上 matrix.postRotate(degree,scaleCenter.x,scaleCenter.y); //让图片的缩放中点跟随手指缩放中点 matrix.postTranslate(lineCenter.x - scaleCenter.x, lineCenter.y - scaleCenter.y); //应用变换 mOuterMatrix.set(matrix); MathUtils.matrixGiven(matrix); dispatchOuterMatrixChanged(); //重绘 invalidate(); }
private void initView(Context context, AttributeSet attrs) { mMatrix = new Matrix(); DensityUtil density = new DensityUtil(); mSunSize = density.dip2px(40); setupAnimation(); setupPathsDrawable(); setMinimumHeight(density.dip2px(100)); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PhoenixHeader); int primaryColor = ta.getColor(R.styleable.PhoenixHeader_phPrimaryColor, 0); int accentColor = ta.getColor(R.styleable.PhoenixHeader_phAccentColor, 0); if (primaryColor != 0) { setBackgroundColor(primaryColor); if (accentColor != 0) { mDrawableSky.parserColors(primaryColor, accentColor); } else { mDrawableSky.parserColors(primaryColor); } } ta.recycle(); }
private void configureTransform(TextureView textureView) { if (null == textureView || null == mPreviewSize || null == mActivity) { return; } int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation(); Matrix matrix = new Matrix(); RectF viewRect = new RectF(0, 0, textureView.getWidth(), textureView.getHeight()); RectF bufferRect = new RectF(0, 0, mPreviewSize.y, mPreviewSize.x); float centerX = viewRect.centerX(); float centerY = viewRect.centerY(); if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); float scale = Math.max( (float) textureView.getHeight() / mPreviewSize.y, (float) textureView.getWidth() / mPreviewSize.x); matrix.postScale(scale, scale, centerX, centerY); } matrix.postRotate(-90 * rotation, centerX, centerY); textureView.setTransform(matrix); }
public PageWidget(Context context, String bookId, List<BookMixAToc.mixToc.Chapters> chaptersList, OnReadStateChangeListener listener) { super(context, bookId, chaptersList, listener); mPath0 = new Path(); mPath1 = new Path(); mMaxLength = (float) Math.hypot(mScreenWidth, mScreenHeight); mPaint = new Paint(); mPaint.setStyle(Paint.Style.FILL); createDrawable(); ColorMatrix cm = new ColorMatrix();//设置颜色数组 float array[] = {0.55f, 0, 0, 0, 80.0f, 0, 0.55f, 0, 0, 80.0f, 0, 0, 0.55f, 0, 80.0f, 0, 0, 0, 0.2f, 0}; cm.set(array); mColorMatrixFilter = new ColorMatrixColorFilter(cm); mMatrix = new Matrix(); mTouch.x = 0.01f; // 不让x,y为0,否则在点计算时会有问题 mTouch.y = 0.01f; }
/** * 快速模糊图片 * <p>先缩小原图,对小图进行模糊,再放大回原先尺寸</p> * * @param src 源图片 * @param scale 缩放比例(0...1) * @param radius 模糊半径(0...25) * @param recycle 是否回收 * @return 模糊后的图片 */ public static Bitmap fastBlur(final Bitmap src, @FloatRange(from = 0, to = 1, fromInclusive = false) final float scale, @FloatRange(from = 0, to = 25, fromInclusive = false) final float radius, final boolean recycle) { if (isEmptyBitmap(src)) return null; int width = src.getWidth(); int height = src.getHeight(); Matrix matrix = new Matrix(); matrix.setScale(scale, scale); Bitmap scaleBitmap = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG); Canvas canvas = new Canvas(); PorterDuffColorFilter filter = new PorterDuffColorFilter( Color.TRANSPARENT, PorterDuff.Mode.SRC_ATOP); paint.setColorFilter(filter); canvas.scale(scale, scale); canvas.drawBitmap(scaleBitmap, 0, 0, paint); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { scaleBitmap = renderScriptBlur(scaleBitmap, radius, recycle); } else { scaleBitmap = stackBlur(scaleBitmap, (int) radius, recycle); } if (scale == 1) return scaleBitmap; Bitmap ret = Bitmap.createScaledBitmap(scaleBitmap, width, height, true); if (scaleBitmap != null && !scaleBitmap.isRecycled()) scaleBitmap.recycle(); if (recycle && !src.isRecycled()) src.recycle(); return ret; }
public static Bitmap convert(Bitmap a) { int w = a.getWidth(); int h = a.getHeight(); Bitmap newb = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图 Canvas cv = new Canvas(newb); Matrix m = new Matrix(); //m.postScale(1, -1); //镜像垂直翻转 m.postScale(-1, 1); //镜像水平翻转 //m.postRotate(-90); //旋转-90度 Bitmap new2 = Bitmap.createBitmap(a, 0, 0, w, h, m, true); cv.drawBitmap(new2, new Rect(0, 0, new2.getWidth(), new2.getHeight()),new Rect(0, 0, w, h), null); return newb; }
private void initImage() { if (headImageRes != 0) { bitmap = BitmapFactory.decodeResource(getResources(), headImageRes); if (headImageWidth != 0 || headImageHeight != 0) bitmap = getResizedBitmap(bitmap, headImageWidth, headImageHeight); bitmapOffsetX = bitmap.getWidth() / 2; bitmapOffsetY = bitmap.getHeight() / 2; bitmapPosition = new float[2]; bitmapTan = new float[2]; matrix = new Matrix(); } }
@Test public void exifTransverse() { Request data = new Request.Builder(URI_1).rotate(-45).build(); Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888); Bitmap result = transformResult(data, source, ORIENTATION_TRANSVERSE); ShadowBitmap shadowBitmap = shadowOf(result); assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source); Matrix matrix = shadowBitmap.getCreatedFromMatrix(); ShadowMatrix shadowMatrix = shadowOf(matrix); assertThat(shadowMatrix.getPostOperations()).containsExactly("scale -1.0 1.0"); assertThat(shadowMatrix.getPreOperations()).containsExactly("rotate 270.0"); }
public static void mapPoints(Matrix matrix, float[] points) { float[] m = { 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F }; matrix.getValues(m); points[0] = (points[0] * m[0] + m[2]); points[1] = (points[1] * m[4] + m[5]); if (points.length == 4) { points[2] = (points[2] * m[0] + m[2]); points[3] = (points[3] * m[4] + m[5]); } }
private void overlay(Bitmap bm1, Bitmap bm2) { // Combine bitmaps bmOverlay = Bitmap.createBitmap(bm1.getWidth(), bm1.getHeight(), bm1.getConfig()); Canvas canvas = new Canvas(bmOverlay); Paint paint = new Paint(); paint.setAlpha(128); canvas.drawBitmap(bm1, new Matrix(), null); canvas.drawBitmap(bm2, 0, 0, paint); }
Fling(int velocityX, int velocityY) { setState(State.FLING); scroller = new CompatScroller(context); matrix.getValues(m); int startX = (int) m[Matrix.MTRANS_X]; int startY = (int) m[Matrix.MTRANS_Y]; int minX, maxX, minY, maxY; if (getImageWidth() > viewWidth) { minX = viewWidth - (int) getImageWidth(); maxX = 0; } else { minX = maxX = startX; } if (getImageHeight() > viewHeight) { minY = viewHeight - (int) getImageHeight(); maxY = 0; } else { minY = maxY = startY; } scroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY); currX = startX; currY = startY; }
public static Bitmap rotateBitmap(Bitmap bitmap, int degress, boolean needRecycle) { Matrix m = new Matrix(); m.postRotate((float)degress); Bitmap bm = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true); if(needRecycle) { bitmap.recycle(); } return bm; }
/** * Performs boundary checking and fixes the image matrix if it * is out of bounds. */ private void fixTrans() { matrix.getValues(m); float transX = m[Matrix.MTRANS_X]; float transY = m[Matrix.MTRANS_Y]; float fixTransX = getFixTrans(transX, viewWidth, getImageWidth()); float fixTransY = getFixTrans(transY, viewHeight, getImageHeight()); if (fixTransX != 0 || fixTransY != 0) { matrix.postTranslate(fixTransX, fixTransY); } }
public static Bitmap getRotatedBitMap(File imageFile) { if (imageFile == null || !imageFile.canRead() || !imageFile.exists()) { return null; } Bitmap rotatedBitmap = null; try { Bitmap srcBitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath()); ExifInterface exif = new ExifInterface(imageFile.getName()); String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION); int orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL; int rotationAngle = 0; if (orientation == ExifInterface.ORIENTATION_ROTATE_90) rotationAngle = 90; if (orientation == ExifInterface.ORIENTATION_ROTATE_180) rotationAngle = 180; if (orientation == ExifInterface.ORIENTATION_ROTATE_270) rotationAngle = 270; Matrix matrix = new Matrix(); matrix.setRotate(rotationAngle, (float) srcBitmap.getWidth() / 2, (float) srcBitmap.getHeight() / 2); rotatedBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(), srcBitmap.getHeight(), matrix, true); } catch (Exception e) { e.printStackTrace(); CrashlyticsWrapper.log(e); } return rotatedBitmap; }
/** * Constructor with initialization parameters. * * @param chart instance of the chart * @param touchMatrix the touch-matrix of the chart * @param dragTriggerDistance the minimum movement distance that will be interpreted as a "drag" gesture in dp (3dp equals * to about 9 pixels on a 5.5" FHD screen) */ public BarLineChartTouchListener(BarLineChartBase<? extends BarLineScatterCandleBubbleData<? extends IBarLineScatterCandleBubbleDataSet<? extends Entry>>> chart, Matrix touchMatrix, float dragTriggerDistance) { super(chart); this.mMatrix = touchMatrix; this.mDragTriggerDist = Utils.convertDpToPixel(dragTriggerDistance); this.mMinScalePointerDistance = Utils.convertDpToPixel(3.5f); }
/** * 处理图片缩放 */ private Bitmap setScale(Bitmap a) { scale = ((float) (mWidth) / mBitWidth); Matrix mMatrix = new Matrix(); mMatrix.postScale(scale, scale); Bitmap bmp = Bitmap.createBitmap(a, 0, 0, a.getWidth(), a.getHeight(), mMatrix, true); return bmp; }
/** * 获得带倒影的Bitmap * * @param bitmap 源Bitmap * @return 带倒影的Bitmap */ public static Bitmap createReflectionBitmap(Bitmap bitmap) { final int reflectionGap = 4; int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1); Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2, width, height / 2, matrix, false); Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(bitmap, 0, 0, null); Paint deafalutPaint = new Paint(); canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint); canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); paint.setShader(shader); // Set the Transfer mode to be porter duff and destination in paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); // Draw a rectangle using the paint with our linear gradient canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint); return bitmapWithReflection; }