android.graphics.Matrix Java Examples

The following examples show how to use android.graphics.Matrix. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MatrixUtils.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * android.graphics.Matrixの3x3行列をOpenGLの4x4(列優先)行列に変換する
 * (アフィン変換のみ)
 * |a11 a12 a13|  |0 1 2|      |a11 a12   0 a13|   |0 4 8  12|
 * |a21 a22 a23|  |3 4 5|      |a21 a22   0 a23|   |1 5 9  13|
 * |a31 a32 a33|  |6 7 8| =>   |  0   0   1   0|   |2 6 10 14|
 *                             |a31 a32   0 a33|   |3 7 11 15|
 * @param transform
 * @param result
 * @return
 */
@NonNull
@Size(min=16)
public static float[] toGLMatrix(@NonNull final Matrix transform,
	@NonNull @Size(min=16) final float[] result,
	@NonNull @Size(min=9) final float[] aMatrix) {

	transform.getValues(aMatrix);
	result[ 0] = aMatrix[Matrix.MSCALE_X];
	result[ 1] = aMatrix[Matrix.MSKEW_Y];
	result[ 2] = 0;
	result[ 3] = aMatrix[Matrix.MPERSP_0];
	result[ 4] = aMatrix[Matrix.MSKEW_X];
	result[ 5] = aMatrix[Matrix.MSCALE_Y];
	result[ 6] = 0;
	result[ 7] = aMatrix[Matrix.MPERSP_1];
	result[ 8] = 0;
	result[ 9] = 0;
	result[10] = 1;
	result[11] = 0;
	result[12] = aMatrix[Matrix.MTRANS_X];
	result[13] = aMatrix[Matrix.MTRANS_Y];
	result[14] = 0;
	result[15] = aMatrix[Matrix.MPERSP_2];
	return result;
}
 
Example #2
Source File: RsBlurLinearLayout.java    From HokoBlur with Apache License 2.0 6 votes vote down vote up
private void prepare() {
    int width = getWidth();
    int height = getHeight();

    width = Math.max(width, 1);
    height = Math.max(height, 1);

    if (mBitmap == null || mBitmap.getWidth() != width || mBitmap.getHeight() != height) {
        mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    }

    getLocationInWindow(mLocationInWindow);
    mCanvas.restoreToCount(1);
    mCanvas.setBitmap(mBitmap);
    mCanvas.setMatrix(new Matrix());
    mCanvas.translate(-mLocationInWindow[0], -mLocationInWindow[1]);
    mCanvas.save();
    getRootView().draw(mCanvas);
}
 
Example #3
Source File: TouchImageView.java    From ScaleLayout with Apache License 2.0 6 votes vote down vote up
@Override
public boolean canScrollHorizontally(int direction) {
    matrix.getValues(m);
    float x = m[Matrix.MTRANS_X];

    if (getImageWidth() < viewWidth) {
        return false;

    } else if (x >= -1 && direction < 0) {
        return false;

    } else if (Math.abs(x) + viewWidth + 1 >= getImageWidth() && direction > 0) {
        return false;
    }

    return true;
}
 
Example #4
Source File: ContactChipDrawable.java    From material with Apache License 2.0 6 votes vote down vote up
public ContactChipDrawable(int paddingLeft, int paddingRight, Typeface typeface, int textColor, int textSize, int backgroundColor) {
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(textColor);
    mPaint.setTypeface(typeface);
    mPaint.setTextSize(textSize);

    mTextPaint = new TextPaint(mPaint);
    mMetrics = new BoringLayout.Metrics();
    Paint.FontMetricsInt temp = mTextPaint.getFontMetricsInt();
    mMetrics.ascent = temp.ascent;
    mMetrics.bottom = temp.bottom;
    mMetrics.descent = temp.descent;
    mMetrics.top = temp.top;
    mMetrics.leading = temp.leading;

    mRect = new RectF();

    mMatrix = new Matrix();

    mPaddingLeft = paddingLeft;
    mPaddingRight = paddingRight;
    mBackgroundColor = backgroundColor;
}
 
Example #5
Source File: DrawableProvider.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
/**
 * 将图片按照某个角度进行旋转
 *
 * @param bm     需要旋转的图片
 * @param degree 旋转角度
 * @return 旋转后的图片
 */
public static Bitmap rotateBitmapByDegree(Bitmap bm, int degree) {
    Bitmap returnBm = null;

    // 根据旋转角度,生成旋转矩阵
    Matrix matrix = new Matrix();
    matrix.postRotate(degree);
    try {
        // 将原始图片按照旋转矩阵进行旋转,并得到新的图片
        returnBm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
    }
    if (returnBm == null) {
        returnBm = bm;
    }
    if (bm != returnBm) {
        bm.recycle();
    }
    return returnBm;
}
 
Example #6
Source File: ScaleTypeStartInside.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public void getTransformImpl(
    Matrix outTransform,
    Rect parentRect,
    int childWidth,
    int childHeight,
    float focusX,
    float focusY,
    float scaleX,
    float scaleY) {
  float scale = Math.min(Math.min(scaleX, scaleY), 1.0f);
  float dx = parentRect.left;
  float dy = parentRect.top;
  outTransform.setScale(scale, scale);
  outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
}
 
Example #7
Source File: ViewGroupUtilsHoneycomb.java    From fab-speed-dial with Apache License 2.0 6 votes vote down vote up
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());
        }
    }
}
 
Example #8
Source File: TouchImageView.java    From Expert-Android-Programming with MIT License 6 votes vote down vote up
private void sharedConstructing(Context context) {
    super.setClickable(true);
    this.context = context;
    mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
    mGestureDetector = new GestureDetector(context, new GestureListener());
    matrix = new Matrix();
    prevMatrix = new Matrix();
    m = new float[9];
    normalizedScale = 1;
    if (mScaleType == null) {
        mScaleType = ScaleType.FIT_CENTER;
    }
    minScale = 1;
    maxScale = 3;
    superMinScale = SUPER_MIN_MULTIPLIER * minScale;
    superMaxScale = SUPER_MAX_MULTIPLIER * maxScale;
    setImageMatrix(matrix);
    setScaleType(ScaleType.MATRIX);
    setState(State.NONE);
    onDrawReady = false;
    super.setOnTouchListener(new PrivateOnTouchListener());
}
 
Example #9
Source File: Sign.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void save(int width, int height, boolean transparentBackground, File sigFile) throws IOException {
    if (mNotInitialized)
        return;

    float scale = Math.min((float) width / getWidth(), (float) height / getHeight());
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);

    Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bmp);
    canvas.setMatrix(matrix);

    int color = transparentBackground ? Color.TRANSPARENT : 0xFFFFFF - mPaint.getColor();
    drawSign(canvas, color, mPaint);
    if(sigFile.exists() || sigFile.createNewFile()) {
        FileOutputStream out = new FileOutputStream(sigFile);
        bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
    }
}
 
Example #10
Source File: CameraConnectionFragment.java    From dbclf with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #11
Source File: RangeSeekBar.java    From SimpleVideoEdit with Apache License 2.0 6 votes vote down vote up
private void init() {
    mScaledTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
    //等比例缩放图片
    thumbImageLeft = BitmapFactory.decodeResource(getResources(), R.drawable.video_trim_handle);
    int width = thumbImageLeft.getWidth();
    int height = thumbImageLeft.getHeight();
    int newWidth = dip2px(11);
    int newHeight = dip2px(60);
    float scaleWidth = newWidth * 1.0f / width;
    float scaleHeight = newHeight * 1.0f / height;
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    thumbImageLeft = Bitmap.createBitmap(thumbImageLeft, 0, 0, width, height, matrix, true);
    thumbImageRight = thumbImageLeft;
    thumbPressedImage = thumbImageLeft;
    thumbWidth = newWidth;
    thumbHalfWidth = thumbWidth / 2;


    mBitmapBlack = BitmapFactory.decodeResource(getResources(), R.drawable.upload_overlay_black);
    mBitmapPro = BitmapFactory.decodeResource(getResources(), R.drawable.upload_overlay_trans);
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    rectPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    rectPaint.setStyle(Paint.Style.FILL);
    rectPaint.setColor(Color.parseColor("#ffffff"));
}
 
Example #12
Source File: TouchImageView.java    From ImageGallery with Apache License 2.0 6 votes vote down vote up
private void sharedConstructing(Context context) {
    super.setClickable(true);
    this.context = context;
    mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
    mGestureDetector = new GestureDetector(context, new GestureListener());
    matrix = new Matrix();
    prevMatrix = new Matrix();
    m = new float[9];
    normalizedScale = 1;
    if (mScaleType == null) {
        mScaleType = ScaleType.FIT_CENTER;
    }
    minScale = 1;
    maxScale = 3;
    superMinScale = SUPER_MIN_MULTIPLIER * minScale;
    superMaxScale = SUPER_MAX_MULTIPLIER * maxScale;
    setImageMatrix(matrix);
    setScaleType(ScaleType.MATRIX);
    setState(State.NONE);
    onDrawReady = false;
    super.setOnTouchListener(new PrivateOnTouchListener());
}
 
Example #13
Source File: PinchImageView.java    From SmallGdufe-Android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 执行当前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();
    }
}
 
Example #14
Source File: RotateLoadingLayout.java    From SwipeMenuAndRefresh with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #15
Source File: ParticleHeartView.java    From IndicatorBox with MIT License 6 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    mPaint = new Paint();
    //setFilterBitmap() and setAntiAlias used together to make drawing bitmap anti-aliased.
    mPaint.setFilterBitmap(true);
    mPaint.setAntiAlias(true);
    mMatrix = new Matrix();
    bitmapDisappearDust = BitmapFactory.decodeResource(getResources(), R.drawable.icon_red_dust);
    bitmapDisappearDustHalfWidth = bitmapDisappearDust.getWidth() / 2;
    bitmapDisappearDustHalfHeight = bitmapDisappearDust.getHeight() / 2;
    random = new Random(bitmapDisappearDust.getByteCount());
    mCenterBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_un_praised);
    centerBitmapHalfWidth = mCenterBitmap.getWidth() / 2;
    centerBitmapHalfHeight = mCenterBitmap.getHeight() / 2;
    this.setOnTouchListener(this);
    isPraised = false;
    //Follow circle
    outerCirclePaint = new Paint();
    innerCirclePaint = new Paint();
    outerCirclePaint.setStyle(Paint.Style.FILL);
    outerCirclePaint.setAntiAlias(true);
    innerCirclePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    innerCirclePaint.setAntiAlias(true);
    argbEvaluator = new ArgbEvaluator();
}
 
Example #16
Source File: AsteroidData.java    From Asteroid with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the position Matrix of the asteroid to draw
 * in the next frame.
 *
 * @param speed     The speed of the asteroid.
 * @param width     The width of the drawing canvas.
 * @param height    The height of the drawing canvas.
 * @return          The position Matrix of the asteroid.
 *                  Equals null if the asteroid can no longer
 *                  be drawn within the given width/height.
 */
public Matrix next(float speed, int width, int height) {
    if ((y - asteroidBitmap.getHeight()) < height) {
        y += yDiff * speed;
        rotation += rotationDiff;
        x += xDiff * speed;
    } else return null;

    float left = x * width, top = y;
    position = new Rect(
            (int) left - (asteroidBitmap.getWidth() / 2),
            (int) top - (asteroidBitmap.getHeight() / 2),
            (int) left + (asteroidBitmap.getWidth() / 2),
            (int) top + (asteroidBitmap.getHeight() / 2)
    );

    Matrix matrix = new Matrix();
    matrix.postTranslate(-asteroidBitmap.getWidth() / 2, -asteroidBitmap.getHeight() / 2);
    matrix.postRotate(rotation);
    matrix.postTranslate(left, top);

    return matrix;
}
 
Example #17
Source File: BottomItemView.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
private Bitmap getScaleBitmap(Bitmap viewBg, float scalX, float scalY) {
    Matrix matrix = getBitmapMatrix(viewBg, scalX, scalY);

    int width = viewBg.getWidth();//获取资源位图的宽
    int height = viewBg.getHeight();//获取资源位图的高

    Bitmap dstbmp = Bitmap.createBitmap(viewBg, 0, 0,
            width, height, matrix, true); //根据缩放比例获取新的位图

    return dstbmp;
}
 
Example #18
Source File: ScreencastDispatcher.java    From stetho with MIT License 5 votes vote down vote up
private void updateScreenBitmap() {
  if (!mIsRunning) {
    return;
  }
  Activity activity = mActivityTracker.tryGetTopActivity();
  if (activity == null) {
    return;
  }
  // This stuff needs to happen in the UI thread
  View rootView = activity.getWindow().getDecorView();
  try {
    if (mBitmap == null) {
      int viewWidth = rootView.getWidth();
      int viewHeight = rootView.getHeight();
      float scale = Math.min((float) mRequest.maxWidth / (float) viewWidth,
          (float) mRequest.maxHeight / (float) viewHeight);
      int destWidth = (int) (viewWidth * scale);
      int destHeight = (int) (viewHeight * scale);
      mBitmap = Bitmap.createBitmap(destWidth, destHeight, Bitmap.Config.RGB_565);
      mCanvas = new Canvas(mBitmap);
      Matrix matrix = new Matrix();
      mTempSrc.set(0, 0, viewWidth, viewHeight);
      mTempDst.set(0, 0, destWidth, destHeight);
      matrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.CENTER);
      mCanvas.setMatrix(matrix);
    }
    rootView.draw(mCanvas);
  } catch (OutOfMemoryError e) {
    LogUtil.w("Out of memory trying to allocate screencast Bitmap.");
  }
}
 
Example #19
Source File: TouchImageView.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRotate(float delta) {
    if (((System.currentTimeMillis() - _rotationTimestampDebounce)) > 300 && Math.abs(delta) > 4.6) {
        _rotationDegrees = ((_rotationDegrees + (90 * (delta > 0 ? 1 : -1))) % 360);
        Matrix matrix = new Matrix();
        matrix.postRotate(_rotationDegrees);
        TouchImageView.super.setImageBitmap(Bitmap.createBitmap(_orig, 0, 0, _orig.getWidth(), _orig.getHeight(), matrix, true));
        _rotationTimestampDebounce = System.currentTimeMillis();
    }
}
 
Example #20
Source File: PageView.java    From Mupdf with Apache License 2.0 5 votes vote down vote up
public PageView(Context c, MuPDFCore core, Point parentSize, Bitmap sharedHqBm) {
	super(c);
	mContext = c;
	mCore = core;
	mParentSize = parentSize;
	setBackgroundColor(BACKGROUND_COLOR);
	mEntireBm = Bitmap.createBitmap(parentSize.x, parentSize.y, Config.ARGB_8888);
	mPatchBm = sharedHqBm;
	mEntireMat = new Matrix();
}
 
Example #21
Source File: MyBitmapUtils.java    From FaceDetect with Apache License 2.0 5 votes vote down vote up
/**
 * 旋转bitmap
 * @param bitmap
 * @param degress 旋转角度
 * @param needRecycle
 * @return
 */
public static Bitmap rotateBitmap(Bitmap bitmap, int degress, boolean needRecycle) {
    Matrix m = new Matrix();
    m.postRotate(degress);
    Bitmap bm = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
    if(needRecycle) {
        bitmap.recycle();
    }
    return bm;
}
 
Example #22
Source File: ZoomImageView.java    From Gank-Veaer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Helper method that maps the supplied Matrix to the current Drawable
 *
 * @param matrix
 *            - Matrix to map Drawable against
 * @return RectF - Displayed Rectangle
 */
private RectF getDisplayRect(Matrix matrix) {
    Drawable d = getDrawable();
    if (null != d) {
        displayRect.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        matrix.mapRect(displayRect);
        return displayRect;
    }

    return null;
}
 
Example #23
Source File: DrawerArrowDrawable.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
/**
 * Scales the paths to the given screen density. If the density matches the
 * {@link DrawerArrowDrawable#PATH_GEN_DENSITY}, no scaling needs to be done.
 */
private static void scalePath(Path path, float density) {
    if (density == PATH_GEN_DENSITY) return;
    Matrix scaleMatrix = new Matrix();
    scaleMatrix.setScale(density / PATH_GEN_DENSITY, density / PATH_GEN_DENSITY, 0, 0);
    path.transform(scaleMatrix);
}
 
Example #24
Source File: CoverImageView.java    From Klyph with MIT License 5 votes vote down vote up
@Override
protected boolean  setFrame(int l, int t, int r, int b)
{
	boolean  changed = super.setFrame(l, t, r, b);

	if (getDrawable() == null)
		return changed;

	int dwidth = getDrawable().getIntrinsicWidth();
	int dheight = getDrawable().getIntrinsicHeight();

	int vwidth = getWidth() - getPaddingLeft() - getPaddingRight();
	// int vheight = getHeight() - getPaddingTop() - getPaddingBottom();

	Matrix matrix = new Matrix();
	float scale;
	float dy = 0;

	scale = (float) vwidth / dwidth;
	dy = (float) ((dheight * scale) * (yOffset / 100f));

	matrix.setScale(scale, scale);
	matrix.postTranslate(0, -dy);

	setImageMatrix(matrix);

	return changed;
}
 
Example #25
Source File: ImagePreviewDialog.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void setImageMatrix() {
    Matrix mtrx = new Matrix();
    mtrx.postScale(scaledWidth, scaledHeight);
    mtrx.postTranslate(transX, transY);
    imageView.setImageMatrix(mtrx);
    imageView.setScaleType(ScaleType.MATRIX);
    imageView.invalidate();
}
 
Example #26
Source File: ClipZoomImageView.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 根据当前图片的Matrix获得图片的范围
 *
 * @return
 */
private RectF getMatrixRectF()
{
    Matrix matrix = mScaleMatrix;
    RectF rect = new RectF();
    Drawable d = getDrawable();
    if (null != d)
    {
        rect.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        matrix.mapRect(rect);
    }
    return rect;
}
 
Example #27
Source File: PhotoViewAttacher.java    From GalleryFinal with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that maps the supplied Matrix to the current Drawable
 *
 * @param matrix - Matrix to map Drawable against
 * @return RectF - Displayed Rectangle
 */
private RectF getDisplayRect(Matrix matrix) {
    ImageView imageView = getImageView();

    if (null != imageView) {
        Drawable d = imageView.getDrawable();
        if (null != d) {
            mDisplayRect.set(0, 0, d.getIntrinsicWidth(),
                    d.getIntrinsicHeight());
            matrix.mapRect(mDisplayRect);
            return mDisplayRect;
        }
    }
    return null;
}
 
Example #28
Source File: GestureImageView.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
private void calcInitParams()
{
	if(_imageRect.width()==0 || _imageRect.height()==0 || _viewRect.width() == 0 || _viewRect.height() == 0)
		return;

	_scaleX = _scaleY = 0;
	_posX = _posY = 0;
	_scaleFactorX = _scaleFactorY = 1.f;
	RectF imageRect = new RectF(_imageRect);
	if(_rotation != 0)
	{
		applyTrans();
		_imageMatrix.mapRect(imageRect);
	}

	float scaleFactor;
	if(imageRect.width()<=_viewRect.width() && imageRect.height()<= _viewRect.height() && !_autoZoom)
		scaleFactor = 1.f;
	else	
		scaleFactor = Math.min(
				_viewRect.height()/imageRect.height(),
				_viewRect.width()/imageRect.width()
		);


	_scaleFactorX = _flipX ? -scaleFactor : scaleFactor;
	_scaleFactorY = _flipY ? -scaleFactor : scaleFactor;
	_imageMatrix.reset();
	_imageMatrix.postRotate(_rotation);
	_imageMatrix.postScale(_scaleFactorX, _scaleFactorY);
	validate();
	Matrix m = new Matrix(_imageMatrix);
	setImageMatrix(m);
	_inited = true;
}
 
Example #29
Source File: TouchImageView.java    From Chimee with MIT License 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #30
Source File: OrientedDrawableTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testCreation_flipVertical() {
  OrientedDrawable drawable =
      new OrientedDrawable(mDrawable, 0, ExifInterface.ORIENTATION_FLIP_VERTICAL);
  drawable.setBounds(mBounds);
  drawable.draw(mCanvas);

  Matrix expectedMatrix = new Matrix();
  expectedMatrix.setScale(1, -1);
  assertFalse(drawable.mRotationMatrix.isIdentity());
  AndroidGraphicsTestUtils.assertEquals(expectedMatrix, drawable.mRotationMatrix);
  verifySetBounds(expectedMatrix);
}