Search in sources :

Example 76 with Matrix

use of android.graphics.Matrix in project picasso by square.

the class BitmapHunterTest method exifVerticalFlip.

@Test
public void exifVerticalFlip() {
    Request data = new Request.Builder(URI_1).rotate(-45).build();
    Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
    Bitmap result = transformResult(data, source, ORIENTATION_FLIP_VERTICAL);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPostOperations()).containsOnly("scale -1.0 1.0");
    assertThat(shadowMatrix.getPreOperations()).containsOnly("rotate 180.0");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 77 with Matrix

use of android.graphics.Matrix in project picasso by square.

the class BitmapHunterTest method centerCropWithGravityHorizontalRight.

@Test
public void centerCropWithGravityHorizontalRight() {
    Bitmap source = Bitmap.createBitmap(20, 10, ARGB_8888);
    Request data = new Request.Builder(URI_1).resize(40, 40).centerCrop(Gravity.RIGHT).build();
    Bitmap result = transformResult(data, source, 0);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source);
    assertThat(shadowBitmap.getCreatedFromX()).isEqualTo(10);
    assertThat(shadowBitmap.getCreatedFromY()).isEqualTo(0);
    assertThat(shadowBitmap.getCreatedFromWidth()).isEqualTo(10);
    assertThat(shadowBitmap.getCreatedFromHeight()).isEqualTo(10);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).containsOnly("scale 4.0 4.0");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 78 with Matrix

use of android.graphics.Matrix in project picasso by square.

the class BitmapHunterTest method centerCropResultMatchesTargetSizeWhileDesiredHeightIs0.

@Test
public void centerCropResultMatchesTargetSizeWhileDesiredHeightIs0() {
    Request request = new Request.Builder(URI_1).resize(1080, 0).centerCrop().build();
    Bitmap source = Bitmap.createBitmap(640, 640, ARGB_8888);
    Bitmap result = transformResult(request, source, 0);
    ShadowBitmap shadowBitmap = shadowOf(result);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    String scalePreOperation = shadowMatrix.getPreOperations().get(0);
    assertThat(scalePreOperation).startsWith("scale ");
    float scaleX = Float.valueOf(scalePreOperation.split(" ")[1]);
    float scaleY = Float.valueOf(scalePreOperation.split(" ")[2]);
    int transformedWidth = Math.round(result.getWidth() * scaleX);
    int transformedHeight = Math.round(result.getHeight() * scaleY);
    assertThat(transformedWidth).isEqualTo(1080);
    assertThat(transformedHeight).isEqualTo(1080);
}
Also used : TestUtils.makeBitmap(com.squareup.picasso.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 79 with Matrix

use of android.graphics.Matrix in project picasso by square.

the class BitmapHunterTest method onlyScaleDownOriginalBiggerWidthIs0.

@Test
public void onlyScaleDownOriginalBiggerWidthIs0() {
    Bitmap source = Bitmap.createBitmap(50, 50, ARGB_8888);
    Request data = new Request.Builder(URI_1).resize(0, 40).onlyScaleDown().build();
    Bitmap result = transformResult(data, source, 0);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).containsOnly("scale 0.8 0.8");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 80 with Matrix

use of android.graphics.Matrix in project HTextView by hanks-zyh.

the class PixelateText method init.

public void init(HTextView hTextView, AttributeSet attrs, int defStyle) {
    mHTextView = hTextView;
    mText = "";
    mOldText = "";
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.BLACK);
    paint.setStyle(Paint.Style.FILL);
    paint.setTypeface(hTextView.getTypeface());
    oldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    oldPaint.setColor(Color.BLACK);
    oldPaint.setStyle(Paint.Style.FILL);
    oldPaint.setTypeface(hTextView.getTypeface());
    pixPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    pixPaint.setColor(Color.BLACK);
    pixPaint.setStyle(Paint.Style.FILL);
    metrics = new DisplayMetrics();
    WindowManager windowManger = (WindowManager) hTextView.getContext().getSystemService(Context.WINDOW_SERVICE);
    windowManger.getDefaultDisplay().getMetrics(metrics);
    textSize = hTextView.getTextSize();
    bitmap = Bitmap.createBitmap(700, 200, Bitmap.Config.ARGB_4444);
    matrix = new Matrix();
    pixCanvas = new Canvas(bitmap);
}
Also used : Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager)

Aggregations

Matrix (android.graphics.Matrix)970 Bitmap (android.graphics.Bitmap)254 Paint (android.graphics.Paint)201 RectF (android.graphics.RectF)155 Rect (android.graphics.Rect)99 Test (org.junit.Test)93 Canvas (android.graphics.Canvas)80 ImageView (android.widget.ImageView)67 View (android.view.View)65 Point (android.graphics.Point)52 Bundle (android.os.Bundle)45 GhostView (android.view.GhostView)40 ViewGroup (android.view.ViewGroup)39 ColorMatrix (android.graphics.ColorMatrix)38 Drawable (android.graphics.drawable.Drawable)38 IOException (java.io.IOException)38 BitmapHunter.forRequest (com.squareup.picasso.BitmapHunter.forRequest)36 TestUtils.makeBitmap (com.squareup.picasso.TestUtils.makeBitmap)36 ShadowBitmap (org.robolectric.shadows.ShadowBitmap)36 ShadowMatrix (org.robolectric.shadows.ShadowMatrix)36