Search in sources :

Example 81 with Matrix

use of android.graphics.Matrix in project fresco by facebook.

the class MainActivity method loadTranslatedBitmap.

public void loadTranslatedBitmap(int x, int y, int width, int height, int tx, int ty) {
    Matrix matrix = getMatrix(tx, ty, 1, 1, 0);
    CloseableReference<Bitmap> bitmapRef = mBitmapFactory.createBitmap(mOriginalBitmap, x, y, width, height, matrix, true);
    setImageBitmap(bitmapRef);
    checkValid(bitmapRef, Bitmap.createBitmap(mOriginalBitmap, x, y, width, height, matrix, true));
}
Also used : Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix)

Example 82 with Matrix

use of android.graphics.Matrix in project cardslib by gabrielemariotti.

the class RoundCornersDrawable method onBoundsChange.

@Override
protected void onBoundsChange(Rect bounds) {
    super.onBoundsChange(bounds);
    mRect.set(mMargin, mMargin, bounds.width() - mMargin, bounds.height() - mMargin);
    mRectBottomR.set((bounds.width() - mMargin) / 2, (bounds.height() - mMargin) / 2, bounds.width() - mMargin, bounds.height() - mMargin);
    mRectBottomL.set(0, (bounds.height() - mMargin) / 2, (bounds.width() - mMargin) / 2, bounds.height() - mMargin);
    if (USE_VIGNETTE) {
        RadialGradient vignette = new RadialGradient(mRect.centerX(), mRect.centerY() * 1.0f / 0.7f, mRect.centerX() * 1.3f, new int[] { 0, 0, 0x7f000000 }, new float[] { 0.0f, 0.7f, 1.0f }, Shader.TileMode.CLAMP);
        Matrix oval = new Matrix();
        oval.setScale(1.0f, 0.7f);
        vignette.setLocalMatrix(oval);
        mPaint.setShader(new ComposeShader(mBitmapShader, vignette, PorterDuff.Mode.SRC_OVER));
    }
}
Also used : ComposeShader(android.graphics.ComposeShader) Matrix(android.graphics.Matrix) RadialGradient(android.graphics.RadialGradient)

Example 83 with Matrix

use of android.graphics.Matrix in project cardslib by gabrielemariotti.

the class RoundCornersDrawable method onBoundsChange.

@Override
protected void onBoundsChange(Rect bounds) {
    super.onBoundsChange(bounds);
    mRect.set(mMargin, mMargin, bounds.width() - mMargin, bounds.height() - mMargin);
    if (USE_VIGNETTE) {
        RadialGradient vignette = new RadialGradient(mRect.centerX(), mRect.centerY() * 1.0f / 0.7f, mRect.centerX() * 1.3f, new int[] { 0, 0, 0x7f000000 }, new float[] { 0.0f, 0.7f, 1.0f }, Shader.TileMode.CLAMP);
        Matrix oval = new Matrix();
        oval.setScale(1.0f, 0.7f);
        vignette.setLocalMatrix(oval);
        mPaint.setShader(new ComposeShader(mBitmapShader, vignette, PorterDuff.Mode.SRC_OVER));
    }
}
Also used : ComposeShader(android.graphics.ComposeShader) Matrix(android.graphics.Matrix) RadialGradient(android.graphics.RadialGradient)

Example 84 with Matrix

use of android.graphics.Matrix in project AndroidSDK-RecipeBook by gabu.

the class Recipe048 method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LinearLayout linearLayout = new LinearLayout(this);
    // 元画像をリソースから読み込む
    Bitmap src = BitmapFactory.decodeResource(getResources(), R.drawable.src);
    // 元画像のwidth
    int srcWidth = src.getWidth();
    // 元画像のheight
    int srcHeight = src.getHeight();
    // リサイズしたい新しい画像のサイズ
    Matrix matrix = new Matrix();
    // リサイズ後のwidth
    float dstWidth = 50;
    // リサイズ後のheight
    float dstHeight = 50;
    // Scaleなので、新しいサイズ / 元のサイズ の値を設定する
    matrix.postScale(dstWidth / srcWidth, dstHeight / srcHeight);
    // 切り取り!
    Bitmap dst = // 元画像
    Bitmap.createBitmap(// 元画像
    src, // 開始X座標
    20, // 開始Y座標
    20, // 切り取るwidth
    100, // 切り取るheight
    100);
    ImageView imageView01 = new ImageView(this);
    imageView01.setImageBitmap(src);
    ImageView imageView02 = new ImageView(this);
    imageView02.setImageBitmap(dst);
    linearLayout.addView(imageView01);
    linearLayout.addView(imageView02);
    setContentView(linearLayout);
}
Also used : Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 85 with Matrix

use of android.graphics.Matrix in project fresco by facebook.

the class ScaleTypeDrawableTest method testConfigureBounds_FOCUS_CROP_HL.

/**
   * Underlying drawable's aspect ratio is bigger than view's, so it has to be slided horizontally
   * after scaling. Focus point is too much left, so it cannot be completely centered. Left-most
   * part of the image is displayed.
   */
@Test
public void testConfigureBounds_FOCUS_CROP_HL() {
    Rect bounds = new Rect(10, 10, 410, 310);
    int width = 400;
    int height = 200;
    PointF focusPoint = new PointF(0.1f, 0.5f);
    Matrix expectedMatrix = new Matrix();
    expectedMatrix.setScale(1.5f, 1.5f);
    expectedMatrix.postTranslate(10, 10);
    testConfigureBounds(bounds, width, height, ScaleType.FOCUS_CROP, focusPoint, expectedMatrix);
}
Also used : Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) PointF(android.graphics.PointF) Test(org.junit.Test)

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