List of usage examples for android.graphics Matrix MSCALE_Y
int MSCALE_Y
To view the source code for android.graphics Matrix MSCALE_Y.
Click Source Link
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; }/* ww w .j a v a2 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 {/*from w w w . j a va 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; }