android.widget.ImageView.ScaleType#CENTER_INSIDE源码实例Demo

下面列出了android.widget.ImageView.ScaleType#CENTER_INSIDE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: volley   文件: ImageRequest.java
/**
 * For API compatibility with the pre-ScaleType variant of the constructor. Equivalent to the
 * normal constructor with {@code ScaleType.CENTER_INSIDE}.
 */
@Deprecated
public ImageRequest(
        String url,
        Response.Listener<Bitmap> listener,
        int maxWidth,
        int maxHeight,
        Config decodeConfig,
        Response.ErrorListener errorListener) {
    this(
            url,
            listener,
            maxWidth,
            maxHeight,
            ScaleType.CENTER_INSIDE,
            decodeConfig,
            errorListener);
}
 
源代码2 项目: GravityBox   文件: ModNavigationBar.java
private static ScaleType getIconScaleType(int index, int keyId) {
    if (mUseLargerIcons) {
        return ScaleType.FIT_CENTER;
    } else {
        ScaleType origScaleType = mNavbarViewInfo[index] == null ? ScaleType.CENTER :
                mNavbarViewInfo[index].originalScaleType.get(keyId, ScaleType.CENTER);
        if (index == 0) {
            return (mNavbarHeight < 75 ? ScaleType.CENTER_INSIDE : origScaleType);
        } else {
            boolean hasVerticalNavbar = mGbContext.getResources().getBoolean(R.bool.hasVerticalNavbar);
            return (mNavbarWidth < 75 && hasVerticalNavbar ? ScaleType.CENTER_INSIDE :
                    origScaleType);
        }
    }
}
 
源代码3 项目: pearl   文件: ImageRequest.java
/**
 * For API compatibility with the pre-ScaleType variant of the constructor. Equivalent to
 * the normal constructor with {@code ScaleType.CENTER_INSIDE}.
 */
@Deprecated
public ImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight,
        Config decodeConfig, Response.ErrorListener errorListener) {
    this(url, listener, maxWidth, maxHeight,
            ScaleType.CENTER_INSIDE, decodeConfig, errorListener);
}
 
源代码4 项目: AndroidProjects   文件: ImageRequest.java
/**
 * For API compatibility with the pre-ScaleType variant of the constructor. Equivalent to
 * the normal constructor with {@code ScaleType.CENTER_INSIDE}.
 */
@Deprecated
public ImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight,
        Config decodeConfig, Response.ErrorListener errorListener) {
    this(url, listener, maxWidth, maxHeight,
            ScaleType.CENTER_INSIDE, decodeConfig, errorListener);
}
 
源代码5 项目: CrossBow   文件: ImageRequest.java
/**
 * For API compatibility with the pre-ScaleType variant of the constructor. Equivalent to
 * the normal constructor with {@code ScaleType.CENTER_INSIDE}.
 */
@Deprecated
public ImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight,
        Config decodeConfig, Response.ErrorListener errorListener) {
    this(url, listener, maxWidth, maxHeight,
            ScaleType.CENTER_INSIDE, decodeConfig, errorListener);
}
 
源代码6 项目: react-native-image-zoom   文件: ViewManager.java
@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);
}
 
源代码7 项目: SimplifyReader   文件: ImageRequest.java
/**
 * For API compatibility with the pre-ScaleType variant of the constructor. Equivalent to
 * the normal constructor with {@code ScaleType.CENTER_INSIDE}.
 */
@Deprecated
public ImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight,
        Config decodeConfig, Response.ErrorListener errorListener) {
    this(url, listener, maxWidth, maxHeight,
            ScaleType.CENTER_INSIDE, decodeConfig, errorListener);
}
 
源代码8 项目: TitanjumNote   文件: ImageRequest.java
/**
 * For API compatibility with the pre-ScaleType variant of the constructor. Equivalent to
 * the normal constructor with {@code ScaleType.CENTER_INSIDE}.
 */
@Deprecated
public ImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight,
        Config decodeConfig, Response.ErrorListener errorListener) {
    this(url, listener, maxWidth, maxHeight,
            ScaleType.CENTER_INSIDE, decodeConfig, errorListener);
}
 
源代码9 项目: product-emm   文件: ImageRequest.java
/**
 * For API compatibility with the pre-ScaleType variant of the constructor. Equivalent to
 * the normal constructor with {@code ScaleType.CENTER_INSIDE}.
 */
@Deprecated
public ImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight,
        Config decodeConfig, Response.ErrorListener errorListener) {
    this(url, listener, maxWidth, maxHeight,
            ScaleType.CENTER_INSIDE, decodeConfig, errorListener);
}
 
源代码10 项目: product-emm   文件: ImageRequest.java
/**
 * For API compatibility with the pre-ScaleType variant of the constructor. Equivalent to
 * the normal constructor with {@code ScaleType.CENTER_INSIDE}.
 */
@Deprecated
public ImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight,
        Config decodeConfig, Response.ErrorListener errorListener) {
    this(url, listener, maxWidth, maxHeight,
            ScaleType.CENTER_INSIDE, decodeConfig, errorListener);
}
 
源代码11 项目: DaVinci   文件: ImageRequest.java
/**
 * For API compatibility with the pre-ScaleType variant of the constructor. Equivalent to
 * the normal constructor with {@code ScaleType.CENTER_INSIDE}.
 */
@Deprecated
public ImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight,
                    Config decodeConfig, Response.ErrorListener errorListener) {
    this(url, listener, maxWidth, maxHeight,
            ScaleType.CENTER_INSIDE, decodeConfig, errorListener);
}
 
源代码12 项目: volley   文件: ImageRequestTest.java
@Test
public void parseNetworkResponse_resizing() throws Exception {
    // This is a horrible hack but Robolectric doesn't have a way to provide
    // width and height hints for decodeByteArray. It works because the byte array
    // "file:fake" is ASCII encodable and thus the name in Robolectric's fake
    // bitmap creator survives as-is, and provideWidthAndHeightHints puts
    // "file:" + name in its lookaside map. I write all this because it will
    // probably break mysteriously at some point and I feel terrible about your
    // having to debug it.
    byte[] jpegBytes = "file:fake".getBytes(StandardCharsets.UTF_8);
    ShadowBitmapFactory.provideWidthAndHeightHints("fake", 1024, 500);
    NetworkResponse jpeg = new NetworkResponse(jpegBytes);

    // Scale the image uniformly (maintain the image's aspect ratio) so that
    // both dimensions (width and height) of the image will be equal to or
    // less than the corresponding dimension of the view.
    ScaleType scalteType = ScaleType.CENTER_INSIDE;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250); // exactly half
    verifyResize(jpeg, 511, 249, scalteType, 509, 249); // just under half
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500); // larger
    verifyResize(jpeg, 500, 500, scalteType, 500, 244); // keep same ratio

    // Specify only width, preserve aspect ratio
    verifyResize(jpeg, 512, 0, scalteType, 512, 250);
    verifyResize(jpeg, 800, 0, scalteType, 800, 390);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height, preserve aspect ratio
    verifyResize(jpeg, 0, 250, scalteType, 512, 250);
    verifyResize(jpeg, 0, 391, scalteType, 800, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);

    // Scale the image uniformly (maintain the image's aspect ratio) so that
    // both dimensions (width and height) of the image will be equal to or
    // larger than the corresponding dimension of the view.
    scalteType = ScaleType.CENTER_CROP;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250);
    verifyResize(jpeg, 511, 249, scalteType, 511, 249);
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500);
    verifyResize(jpeg, 500, 500, scalteType, 1024, 500);

    // Specify only width
    verifyResize(jpeg, 512, 0, scalteType, 512, 250);
    verifyResize(jpeg, 800, 0, scalteType, 800, 390);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height
    verifyResize(jpeg, 0, 250, scalteType, 512, 250);
    verifyResize(jpeg, 0, 391, scalteType, 800, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);

    // Scale in X and Y independently, so that src matches dst exactly. This
    // may change the aspect ratio of the src.
    scalteType = ScaleType.FIT_XY;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250);
    verifyResize(jpeg, 511, 249, scalteType, 511, 249);
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500);
    verifyResize(jpeg, 500, 500, scalteType, 500, 500);

    // Specify only width
    verifyResize(jpeg, 512, 0, scalteType, 512, 500);
    verifyResize(jpeg, 800, 0, scalteType, 800, 500);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height
    verifyResize(jpeg, 0, 250, scalteType, 1024, 250);
    verifyResize(jpeg, 0, 391, scalteType, 1024, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);
}
 
源代码13 项目: sketch   文件: AdaptiveTwoLevelScales.java
@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};
}
 
源代码14 项目: SaveVolley   文件: ImageRequest.java
/**
 * For API compatibility with the pre-ScaleType variant of the constructor. Equivalent to
 * the normal constructor with {@code ScaleType.CENTER_INSIDE}.
 */
@Deprecated
public ImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight, Config decodeConfig, Response.ErrorListener errorListener) {
    this(url, listener, maxWidth, maxHeight, ScaleType.CENTER_INSIDE, decodeConfig,
            errorListener);
}
 
源代码15 项目: SaveVolley   文件: ImageRequest.java
/**
 * For API compatibility with the pre-ScaleType variant of the constructor. Equivalent to
 * the normal constructor with {@code ScaleType.CENTER_INSIDE}.
 */
@Deprecated
public ImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight, Config decodeConfig, Response.ErrorListener errorListener) {
    this(url, listener, maxWidth, maxHeight, ScaleType.CENTER_INSIDE, decodeConfig,
            errorListener);
}
 
源代码16 项目: CrossBow   文件: ImageRequestTest.java
@Test public void parseNetworkResponse_resizing() throws Exception {
    // This is a horrible hack but Robolectric doesn't have a way to provide
    // width and height hints for decodeByteArray. It works because the byte array
    // "file:fake" is ASCII encodable and thus the name in Robolectric's fake
    // bitmap creator survives as-is, and provideWidthAndHeightHints puts
    // "file:" + name in its lookaside map. I write all this because it will
    // probably break mysteriously at some point and I feel terrible about your
    // having to debug it.
    byte[] jpegBytes = "file:fake".getBytes();
    ShadowBitmapFactory.provideWidthAndHeightHints("fake", 1024, 500);
    NetworkResponse jpeg = new NetworkResponse(jpegBytes);

    // Scale the image uniformly (maintain the image's aspect ratio) so that
    // both dimensions (width and height) of the image will be equal to or
    // less than the corresponding dimension of the view.
    ScaleType scalteType = ScaleType.CENTER_INSIDE;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250); // exactly half
    verifyResize(jpeg, 511, 249, scalteType, 509, 249); // just under half
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500); // larger
    verifyResize(jpeg, 500, 500, scalteType, 500, 244); // keep same ratio

    // Specify only width, preserve aspect ratio
    verifyResize(jpeg, 512, 0, scalteType, 512, 250);
    verifyResize(jpeg, 800, 0, scalteType, 800, 390);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height, preserve aspect ratio
    verifyResize(jpeg, 0, 250, scalteType, 512, 250);
    verifyResize(jpeg, 0, 391, scalteType, 800, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);


    // Scale the image uniformly (maintain the image's aspect ratio) so that
    // both dimensions (width and height) of the image will be equal to or
    // larger than the corresponding dimension of the view.
    scalteType = ScaleType.CENTER_CROP;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250);
    verifyResize(jpeg, 511, 249, scalteType, 511, 249);
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500);
    verifyResize(jpeg, 500, 500, scalteType, 1024, 500);

    // Specify only width
    verifyResize(jpeg, 512, 0, scalteType, 512, 250);
    verifyResize(jpeg, 800, 0, scalteType, 800, 390);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height
    verifyResize(jpeg, 0, 250, scalteType, 512, 250);
    verifyResize(jpeg, 0, 391, scalteType, 800, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);


    // Scale in X and Y independently, so that src matches dst exactly. This
    // may change the aspect ratio of the src.
    scalteType = ScaleType.FIT_XY;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250);
    verifyResize(jpeg, 511, 249, scalteType, 511, 249);
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500);
    verifyResize(jpeg, 500, 500, scalteType, 500, 500);

    // Specify only width
    verifyResize(jpeg, 512, 0, scalteType, 512, 500);
    verifyResize(jpeg, 800, 0, scalteType, 800, 500);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height
    verifyResize(jpeg, 0, 250, scalteType, 1024, 250);
    verifyResize(jpeg, 0, 391, scalteType, 1024, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);
}
 
源代码17 项目: SaveVolley   文件: ImageRequestTest.java
@Test public void parseNetworkResponse_resizing() throws Exception {
    // This is a horrible hack but Robolectric doesn't have a way to provide
    // width and height hints for decodeByteArray. It works because the byte array
    // "file:fake" is ASCII encodable and thus the name in Robolectric's fake
    // bitmap creator survives as-is, and provideWidthAndHeightHints puts
    // "file:" + name in its lookaside map. I write all this because it will
    // probably break mysteriously at some point and I feel terrible about your
    // having to debug it.
    byte[] jpegBytes = "file:fake".getBytes();
    ShadowBitmapFactory.provideWidthAndHeightHints("fake", 1024, 500);
    NetworkResponse jpeg = new NetworkResponse(jpegBytes);

    // Scale the image uniformly (maintain the image's aspect ratio) so that
    // both dimensions (width and height) of the image will be equal to or
    // less than the corresponding dimension of the view.
    ScaleType scalteType = ScaleType.CENTER_INSIDE;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250); // exactly half
    verifyResize(jpeg, 511, 249, scalteType, 509, 249); // just under half
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500); // larger
    verifyResize(jpeg, 500, 500, scalteType, 500, 244); // keep same ratio

    // Specify only width, preserve aspect ratio
    verifyResize(jpeg, 512, 0, scalteType, 512, 250);
    verifyResize(jpeg, 800, 0, scalteType, 800, 390);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height, preserve aspect ratio
    verifyResize(jpeg, 0, 250, scalteType, 512, 250);
    verifyResize(jpeg, 0, 391, scalteType, 800, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);

    // Scale the image uniformly (maintain the image's aspect ratio) so that
    // both dimensions (width and height) of the image will be equal to or
    // larger than the corresponding dimension of the view.
    scalteType = ScaleType.CENTER_CROP;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250);
    verifyResize(jpeg, 511, 249, scalteType, 511, 249);
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500);
    verifyResize(jpeg, 500, 500, scalteType, 1024, 500);

    // Specify only width
    verifyResize(jpeg, 512, 0, scalteType, 512, 250);
    verifyResize(jpeg, 800, 0, scalteType, 800, 390);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height
    verifyResize(jpeg, 0, 250, scalteType, 512, 250);
    verifyResize(jpeg, 0, 391, scalteType, 800, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);

    // Scale in X and Y independently, so that src matches dst exactly. This
    // may change the aspect ratio of the src.
    scalteType = ScaleType.FIT_XY;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250);
    verifyResize(jpeg, 511, 249, scalteType, 511, 249);
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500);
    verifyResize(jpeg, 500, 500, scalteType, 500, 500);

    // Specify only width
    verifyResize(jpeg, 512, 0, scalteType, 512, 500);
    verifyResize(jpeg, 800, 0, scalteType, 800, 500);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height
    verifyResize(jpeg, 0, 250, scalteType, 1024, 250);
    verifyResize(jpeg, 0, 391, scalteType, 1024, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);
}
 
源代码18 项目: product-emm   文件: ImageRequestTest.java
@Test public void parseNetworkResponse_resizing() throws Exception {
    // This is a horrible hack but Robolectric doesn't have a way to provide
    // width and height hints for decodeByteArray. It works because the byte array
    // "file:fake" is ASCII encodable and thus the name in Robolectric's fake
    // bitmap creator survives as-is, and provideWidthAndHeightHints puts
    // "file:" + name in its lookaside map. I write all this because it will
    // probably break mysteriously at some point and I feel terrible about your
    // having to debug it.
    byte[] jpegBytes = "file:fake".getBytes();
    ShadowBitmapFactory.provideWidthAndHeightHints("fake", 1024, 500);
    NetworkResponse jpeg = new NetworkResponse(jpegBytes);

    // Scale the image uniformly (maintain the image's aspect ratio) so that
    // both dimensions (width and height) of the image will be equal to or
    // less than the corresponding dimension of the view.
    ScaleType scalteType = ScaleType.CENTER_INSIDE;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250); // exactly half
    verifyResize(jpeg, 511, 249, scalteType, 509, 249); // just under half
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500); // larger
    verifyResize(jpeg, 500, 500, scalteType, 500, 244); // keep same ratio

    // Specify only width, preserve aspect ratio
    verifyResize(jpeg, 512, 0, scalteType, 512, 250);
    verifyResize(jpeg, 800, 0, scalteType, 800, 390);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height, preserve aspect ratio
    verifyResize(jpeg, 0, 250, scalteType, 512, 250);
    verifyResize(jpeg, 0, 391, scalteType, 800, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);


    // Scale the image uniformly (maintain the image's aspect ratio) so that
    // both dimensions (width and height) of the image will be equal to or
    // larger than the corresponding dimension of the view.
    scalteType = ScaleType.CENTER_CROP;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250);
    verifyResize(jpeg, 511, 249, scalteType, 511, 249);
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500);
    verifyResize(jpeg, 500, 500, scalteType, 1024, 500);

    // Specify only width
    verifyResize(jpeg, 512, 0, scalteType, 512, 250);
    verifyResize(jpeg, 800, 0, scalteType, 800, 390);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height
    verifyResize(jpeg, 0, 250, scalteType, 512, 250);
    verifyResize(jpeg, 0, 391, scalteType, 800, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);


    // Scale in X and Y independently, so that src matches dst exactly. This
    // may change the aspect ratio of the src.
    scalteType = ScaleType.FIT_XY;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250);
    verifyResize(jpeg, 511, 249, scalteType, 511, 249);
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500);
    verifyResize(jpeg, 500, 500, scalteType, 500, 500);

    // Specify only width
    verifyResize(jpeg, 512, 0, scalteType, 512, 500);
    verifyResize(jpeg, 800, 0, scalteType, 800, 500);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height
    verifyResize(jpeg, 0, 250, scalteType, 1024, 250);
    verifyResize(jpeg, 0, 391, scalteType, 1024, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);
}
 
源代码19 项目: product-emm   文件: ImageRequestTest.java
@Test public void parseNetworkResponse_resizing() throws Exception {
    // This is a horrible hack but Robolectric doesn't have a way to provide
    // width and height hints for decodeByteArray. It works because the byte array
    // "file:fake" is ASCII encodable and thus the name in Robolectric's fake
    // bitmap creator survives as-is, and provideWidthAndHeightHints puts
    // "file:" + name in its lookaside map. I write all this because it will
    // probably break mysteriously at some point and I feel terrible about your
    // having to debug it.
    byte[] jpegBytes = "file:fake".getBytes();
    ShadowBitmapFactory.provideWidthAndHeightHints("fake", 1024, 500);
    NetworkResponse jpeg = new NetworkResponse(jpegBytes);

    // Scale the image uniformly (maintain the image's aspect ratio) so that
    // both dimensions (width and height) of the image will be equal to or
    // less than the corresponding dimension of the view.
    ScaleType scalteType = ScaleType.CENTER_INSIDE;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250); // exactly half
    verifyResize(jpeg, 511, 249, scalteType, 509, 249); // just under half
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500); // larger
    verifyResize(jpeg, 500, 500, scalteType, 500, 244); // keep same ratio

    // Specify only width, preserve aspect ratio
    verifyResize(jpeg, 512, 0, scalteType, 512, 250);
    verifyResize(jpeg, 800, 0, scalteType, 800, 390);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height, preserve aspect ratio
    verifyResize(jpeg, 0, 250, scalteType, 512, 250);
    verifyResize(jpeg, 0, 391, scalteType, 800, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);


    // Scale the image uniformly (maintain the image's aspect ratio) so that
    // both dimensions (width and height) of the image will be equal to or
    // larger than the corresponding dimension of the view.
    scalteType = ScaleType.CENTER_CROP;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250);
    verifyResize(jpeg, 511, 249, scalteType, 511, 249);
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500);
    verifyResize(jpeg, 500, 500, scalteType, 1024, 500);

    // Specify only width
    verifyResize(jpeg, 512, 0, scalteType, 512, 250);
    verifyResize(jpeg, 800, 0, scalteType, 800, 390);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height
    verifyResize(jpeg, 0, 250, scalteType, 512, 250);
    verifyResize(jpeg, 0, 391, scalteType, 800, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);


    // Scale in X and Y independently, so that src matches dst exactly. This
    // may change the aspect ratio of the src.
    scalteType = ScaleType.FIT_XY;

    // Exact sizes
    verifyResize(jpeg, 512, 250, scalteType, 512, 250);
    verifyResize(jpeg, 511, 249, scalteType, 511, 249);
    verifyResize(jpeg, 1080, 500, scalteType, 1024, 500);
    verifyResize(jpeg, 500, 500, scalteType, 500, 500);

    // Specify only width
    verifyResize(jpeg, 512, 0, scalteType, 512, 500);
    verifyResize(jpeg, 800, 0, scalteType, 800, 500);
    verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);

    // Specify only height
    verifyResize(jpeg, 0, 250, scalteType, 1024, 250);
    verifyResize(jpeg, 0, 391, scalteType, 1024, 391);
    verifyResize(jpeg, 0, 500, scalteType, 1024, 500);

    // No resize
    verifyResize(jpeg, 0, 0, scalteType, 1024, 500);
}
 
源代码20 项目: sketch   文件: ScaleDragHelper.java
@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);
    }
}