Java Code Examples for android.graphics.Matrix#setSkew()

The following examples show how to use android.graphics.Matrix#setSkew() . 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: PwaWrapperSplashScreenStrategyTest.java    From android-browser-helper with Apache License 2.0 5 votes vote down vote up
@Test
public void setsParametersOnTwaBuilder() throws InterruptedException {
    int bgColor = 0x115599;
    ImageView.ScaleType scaleType = ImageView.ScaleType.MATRIX;
    Matrix matrix = new Matrix();
    matrix.setSkew(1, 2, 3, 4);
    int fadeOutDuration = 300;

    PwaWrapperSplashScreenStrategy strategy = new PwaWrapperSplashScreenStrategy(mActivity,
            R.drawable.splash, bgColor, scaleType, matrix, fadeOutDuration,
            FILE_PROVIDER_AUTHORITY);
    strategy.onActivityEnterAnimationComplete();
    initiateLaunch(strategy);

    TrustedWebActivityIntentBuilder builder = new TrustedWebActivityIntentBuilder(
            Uri.parse("https://test.com"));

    CountDownLatch latch = new CountDownLatch(1);
    strategy.configureTwaBuilder(builder, mSession, latch::countDown);
    assertTrue(latch.await(3, TimeUnit.SECONDS));

    Intent intent = builder.build(mSession);
    Bundle bundle = intent.getBundleExtra(EXTRA_SPLASH_SCREEN_PARAMS);

    assertEquals(bgColor, bundle.getInt(SplashScreenParamKey.BACKGROUND_COLOR));
    assertEquals(scaleType.ordinal(), bundle.getInt(SplashScreenParamKey.SCALE_TYPE));
    assertEquals(fadeOutDuration, bundle.getInt(SplashScreenParamKey.FADE_OUT_DURATION_MS));

    float[] matrixValues = new float[9];
    matrix.getValues(matrixValues);
    assertArrayEquals(matrixValues, bundle.getFloatArray(
            SplashScreenParamKey.IMAGE_TRANSFORMATION_MATRIX), 1e-3f);
}
 
Example 2
Source File: ImageUtils.java    From Android-utils with Apache License 2.0 5 votes vote down vote up
public static Bitmap skew(final Bitmap src,
                          final float kx,
                          final float ky,
                          final float px,
                          final float py,
                          final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Matrix matrix = new Matrix();
    matrix.setSkew(kx, ky, px, py);
    Bitmap ret = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 3
Source File: BitmapUtils.java    From FastAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 倾斜图片
 *
 * @param src     源图片
 * @param kx      倾斜因子 x
 * @param ky      倾斜因子 y
 * @param px      平移因子 x
 * @param py      平移因子 y
 * @param recycle 是否回收
 * @return 倾斜后的图片
 */
public static Bitmap skew(@NonNull Bitmap src,
                          float kx,
                          float ky,
                          float px,
                          float py,
                          boolean recycle) {
    Matrix matrix = new Matrix();
    matrix.setSkew(kx, ky, px, py);
    Bitmap ret = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 4
Source File: ImageUtils.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * Return the skewed bitmap.
 *
 * @param src     The source of bitmap.
 * @param kx      The skew factor of x.
 * @param ky      The skew factor of y.
 * @param px      The x coordinate of the pivot point.
 * @param py      The y coordinate of the pivot point.
 * @param recycle True to recycle the source of bitmap, false otherwise.
 * @return the skewed bitmap
 */
public static Bitmap skew(final Bitmap src,
                          final float kx,
                          final float ky,
                          final float px,
                          final float py,
                          final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Matrix matrix = new Matrix();
    matrix.setSkew(kx, ky, px, py);
    Bitmap ret = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
    if (recycle && !src.isRecycled() && ret != src) src.recycle();
    return ret;
}
 
Example 5
Source File: PwaWrapperSplashScreenStrategyTest.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
@Test
public void setsParametersOnTwaBuilder() throws InterruptedException {
    int bgColor = 0x115599;
    ImageView.ScaleType scaleType = ImageView.ScaleType.MATRIX;
    Matrix matrix = new Matrix();
    matrix.setSkew(1, 2, 3, 4);
    int fadeOutDuration = 300;

    PwaWrapperSplashScreenStrategy strategy = new PwaWrapperSplashScreenStrategy(mActivity,
            R.drawable.splash, bgColor, scaleType, matrix, fadeOutDuration,
            FILE_PROVIDER_AUTHORITY);
    strategy.onActivityEnterAnimationComplete();
    initiateLaunch(strategy);

    TrustedWebActivityIntentBuilder builder = new TrustedWebActivityIntentBuilder(
            Uri.parse("https://test.com"));

    CountDownLatch latch = new CountDownLatch(1);
    strategy.configureTwaBuilder(builder, mSession, latch::countDown);
    assertTrue(latch.await(3, TimeUnit.SECONDS));

    Intent intent = TestUtil.getBrowserActivityWhenLaunched(
            () -> mActivity.startActivity(builder.build(mSession))).getIntent();
    Bundle bundle = intent.getBundleExtra(EXTRA_SPLASH_SCREEN_PARAMS);

    assertEquals(bgColor, bundle.getInt(SplashScreenParamKey.BACKGROUND_COLOR));
    assertEquals(scaleType.ordinal(), bundle.getInt(SplashScreenParamKey.SCALE_TYPE));
    assertEquals(fadeOutDuration, bundle.getInt(SplashScreenParamKey.FADE_OUT_DURATION_MS));

    float[] matrixValues = new float[9];
    matrix.getValues(matrixValues);
    assertArrayEquals(matrixValues, bundle.getFloatArray(
            SplashScreenParamKey.IMAGE_TRANSFORMATION_MATRIX), 1e-3f);
}
 
Example 6
Source File: MatrixView.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	Bitmap targetBitmap = BitmapFactory.decodeResource(getResources(),
			R.drawable.ic_launcher);
	Matrix matrix = new Matrix();
	matrix.setRotate(50, targetBitmap.getWidth() / 2,
			targetBitmap.getHeight() / 2);
	matrix.setSkew(2, 2);
	canvas.drawBitmap(targetBitmap, matrix, new Paint());
	super.onDraw(canvas);
}
 
Example 7
Source File: BitmapUtils.java    From DevUtils with Apache License 2.0 3 votes vote down vote up
/**
 * 倾斜图片
 * <pre>
 *     倾斜因子 以小数点倾斜 如: 0.1 防止数值过大 Canvas: trying to draw too large
 * </pre>
 * @param bitmap 待操作源图片
 * @param kx     X 轴倾斜因子
 * @param ky     Y 轴倾斜因子
 * @param px     X 轴轴心点
 * @param py     Y 轴轴心点
 * @return 倾斜后的图片
 */
public static Bitmap skew(final Bitmap bitmap, final float kx, final float ky, final float px, final float py) {
    if (isEmpty(bitmap)) return null;
    Matrix matrix = new Matrix();
    matrix.setSkew(kx, ky, px, py);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
 
Example 8
Source File: ImageUtils.java    From Android-UtilCode with Apache License 2.0 3 votes vote down vote up
/**
 * 倾斜图片
 *
 * @param src     源图片
 * @param kx      倾斜因子x
 * @param ky      倾斜因子y
 * @param px      平移因子x
 * @param py      平移因子y
 * @param recycle 是否回收
 * @return 倾斜后的图片
 */
public static Bitmap skew(Bitmap src, float kx, float ky, float px, float py, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Matrix matrix = new Matrix();
    matrix.setSkew(kx, ky, px, py);
    Bitmap ret = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 9
Source File: RxImageTool.java    From RxTools-master with Apache License 2.0 3 votes vote down vote up
/**
 * 倾斜图片
 *
 * @param src     源图片
 * @param kx      倾斜因子x
 * @param ky      倾斜因子y
 * @param px      平移因子x
 * @param py      平移因子y
 * @param recycle 是否回收
 * @return 倾斜后的图片
 */
public static Bitmap skew(Bitmap src, float kx, float ky, float px, float py, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Matrix matrix = new Matrix();
    matrix.setSkew(kx, ky, px, py);
    Bitmap ret = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}