Java Code Examples for android.widget.ImageView.ScaleType#MATRIX
The following examples show how to use
android.widget.ImageView.ScaleType#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: WXImage.java From weex with Apache License 2.0 | 6 votes |
private ScaleType getResizeMode(String resizeMode) { ScaleType scaleType = ScaleType.FIT_XY; if (TextUtils.isEmpty(resizeMode)) { return scaleType; } if (resizeMode.equals("cover")) { scaleType = ScaleType.CENTER_CROP; } else if (resizeMode.equals("contain")) { scaleType = ScaleType.FIT_CENTER; } else if (resizeMode.equals("stretch")) { scaleType = ScaleType.FIT_XY; } else if (resizeMode.equals("center")) { scaleType = ScaleType.CENTER; } else if (resizeMode.equals("start")) { scaleType = ScaleType.MATRIX; } else if (resizeMode.equals("end")) { scaleType = ScaleType.FIT_END; } return scaleType; }
Example 2
Source File: PhotoViewAttacher.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
private void checkImageViewScaleType() { ImageView imageView = getImageView(); /** * PhotoView's getScaleType() will just divert to this.getScaleType() so * only call if we're not attached to a PhotoView. */ if (null != imageView && !(imageView instanceof PhotoView)) { if (imageView.getScaleType() != ScaleType.MATRIX) { throw new IllegalStateException( "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher"); } } }
Example 3
Source File: PhotoViewAttacher.java From WifiChat with GNU General Public License v2.0 | 5 votes |
private void checkImageViewScaleType() { ImageView imageView = getImageView(); /** * PhotoView's getScaleType() will just divert to this.getScaleType() so * only call if we're not attached to a PhotoView. */ if (null != imageView && !(imageView instanceof PhotoView)) { if (imageView.getScaleType() != ScaleType.MATRIX) { throw new IllegalStateException( "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher"); } } }
Example 4
Source File: PhotoViewAttacher.java From iBeebo with GNU General Public License v3.0 | 5 votes |
private void checkImageViewScaleType() { ImageView imageView = getImageView(); /** * PhotoView's getScaleType() will just divert to this.getScaleType() so only call if we're * not attached to a PhotoView. */ if (null != imageView && !(imageView instanceof WeiboGalleryPhotoView)) { if (imageView.getScaleType() != ScaleType.MATRIX) { throw new IllegalStateException( "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher"); } } }
Example 5
Source File: PhotoViewAttacher.java From iBeebo with GNU General Public License v3.0 | 5 votes |
private void checkImageViewScaleType() { ImageView imageView = getImageView(); /** * PhotoView's getScaleType() will just divert to this.getScaleType() so only call if we're * not attached to a PhotoView. */ if (null != imageView && !(imageView instanceof WeiboGalleryPhotoView)) { if (imageView.getScaleType() != ScaleType.MATRIX) { throw new IllegalStateException( "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher"); } } }
Example 6
Source File: PhotoViewAttacher.java From android-discourse with Apache License 2.0 | 5 votes |
private void checkImageViewScaleType() { ImageView imageView = getImageView(); /** * PhotoView's getScaleType() will just divert to this.getScaleType() so * only call if we're not attached to a PhotoView. */ if (null != imageView && !(imageView instanceof IPhotoView)) { if (imageView.getScaleType() != ScaleType.MATRIX) { throw new IllegalStateException("The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher"); } } }
Example 7
Source File: PhotoViewAttacher.java From school_shop with MIT License | 5 votes |
private void checkImageViewScaleType() { ImageView imageView = getImageView(); /** * PhotoView's getScaleType() will just divert to this.getScaleType() so * only call if we're not attached to a PhotoView. */ if (null != imageView && !(imageView instanceof PhotoView)) { if (imageView.getScaleType() != ScaleType.MATRIX) { throw new IllegalStateException( "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher"); } } }
Example 8
Source File: PhotoViewAttacher.java From jmessage-android-uikit with MIT License | 5 votes |
private void checkImageViewScaleType() { ImageView imageView = getImageView(); /** * PhotoView's getScaleType() will just divert to this.getScaleType() so * only call if we're not attached to a PhotoView. */ if (null != imageView && !(imageView instanceof PhotoView)) { if (imageView.getScaleType() != ScaleType.MATRIX) { throw new IllegalStateException( "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher"); } } }
Example 9
Source File: PhotoViewAttacher.java From jmessage-android-uikit with MIT License | 5 votes |
private void checkImageViewScaleType() { ImageView imageView = getImageView(); /** * PhotoView's getScaleType() will just divert to this.getScaleType() so * only call if we're not attached to a PhotoView. */ if (null != imageView && !(imageView instanceof PhotoView)) { if (imageView.getScaleType() != ScaleType.MATRIX) { throw new IllegalStateException( "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher"); } } }
Example 10
Source File: ViewManager.java From react-native-image-zoom with MIT License | 5 votes |
@ReactProp(name = "scaleType") public void setScaleType(PhotoViewWrapper view, String scaleType) { ScaleType value = ScaleType.CENTER; switch (scaleType) { case "center": value = ScaleType.CENTER; break; case "centerCrop": value = ScaleType.CENTER_CROP; break; case "centerInside": value = ScaleType.CENTER_INSIDE; break; case "fitCenter": value = ScaleType.FIT_CENTER; break; case "fitStart": value = ScaleType.FIT_START; break; case "fitEnd": value = ScaleType.FIT_END; break; case "fitXY": value = ScaleType.FIT_XY; break; case "matrix": value = ScaleType.MATRIX; break; } view.setScaleType(value); }
Example 11
Source File: PhotoViewAttacher.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
private void checkImageViewScaleType() { ImageView imageView = getImageView(); /** * PhotoView's getScaleType() will just divert to this.getScaleType() so * only call if we're not attached to a PhotoView. */ if (null != imageView && !(imageView instanceof EasePhotoView)) { if (imageView.getScaleType() != ScaleType.MATRIX) { throw new IllegalStateException( "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher"); } } }
Example 12
Source File: PhotoViewAttacher.java From PicturePicker with Apache License 2.0 | 5 votes |
private void checkImageViewScaleType() { ImageView imageView = getImageView(); /** * PhotoView's getScaleType() will just divert to this.getScaleType() so * only call if we're not attached to a PhotoView. */ if (null != imageView && !(imageView instanceof PhotoView)) { if (imageView.getScaleType() != ScaleType.MATRIX) { throw new IllegalStateException( "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher"); } } }
Example 13
Source File: PhotoViewAttacher.java From LLApp with Apache License 2.0 | 5 votes |
private void checkImageViewScaleType() { ImageView imageView = getImageView(); /** * PhotoView's getScaleType() will just divert to this.getScaleType() so * only call if we're not attached to a PhotoView. */ if (null != imageView && !(imageView instanceof PhotoView)) { if (imageView.getScaleType() != ScaleType.MATRIX) { throw new IllegalStateException( "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher"); } } }
Example 14
Source File: PhotoViewAttacher.java From monolog-android with MIT License | 5 votes |
private void checkImageViewScaleType() { ImageView imageView = getImageView(); /** * PhotoView's getScaleType() will just divert to this.getScaleType() so * only call if we're not attached to a PhotoView. */ if (null != imageView && !(imageView instanceof EasePhotoView)) { if (imageView.getScaleType() != ScaleType.MATRIX) { throw new IllegalStateException( "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher"); } } }
Example 15
Source File: PhotoViewAttacher.java From Social with Apache License 2.0 | 5 votes |
private void checkImageViewScaleType() { ImageView imageView = getImageView(); /** * PhotoView's getScaleType() will just divert to this.getScaleType() so * only call if we're not attached to a PhotoView. */ if (null != imageView && !(imageView instanceof EasePhotoView)) { if (imageView.getScaleType() != ScaleType.MATRIX) { throw new IllegalStateException( "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher"); } } }
Example 16
Source File: PhotoViewAttacher.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private void checkImageViewScaleType() { ImageView imageView = getImageView(); /** * PhotoView's getScaleType() will just divert to this.getScaleType() so * only call if we're not attached to a PhotoView. */ if (null != imageView && !(imageView instanceof PhotoView)) { if (imageView.getScaleType() != ScaleType.MATRIX) { throw new IllegalStateException( "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher"); } } }
Example 17
Source File: AdaptiveTwoLevelScales.java From sketch with Apache License 2.0 | 4 votes |
@Override public void reset(@NonNull final Context context, @NonNull final Sizes sizes, @Nullable final ScaleType scaleType, final float rotateDegrees, final boolean readMode) { final int drawableWidth = rotateDegrees % 180 == 0 ? sizes.drawableSize.getWidth() : sizes.drawableSize.getHeight(); final int drawableHeight = rotateDegrees % 180 == 0 ? sizes.drawableSize.getHeight() : sizes.drawableSize.getWidth(); final int imageWidth = rotateDegrees % 180 == 0 ? sizes.imageSize.getWidth() : sizes.imageSize.getHeight(); final int imageHeight = rotateDegrees % 180 == 0 ? sizes.imageSize.getHeight() : sizes.imageSize.getWidth(); final float widthScale = (float) sizes.viewSize.getWidth() / drawableWidth; final float heightScale = (float) sizes.viewSize.getHeight() / drawableHeight; final boolean imageThanViewLarge = drawableWidth > sizes.viewSize.getWidth() || drawableHeight > sizes.viewSize.getHeight(); final ScaleType finalScaleType; if (scaleType == ScaleType.MATRIX) { finalScaleType = ScaleType.FIT_CENTER; } else if (scaleType == ScaleType.CENTER_INSIDE) { finalScaleType = imageThanViewLarge ? ScaleType.FIT_CENTER : ScaleType.CENTER; } else { finalScaleType = scaleType; } // 小的是完整显示比例,大的是充满比例 fullZoomScale = Math.min(widthScale, heightScale); fillZoomScale = Math.max(widthScale, heightScale); originZoomScale = Math.max((float) imageWidth / drawableWidth, (float) imageHeight / drawableHeight); initZoomScale = getInitScale(context, sizes, finalScaleType, rotateDegrees, readMode); ImageSizeCalculator sizeCalculator = Sketch.with(context).getConfiguration().getSizeCalculator(); if (readMode && sizeCalculator.canUseReadModeByHeight(imageWidth, imageHeight)) { // 阅读模式下保证阅读效果最重要 minZoomScale = fullZoomScale; maxZoomScale = Math.max(originZoomScale, fillZoomScale); } else if (readMode && sizeCalculator.canUseReadModeByWidth(imageWidth, imageHeight)) { // 阅读模式下保证阅读效果最重要 minZoomScale = fullZoomScale; maxZoomScale = Math.max(originZoomScale, fillZoomScale); } else if (finalScaleType == ScaleType.CENTER) { minZoomScale = 1.0f; maxZoomScale = Math.max(originZoomScale, fillZoomScale); } else if (finalScaleType == ScaleType.CENTER_CROP) { minZoomScale = fillZoomScale; // 由于CENTER_CROP的时候最小缩放比例就是充满比例,所以最大缩放比例一定要比充满比例大的多 maxZoomScale = Math.max(originZoomScale, fillZoomScale * 1.5f); } else if (finalScaleType == ScaleType.FIT_START || finalScaleType == ScaleType.FIT_CENTER || finalScaleType == ScaleType.FIT_END) { minZoomScale = fullZoomScale; // 如果原始比例仅仅比充满比例大一点点,还是用充满比例作为最大缩放比例比较好,否则谁大用谁 if (originZoomScale > fillZoomScale && (fillZoomScale * 1.2f) >= originZoomScale) { maxZoomScale = fillZoomScale; } else { maxZoomScale = Math.max(originZoomScale, fillZoomScale); } // 最大缩放比例和最小缩放比例的差距不能太小,最小得是最小缩放比例的1.5倍 maxZoomScale = Math.max(maxZoomScale, minZoomScale * 1.5f); } else if (finalScaleType == ScaleType.FIT_XY) { minZoomScale = fullZoomScale; maxZoomScale = fullZoomScale; } else { // 基本不会走到这儿 minZoomScale = fullZoomScale; maxZoomScale = fullZoomScale; } // 这样的情况基本不会出现,不过还是加层保险 if (minZoomScale > maxZoomScale) { minZoomScale = minZoomScale + maxZoomScale; maxZoomScale = minZoomScale - maxZoomScale; minZoomScale = minZoomScale - maxZoomScale; } // 双击缩放比例始终由最小缩放比例和最大缩放比例组成 doubleClickZoomScales = new float[]{minZoomScale, maxZoomScale}; }
Example 18
Source File: ScaleDragHelper.java From sketch with Apache License 2.0 | 4 votes |
@SuppressWarnings("ConstantConditions") private void resetBaseMatrix() { baseMatrix.reset(); Size viewSize = imageZoomer.getViewSize(); Size imageSize = imageZoomer.getImageSize(); Size drawableSize = imageZoomer.getDrawableSize(); boolean readMode = imageZoomer.isReadMode(); ScaleType scaleType = imageZoomer.getScaleType(); final int drawableWidth = imageZoomer.getRotateDegrees() % 180 == 0 ? drawableSize.getWidth() : drawableSize.getHeight(); final int drawableHeight = imageZoomer.getRotateDegrees() % 180 == 0 ? drawableSize.getHeight() : drawableSize.getWidth(); final int imageWidth = imageZoomer.getRotateDegrees() % 180 == 0 ? imageSize.getWidth() : imageSize.getHeight(); final int imageHeight = imageZoomer.getRotateDegrees() % 180 == 0 ? imageSize.getHeight() : imageSize.getWidth(); boolean imageThanViewLarge = drawableWidth > viewSize.getWidth() || drawableHeight > viewSize.getHeight(); final ScaleType finalScaleType; if (scaleType == ScaleType.MATRIX) { finalScaleType = ScaleType.FIT_CENTER; } else if (scaleType == ScaleType.CENTER_INSIDE) { finalScaleType = imageThanViewLarge ? ScaleType.FIT_CENTER : ScaleType.CENTER; } else { finalScaleType = scaleType; } float initScale = imageZoomer.getZoomScales().getInitZoomScale(); ImageSizeCalculator sizeCalculator = Sketch.with(imageZoomer.getImageView().getContext()).getConfiguration().getSizeCalculator(); if (readMode && sizeCalculator.canUseReadModeByHeight(imageWidth, imageHeight)) { baseMatrix.postScale(initScale, initScale); } else if (readMode && sizeCalculator.canUseReadModeByWidth(imageWidth, imageHeight)) { baseMatrix.postScale(initScale, initScale); } else if (finalScaleType == ScaleType.CENTER) { baseMatrix.postScale(initScale, initScale); baseMatrix.postTranslate((viewSize.getWidth() - drawableWidth) / 2F, (viewSize.getHeight() - drawableHeight) / 2F); } else if (finalScaleType == ScaleType.CENTER_CROP) { baseMatrix.postScale(initScale, initScale); baseMatrix.postTranslate((viewSize.getWidth() - drawableWidth * initScale) / 2F, (viewSize.getHeight() - drawableHeight * initScale) / 2F); } else if (finalScaleType == ScaleType.FIT_START) { baseMatrix.postScale(initScale, initScale); baseMatrix.postTranslate(0, 0); } else if (finalScaleType == ScaleType.FIT_END) { baseMatrix.postScale(initScale, initScale); baseMatrix.postTranslate(0, (viewSize.getHeight() - drawableHeight * initScale)); } else if (finalScaleType == ScaleType.FIT_CENTER) { baseMatrix.postScale(initScale, initScale); baseMatrix.postTranslate(0, (viewSize.getHeight() - drawableHeight * initScale) / 2F); } else if (finalScaleType == ScaleType.FIT_XY) { RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight); RectF mTempDst = new RectF(0, 0, viewSize.getWidth(), viewSize.getHeight()); baseMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.FILL); } }
Example 19
Source File: AdaptiveTwoLevelScales.java From sketch with Apache License 2.0 | 4 votes |
private float getInitScale(@NonNull final Context context, @NonNull final Sizes sizes, @NonNull final ScaleType scaleType, final float rotateDegrees, final boolean readMode) { final int drawableWidth = rotateDegrees % 180 == 0 ? sizes.drawableSize.getWidth() : sizes.drawableSize.getHeight(); final int drawableHeight = rotateDegrees % 180 == 0 ? sizes.drawableSize.getHeight() : sizes.drawableSize.getWidth(); final int imageWidth = rotateDegrees % 180 == 0 ? sizes.imageSize.getWidth() : sizes.imageSize.getHeight(); final int imageHeight = rotateDegrees % 180 == 0 ? sizes.imageSize.getHeight() : sizes.imageSize.getWidth(); final float widthScale = (float) sizes.viewSize.getWidth() / drawableWidth; final float heightScale = (float) sizes.viewSize.getHeight() / drawableHeight; boolean imageThanViewLarge = drawableWidth > sizes.viewSize.getWidth() || drawableHeight > sizes.viewSize.getHeight(); ImageSizeCalculator sizeCalculator = Sketch.with(context).getConfiguration().getSizeCalculator(); final ScaleType finalScaleType; if (scaleType == ScaleType.MATRIX) { finalScaleType = ScaleType.FIT_CENTER; } else if (scaleType == ScaleType.CENTER_INSIDE) { finalScaleType = imageThanViewLarge ? ScaleType.FIT_CENTER : ScaleType.CENTER; } else { finalScaleType = scaleType; } if (readMode && sizeCalculator.canUseReadModeByHeight(imageWidth, imageHeight)) { return widthScale; } else if (readMode && sizeCalculator.canUseReadModeByWidth(imageWidth, imageHeight)) { return heightScale; } else if (finalScaleType == ScaleType.CENTER) { return 1.0f; } else if (finalScaleType == ScaleType.CENTER_CROP) { return Math.max(widthScale, heightScale); } else if (finalScaleType == ScaleType.FIT_START) { return Math.min(widthScale, heightScale); } else if (finalScaleType == ScaleType.FIT_END) { return Math.min(widthScale, heightScale); } else if (finalScaleType == ScaleType.FIT_CENTER) { return Math.min(widthScale, heightScale); } else if (finalScaleType == ScaleType.FIT_XY) { return 1.0f; } else { return 1.0f; } }
Example 20
Source File: SharedElementCallback.java From letv with Apache License 2.0 | 4 votes |
public Parcelable onCaptureSharedElementSnapshot(View sharedElement, Matrix viewToGlobalMatrix, RectF screenBounds) { Bitmap bitmap; if (sharedElement instanceof ImageView) { ImageView imageView = (ImageView) sharedElement; Drawable d = imageView.getDrawable(); Drawable bg = imageView.getBackground(); if (d != null && bg == null) { bitmap = createDrawableBitmap(d); if (bitmap != null) { Bundle bundle = new Bundle(); bundle.putParcelable(BUNDLE_SNAPSHOT_BITMAP, bitmap); bundle.putString(BUNDLE_SNAPSHOT_IMAGE_SCALETYPE, imageView.getScaleType().toString()); if (imageView.getScaleType() != ScaleType.MATRIX) { return bundle; } float[] values = new float[9]; imageView.getImageMatrix().getValues(values); bundle.putFloatArray(BUNDLE_SNAPSHOT_IMAGE_MATRIX, values); return bundle; } } } int bitmapWidth = Math.round(screenBounds.width()); int bitmapHeight = Math.round(screenBounds.height()); bitmap = null; if (bitmapWidth > 0 && bitmapHeight > 0) { float scale = Math.min(1.0f, ((float) MAX_IMAGE_SIZE) / ((float) (bitmapWidth * bitmapHeight))); bitmapWidth = (int) (((float) bitmapWidth) * scale); bitmapHeight = (int) (((float) bitmapHeight) * scale); if (this.mTempMatrix == null) { this.mTempMatrix = new Matrix(); } this.mTempMatrix.set(viewToGlobalMatrix); this.mTempMatrix.postTranslate(-screenBounds.left, -screenBounds.top); this.mTempMatrix.postScale(scale, scale); bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.concat(this.mTempMatrix); sharedElement.draw(canvas); } return bitmap; }