Example usage for android.widget ImageView getImageMatrix

List of usage examples for android.widget ImageView getImageMatrix

Introduction

In this page you can find the example usage for android.widget ImageView getImageMatrix.

Prototype

public Matrix getImageMatrix() 

Source Link

Document

Returns the view's optional matrix.

Usage

From source file:com.example.PagerCoverFlow.PagerContainer.java

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    //Force the container to redraw on scrolling.
    //Without this the outer pages render initially and then stay static

    int rotationAngle = (int) (positionOffset * mMaxRotationAngle);
    if (Math.abs(rotationAngle) > mMaxRotationAngle) {
        rotationAngle = (rotationAngle < 0) ? -mMaxRotationAngle : mMaxRotationAngle;
    }/*from w ww  . ja  v  a  2s.c  o  m*/
    FrameLayout frameLayout = (FrameLayout) mPager.getChildAt(position);
    ImageView imageview = (ImageView) frameLayout.getChildAt(0);
    Log.i("Test", "positino2:" + rotationAngle);

    transformImageBitmap((ImageView) imageview, imageview.getImageMatrix(), rotationAngle);

    //        Matrix m = mPager.getMatrix();
    //        RectF drawableRect = new RectF(0, 0, width - rotationAngle, width - rotationAngle);
    //        RectF viewRect = new RectF(0, 0, imageview.getWidth(), imageview.getHeight());
    //        m.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER);
    //        mPager.setMa

    if (mNeedsRedraw)
        invalidate();
}

From source file:android.support.v17.leanback.widget.DetailsOverviewSharedElementHelper.java

private void changeImageViewScale(View snapshotView) {
    ImageView snapshotImageView = (ImageView) snapshotView;
    ImageView imageView = mViewHolder.mImageView;
    if (DEBUG) {//from   ww w.  j  a v a  2 s . c om
        Log.d(TAG, "changeImageViewScale to " + snapshotImageView.getScaleType());
    }
    imageView.setScaleType(snapshotImageView.getScaleType());
    if (snapshotImageView.getScaleType() == ScaleType.MATRIX) {
        imageView.setImageMatrix(snapshotImageView.getImageMatrix());
    }
    updateImageViewAfterScaleTypeChange(imageView);
}

From source file:com.github.colorchief.colorchief.MainActivity.java

private boolean clickInImage(int x, int y, ImageView imageView) {

    //ImageView imageViewer = (ImageView) findViewById(R.id.imageView);

    if (imageView.getVisibility() != View.VISIBLE) {
        return false;
    }// w w w .j a v a  2 s  .c  om

    int[] imageViewCoords = new int[2];
    imageView.getLocationOnScreen(imageViewCoords);

    float[] imageViewMatrix = new float[9];
    imageView.getImageMatrix().getValues(imageViewMatrix);
    float scaleX = imageViewMatrix[Matrix.MSCALE_X];
    float scaleY = imageViewMatrix[Matrix.MSCALE_Y];

    Bitmap bitmap = null;
    int bitmapWidth = 0;
    int bitmapHeight = 0;

    try {
        bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        bitmapWidth = bitmap.getWidth();
        bitmapHeight = bitmap.getHeight();
    } catch (NullPointerException npe) {
        Log.e(TAG, "Failed to extract Bitmap from ImageView: " + npe);
    }

    //assuming Bitmap is centred in imageViewer
    int scaledBitmapWidth = Math.round(bitmapWidth * scaleX);
    int scaledBitmapHeight = Math.round(bitmapHeight * scaleY);

    int xOffsetBitmap2imageViewer = (imageView.getWidth() - scaledBitmapWidth) / 2;
    int yOffsetBitmap2imageViewer = (imageView.getHeight() - scaledBitmapHeight) / 2;

    // get total bitmap offset vs. screen origin
    int xTotalOffset = imageViewCoords[0] + xOffsetBitmap2imageViewer;
    int yTotalOffset = imageViewCoords[1] + yOffsetBitmap2imageViewer;

    if ((x >= xTotalOffset) && (x <= xTotalOffset + scaledBitmapWidth) && (y >= yTotalOffset)
            && (y <= yTotalOffset + scaledBitmapHeight)) {
        return true;
    } else {
        return false;
    }
}

From source file:com.github.colorchief.colorchief.MainActivity.java

private int[] clickImagePixelLocation(int x, int y, ImageView imageView) {
    int[] pixelLocation = new int[2];

    //ImageView imageViewer = (ImageView) findViewById(R.id.imageView);
    //Bitmap bitmap = null;
    //Drawable displayedDrawable = null;

    int bitmapWidth;
    int bitmapHeight;

    try {/* w  ww .  j  av  a 2 s .  c  o m*/
        //bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        bitmapWidth = bitmapScaledOriginal.getWidth();
        bitmapHeight = bitmapScaledOriginal.getHeight();
    } catch (NullPointerException npe) {
        Log.e(TAG,
                "Failed to extract Bitmap from ImageView or " + "access width and height parameters: " + npe);
        pixelLocation[0] = pixelLocation[1] = 0;
        return pixelLocation;
    }

    float[] imageMatrixValues = new float[9];
    imageView.getImageMatrix().getValues(imageMatrixValues);
    float scaleX = imageMatrixValues[Matrix.MSCALE_X];
    float scaleY = imageMatrixValues[Matrix.MSCALE_Y];

    int[] imageViewerLoc = new int[2];
    imageView.getLocationOnScreen(imageViewerLoc);

    //assuming Bitmap is centred in imageViewer
    int xOffsetBitmap2imageViewer = (imageView.getWidth() - Math.round(bitmapWidth * scaleX)) / 2;
    int yOffsetBitmap2imageViewer = (imageView.getHeight() - Math.round(bitmapHeight * scaleY)) / 2;

    // get total bitmap offset vs. screen origin
    int xTotalOffset = imageViewerLoc[0] + xOffsetBitmap2imageViewer;
    int yTotalOffset = imageViewerLoc[1] + yOffsetBitmap2imageViewer;

    int xLocationScaledBitmap = x - xTotalOffset;
    int yLocationScaledBitmap = y - yTotalOffset;

    pixelLocation[0] = Math.round(xLocationScaledBitmap / scaleX);
    pixelLocation[1] = Math.round(yLocationScaledBitmap / scaleY);

    Log.d(TAG, "Pixel location x,y = " + Integer.toString(pixelLocation[0]) + ", "
            + Integer.toString(pixelLocation[1]));

    if (pixelLocation[0] < 0)
        pixelLocation[0] = 0;
    if (pixelLocation[0] > (bitmapWidth - 1))
        pixelLocation[0] = (bitmapWidth - 1);

    if (pixelLocation[1] < 0)
        pixelLocation[1] = 0;
    if (pixelLocation[1] > (bitmapHeight - 1))
        pixelLocation[1] = (bitmapHeight - 1);

    return pixelLocation;
}