org.robolectric.shadows.ShadowBitmapFactory Java Examples
The following examples show how to use
org.robolectric.shadows.ShadowBitmapFactory.
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: Test4ImageActivity.java From AndroidGodEye with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout contentView = new LinearLayout(this); ImageView imageView0 = new ImageView(this); imageView0.setImageBitmap(ShadowBitmapFactory.create("AndroidGodEye-Bitmap", null, new Point(200, 100))); ImageView imageView1 = new ImageView(this); imageView1.setImageBitmap(ShadowBitmapFactory.create("AndroidGodEye-Bitmap", null, new Point(200, 100))); ImageView imageView2 = new ImageView(this); imageView2.setImageBitmap(ShadowBitmapFactory.create("AndroidGodEye-Bitmap", null, new Point(200, 100))); imageView3 = new ImageView(this); imageView3.setImageBitmap(ShadowBitmapFactory.create("AndroidGodEye-Bitmap", null, new Point(200, 100))); contentView.addView(imageView0); contentView.addView(imageView1); contentView.addView(imageView2); contentView.addView(imageView3); setContentView(contentView); imageView0.measure(50, 50); imageView0.layout(0, 0, 50, 50); imageView1.measure(500, 500); imageView1.layout(0, 0, 500, 500); imageView2.measure(210, 95); imageView2.layout(0, 0, 210, 95); imageView3.measure(50, 50); imageView3.layout(0, 0, 50, 50); }
Example #2
Source File: PictureResizeDialogTest.java From Onosendai with Apache License 2.0 | 6 votes |
@Test public void itGeneratesLivePreview () throws Exception { this.alert.show(); this.dlg.updateSummary(); final TextView txtSummary = (TextView) this.shadowAlert.getView().findViewById(R.id.txtSummary); ShadowBitmapFactory.provideWidthAndHeightHints(this.attachment, 72, 72); // Note above does not actually have any effect, // since dimensions are read via BitmapFactory.decodeFileDescriptor(). // 100x100 is ShadowBitmapFactory's default. final String expectedStatus = "100 x 100 (3.4 KB) --> 36 x 36 (69 B)"; int n = 0; while (true) { if (expectedStatus.equals(txtSummary.getText().toString())) break; if (n > 5) fail("Expected '" + txtSummary.getText() + "' to be '" + expectedStatus + "' after " + n + " seconds."); n++; Thread.sleep(1000L); } // TODO assert img in UI is set. }
Example #3
Source File: ImageUtilTest.java From AndroidGodEye with Apache License 2.0 | 5 votes |
@Test public void convertToBase64() { String base642 = ImageUtil.convertToBase64(null, 5, 5); Assert.assertNull(base642); Bitmap bitmap = ShadowBitmapFactory.create("AndroidGodEye-Image", null, new Point(10, 10)); String base64 = ImageUtil.convertToBase64(bitmap, 5, 5); Assert.assertNotNull(base64); }
Example #4
Source File: ImageUtilTest.java From AndroidGodEye with Apache License 2.0 | 5 votes |
/** * width > target && height < target */ @Test public void computeTargetSizeWidth1Height0() { Bitmap bitmap = ShadowBitmapFactory.create("AndroidGodEye", null, new Point(100, 20)); int[] targetSize0 = ImageUtil.computeTargetSize(bitmap, 30, 30); Assert.assertEquals(30, targetSize0[0]); Assert.assertEquals(6, targetSize0[1]); }
Example #5
Source File: ImageUtilTest.java From AndroidGodEye with Apache License 2.0 | 5 votes |
/** * width > target && height > target */ @Test public void computeTargetSizeWidth1Height1() { Bitmap bitmap = ShadowBitmapFactory.create("AndroidGodEye", null, new Point(100, 50)); int[] targetSize0 = ImageUtil.computeTargetSize(bitmap, 30, 30); Assert.assertEquals(30, targetSize0[0]); Assert.assertEquals(15, targetSize0[1]); }
Example #6
Source File: ImageUtilTest.java From AndroidGodEye with Apache License 2.0 | 5 votes |
/** * width < target && height > target */ @Test public void computeTargetSizeWidth0Height1() { Bitmap bitmap = ShadowBitmapFactory.create("AndroidGodEye", null, new Point(25, 50)); int[] targetSize0 = ImageUtil.computeTargetSize(bitmap, 30, 30); Assert.assertEquals(15, targetSize0[0]); Assert.assertEquals(30, targetSize0[1]); }
Example #7
Source File: ImageUtilTest.java From AndroidGodEye with Apache License 2.0 | 5 votes |
/** * width < target && height < target */ @Test public void computeTargetSizeWidth0Height0() { Bitmap bitmap = ShadowBitmapFactory.create("AndroidGodEye", null, new Point(20, 10)); int[] targetSize0 = ImageUtil.computeTargetSize(bitmap, 30, 30); Assert.assertEquals(20, targetSize0[0]); Assert.assertEquals(10, targetSize0[1]); }
Example #8
Source File: BaseTransformationTest.java From picasso-transformations with Apache License 2.0 | 5 votes |
protected Bitmap getCopyOfBitmap() { if (sBitmap == null) { try { URL url = new URL(TULIP_IMG_URL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); sBitmap = ShadowBitmapFactory.decodeStream(input); } catch (IOException e) { } } return sBitmap.copy(Bitmap.Config.ARGB_8888, false); }
Example #9
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 #10
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 #11
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 #12
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 #13
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 #14
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); }