Java Code Examples for android.widget.ImageView.ScaleType#FIT_XY
The following examples show how to use
android.widget.ImageView.ScaleType#FIT_XY .
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 ucar-weex-core with Apache License 2.0 | 6 votes |
private ScaleType getResizeMode(String resizeMode) { ScaleType scaleType = ScaleType.FIT_XY; if (TextUtils.isEmpty(resizeMode)) { return scaleType; } switch (resizeMode) { case "cover": scaleType = ScaleType.CENTER_CROP; break; case "contain": scaleType = ScaleType.FIT_CENTER; break; case "stretch": scaleType = ScaleType.FIT_XY; break; } return scaleType; }
Example 2
Source File: WXImage.java From weex-uikit with MIT License | 6 votes |
private ScaleType getResizeMode(String resizeMode) { ScaleType scaleType = ScaleType.FIT_XY; if (TextUtils.isEmpty(resizeMode)) { return scaleType; } switch (resizeMode) { case "cover": scaleType = ScaleType.CENTER_CROP; break; case "contain": scaleType = ScaleType.FIT_CENTER; break; case "stretch": scaleType = ScaleType.FIT_XY; break; } return scaleType; }
Example 3
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 4
Source File: ImageSpec.java From litho with Apache License 2.0 | 5 votes |
@OnBoundsDefined static void onBoundsDefined( ComponentContext c, ComponentLayout layout, @Prop(resType = ResType.DRAWABLE) Drawable drawable, @Prop(optional = true) ScaleType scaleType, Output<DrawableMatrix> drawableMatrix, Output<Integer> drawableWidth, Output<Integer> drawableHeight) { final int horizontalPadding = layout.getPaddingLeft() + layout.getPaddingRight(); final int verticalPadding = layout.getPaddingTop() + layout.getPaddingBottom(); if (ScaleType.FIT_XY == scaleType || drawable == null || drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { drawableMatrix.set(null); drawableWidth.set(layout.getWidth() - horizontalPadding); drawableHeight.set(layout.getHeight() - verticalPadding); } else { final DrawableMatrix matrix = DrawableMatrix.create( drawable, scaleType, layout.getWidth() - horizontalPadding, layout.getHeight() - verticalPadding); drawableMatrix.set(matrix); drawableWidth.set(drawable.getIntrinsicWidth()); drawableHeight.set(drawable.getIntrinsicHeight()); } }
Example 5
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 6
Source File: RoundedDrawable.java From ImageLetterIcon with Apache License 2.0 | 5 votes |
public RoundedDrawable setScaleType(ScaleType scaleType) { if (scaleType == null) { scaleType = ScaleType.FIT_XY; } if (mScaleType != scaleType) { mScaleType = scaleType; updateShaderMatrix(); } return this; }
Example 7
Source File: ImageRequestTest.java From volley with Apache License 2.0 | 4 votes |
@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); }
Example 8
Source File: ImageRequestTest.java From device-database with Apache License 2.0 | 4 votes |
@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); }
Example 9
Source File: ImageRequestTest.java From SaveVolley with Apache License 2.0 | 4 votes |
@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); }
Example 10
Source File: ImageRequestTest.java From product-emm with Apache License 2.0 | 4 votes |
@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); }
Example 11
Source File: ImageRequestTest.java From product-emm with Apache License 2.0 | 4 votes |
@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); }
Example 12
Source File: ImageRequestTest.java From CrossBow with Apache License 2.0 | 4 votes |
@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); }
Example 13
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 14
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 15
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; } }