当前位置: 首页>>代码示例>>Java>>正文


Java Matrix.setScale方法代码示例

本文整理汇总了Java中android.graphics.Matrix.setScale方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.setScale方法的具体用法?Java Matrix.setScale怎么用?Java Matrix.setScale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Matrix的用法示例。


在下文中一共展示了Matrix.setScale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTransformImpl

import android.graphics.Matrix; //导入方法依赖的package包/类
@Override
public void getTransformImpl(
    Matrix outTransform,
    Rect parentRect,
    int childWidth,
    int childHeight,
    float focusX,
    float focusY,
    float scaleX,
    float scaleY) {
  float scale, dx, dy;
  if (scaleY > scaleX) {
    scale = scaleY;
    dx = parentRect.width() * 0.5f - childWidth * scale * focusX;
    dx = parentRect.left + Math.max(Math.min(dx, 0), parentRect.width() - childWidth * scale);
    dy = parentRect.top;
  } else {
    scale = scaleX;
    dx = parentRect.left;
    dy = parentRect.height() * 0.5f - childHeight * scale * focusY;
    dy = parentRect.top + Math.max(Math.min(dy, 0), parentRect.height() - childHeight * scale);
  }
  outTransform.setScale(scale, scale);
  outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:ScalingUtils.java

示例2: updateShader

import android.graphics.Matrix; //导入方法依赖的package包/类
private void updateShader() {
    if (image == null)
        return;

    // Crop Center Image
    image = cropBitmap(image);

    // Create Shader
    BitmapShader shader = new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

    // Center Image in Shader
    Matrix matrix = new Matrix();
    matrix.setScale((float) canvasSize / (float) image.getWidth(), (float) canvasSize / (float) image.getHeight());
    shader.setLocalMatrix(matrix);

    // Set Shader in Paint
    paint.setShader(shader);
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:19,代码来源:CircularImageView.java

示例3: scaleBitmap

import android.graphics.Matrix; //导入方法依赖的package包/类
public static Bitmap scaleBitmap(Bitmap bitmap, int newWidth, int newHeight) {
    Bitmap scaledBitmap = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888);

    float scaleX = newWidth / (float) bitmap.getWidth();
    float scaleY = newHeight / (float) bitmap.getHeight();
    float pivotX = 0;
    float pivotY = 0;

    Matrix scaleMatrix = new Matrix();
    scaleMatrix.setScale(scaleX, scaleY, pivotX, pivotY);

    Canvas canvas = new Canvas(scaledBitmap);
    canvas.setMatrix(scaleMatrix);
    canvas.drawBitmap(bitmap, 0, 0, new Paint(Paint.FILTER_BITMAP_FLAG));

    return scaledBitmap;
}
 
开发者ID:afiqiqmal,项目名称:MVP-Android,代码行数:18,代码来源:SubUtils.java

示例4: adjustmentMatrix

import android.graphics.Matrix; //导入方法依赖的package包/类
public void adjustmentMatrix(Canvas canvas,Rect rect,Paint paint) {

        //Old Style - Source:http://bytefish.de/blog/face_detection_with_android/
        Matrix matrix = new Matrix();
        Matrix matrix2 = new Matrix();
        Matrix matrix3 = new Matrix();
        canvas.save();
        matrix.postRotate(90);
        canvas.concat(matrix);
        matrix2.setScale(-0.96f,0.54f);
        canvas.concat(matrix2);
        matrix3.postTranslate(-1920 / 2f,-1920 / 2f );
        canvas.concat(matrix3);
        canvas.drawRoundRect(rect.left, rect.top, rect.right, rect.bottom, 20f,40f,paint);
        canvas.restore();



    }
 
开发者ID:MartinRGB,项目名称:android_camera_experiment,代码行数:20,代码来源:DetectionView.java

示例5: adjustView

import android.graphics.Matrix; //导入方法依赖的package包/类
private void adjustView(int width1, int height1, int width2, int height2) {
    final double r = (double) height2 / width2;
    int nw, nH;

    if (height1 > (int) (width1 * r)) {
        nw = width1;
        nH = (int) (width1 * r);
    } else {
        nw = (int) (height1 / r);
        nH = height1;
    }

    final int moveX = (width1 - nw) / 2;
    final int moveY = (height1 - nH) / 2;

    final Matrix textureMatrix = new Matrix();
    textureView.getTransform(textureMatrix);
    textureMatrix.setScale((float) nw / width1, (float) nH / height1);
    textureMatrix.postTranslate(moveX, moveY);
    textureView.setTransform(textureMatrix);
}
 
开发者ID:JakeSteam,项目名称:Vidsta,代码行数:22,代码来源:VidstaPlayer.java

示例6: setUpScaleType

import android.graphics.Matrix; //导入方法依赖的package包/类
private Matrix setUpScaleType(Bitmap bitmap, ImageView iv, float width, float height) {
    float scaleX = 1, scaleY = 1, dx = 0, dy = 0;
    Matrix shaderMatrix = new Matrix();
    if (bitmap == null) {
        return null;
    }
    shaderMatrix.set(null);
    if (iv.getScaleType() == ImageView.ScaleType.CENTER_CROP) {
        if (width != bitmap.getWidth()) {
            scaleX = width / bitmap.getWidth();
        }
        if (scaleX * bitmap.getHeight() < height) {
            scaleX = height / bitmap.getHeight();
        }
        dy = (height - bitmap.getHeight() * scaleX) * 0.5f;
        dx = (width - bitmap.getWidth() * scaleX) * 0.5f;
        shaderMatrix.setScale(scaleX, scaleX);
    } else {
        scaleX = width / bitmap.getWidth();
        scaleY = height / bitmap.getHeight();
        dy = (height - bitmap.getHeight() * scaleY) * 0.5f;
        dx = (width - bitmap.getWidth() * scaleX) * 0.5f;
        shaderMatrix.setScale(scaleX, scaleY);
    }
    shaderMatrix.postTranslate(dx + 0.5f, dy + 0.5f);
    return shaderMatrix;
}
 
开发者ID:akshay2211,项目名称:Oblique,代码行数:28,代码来源:ObliqueView.java

示例7: transform

import android.graphics.Matrix; //导入方法依赖的package包/类
public Bitmap transform(Bitmap bitmap, int width, int height){
	  // Scale down the sampled bitmap if it's still larger than the desired dimension.
    float scale = Math.min((float) width / bitmap.getWidth(),
            (float) height / bitmap.getHeight());
    scale = Math.max(scale, Math.min((float) height / bitmap.getWidth(),
            (float) width / bitmap.getHeight()));
    if (scale < 1) {
        Matrix m = new Matrix();
        m.setScale(scale, scale);
        Bitmap transformed = createBitmap(
                bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m);
        bitmap.recycle();
        return transformed;
    }
    return bitmap;
}
 
开发者ID:januslo,项目名称:react-native-sunmi-inner-printer,代码行数:17,代码来源:BitmapUtils.java

示例8: extractThumbnail

import android.graphics.Matrix; //导入方法依赖的package包/类
public static Bitmap extractThumbnail(Bitmap source, int width, int height,
                                      int options) {
    if (source == null) {
        return null;
    }
    float scale;
    if (source.getWidth() < source.getHeight()) {
        scale = width / (float) source.getWidth();
    } else {
        scale = height / (float) source.getHeight();
    }
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);
    return transform(matrix, source, width, height,
            OPTIONS_SCALE_UP | options);
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:17,代码来源:FeThumbUtils.java

示例9: cropBitmapObjectWithScale

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * Crop image bitmap from given bitmap using the given points in the original bitmap and the given rotation.<br>
 * if the rotation is not 0,90,180 or 270 degrees then we must first crop a larger area of the image that
 * contains the requires rectangle, rotate and then crop again a sub rectangle.
 *
 * @param scale how much to scale the cropped image part, use 0.5 to lower the image by half (OOM handling)
 */
private static Bitmap cropBitmapObjectWithScale(Bitmap bitmap, float[] points, int degreesRotated,
                                                boolean fixAspectRatio, int aspectRatioX, int aspectRatioY, float scale) {

    // get the rectangle in original image that contains the required cropped area (larger for non rectangular crop)
    Rect rect = getRectFromPoints(points, bitmap.getWidth(), bitmap.getHeight(), fixAspectRatio, aspectRatioX, aspectRatioY);

    // crop and rotate the cropped image in one operation
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);
    matrix.postRotate(degreesRotated, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
    Bitmap result = Bitmap.createBitmap(bitmap, rect.left, rect.top, rect.width(), rect.height(), matrix, true);

    if (result == bitmap) {
        // corner case when all bitmap is selected, no worth optimizing for it
        result = bitmap.copy(bitmap.getConfig(), false);
    }

    // rotating by 0, 90, 180 or 270 degrees doesn't require extra cropping
    if (degreesRotated % 90 != 0) {

        // extra crop because non rectangular crop cannot be done directly on the image without rotating first
        result = cropForRotatedImage(result, points, rect, degreesRotated, fixAspectRatio, aspectRatioX, aspectRatioY);
    }

    return result;
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:34,代码来源:BitmapUtils.java

示例10: centerCrop

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * A potentially expensive operation to crop the given Bitmap so that it fills the given
 * dimensions. This operation is significantly less expensive in terms of memory if a mutable
 * Bitmap with the given dimensions is passed in as well.
 *
 * @param pool     The BitmapPool to obtain a bitmap from.
 * @param inBitmap   The Bitmap to resize.
 * @param width    The width in pixels of the final Bitmap.
 * @param height   The height in pixels of the final Bitmap.
 * @return The resized Bitmap (will be recycled if recycled is not null).
 */
public static Bitmap centerCrop(@NonNull BitmapPool pool, @NonNull Bitmap inBitmap, int width,
    int height) {
  if (inBitmap.getWidth() == width && inBitmap.getHeight() == height) {
    return inBitmap;
  }
  // From ImageView/Bitmap.createScaledBitmap.
  final float scale;
  float dx = 0, dy = 0;
  Matrix m = new Matrix();
  if (inBitmap.getWidth() * height > width * inBitmap.getHeight()) {
    scale = (float) height / (float) inBitmap.getHeight();
    dx = (width - inBitmap.getWidth() * scale) * 0.5f;
  } else {
    scale = (float) width / (float) inBitmap.getWidth();
    dy = (height - inBitmap.getHeight() * scale) * 0.5f;
  }

  m.setScale(scale, scale);
  m.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));

  Bitmap result = pool.get(width, height, getSafeConfig(inBitmap));
  // We don't add or remove alpha, so keep the alpha setting of the Bitmap we were given.
  TransformationUtils.setAlpha(inBitmap, result);

  applyMatrix(inBitmap, result, m);
  return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:39,代码来源:TransformationUtils.java

示例11: initRes

import android.graphics.Matrix; //导入方法依赖的package包/类
private void initRes(Context context) {
  mSrcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test4);
  Matrix matrix = new Matrix();
  matrix.setScale(1F, -1F);
  mRefBitmap =
      Bitmap.createBitmap(mSrcBitmap, 0, 0, mSrcBitmap.getWidth(), mSrcBitmap.getHeight(), matrix,
          true);

  mPaint = new Paint();
  mPaint.setShader(new LinearGradient(0, mSrcBitmap.getHeight(), 0,
      mSrcBitmap.getHeight() + mSrcBitmap.getHeight() / 4, 0XDD000000, 0X10000000,
      Shader.TileMode.CLAMP));
  mXfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
}
 
开发者ID:liuguoquan727,项目名称:android-study,代码行数:15,代码来源:ReflectView.java

示例12: testConfigureBounds_FOCUS_CROP_HL

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:ScaleTypeDrawableTest.java

示例13: fastBlur

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * 快速模糊图片
 * <p>先缩小原图,对小图进行模糊,再放大回原先尺寸</p>
 *
 * @param src     源图片
 * @param scale   缩放比例(0...1)
 * @param radius  模糊半径(0...25)
 * @param recycle 是否回收
 * @return 模糊后的图片
 */
public static Bitmap fastBlur(final Bitmap src, final float scale, final float radius, final boolean recycle) {
	if (isEmptyBitmap(src)) {
		return null;
	}
	int width = src.getWidth();
	int height = src.getHeight();
	Matrix matrix = new Matrix();
	matrix.setScale(scale, scale);
	Bitmap scaleBitmap = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
	Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
	Canvas canvas = new Canvas();
	PorterDuffColorFilter filter = new PorterDuffColorFilter(
			Color.TRANSPARENT, PorterDuff.Mode.SRC_ATOP);
	paint.setColorFilter(filter);
	canvas.scale(scale, scale);
	canvas.drawBitmap(scaleBitmap, 0, 0, paint);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
		scaleBitmap = renderScriptBlur(scaleBitmap, radius, recycle);
	} else {
		scaleBitmap = stackBlur(scaleBitmap, (int) radius, recycle);
	}
	if (scale == 1) {
		return scaleBitmap;
	}
	Bitmap ret = Bitmap.createScaledBitmap(scaleBitmap, width, height, true);
	if (scaleBitmap != null && !scaleBitmap.isRecycled()) {
		scaleBitmap.recycle();
	}
	if (recycle && !src.isRecycled()) {
		src.recycle();
	}
	return ret;
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:44,代码来源:ImageUtils.java

示例14: createBitmap

import android.graphics.Matrix; //导入方法依赖的package包/类
private Bitmap createBitmap(Bitmap bitmap, int w, int h, float scale) {
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);
    matrix.postRotate(orientation);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:7,代码来源:PhotoFilterView.java

示例15: cut2ScaleSize

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * 裁剪并缩放至指定大小
 *
 * @param source
 * @param dstWidth
 * @param dstHeight
 * @param recycleSource 裁剪成功后销毁原图
 * @return
 */
public static Bitmap cut2ScaleSize(Bitmap source, int dstWidth, int dstHeight, boolean recycleSource) {
    final int width = source.getWidth();
    final int height = source.getHeight();
    if (width == dstWidth && height == dstHeight) {
        return source;
    }

    // scale
    Matrix m = new Matrix();
    int l = 0, t = 0, r = width, b = height;
    {
        float sx = dstWidth / (float) width;
        float sy = dstHeight / (float) height;

        if (sx > sy) {
            sy = sx;
            l = 0;
            r = width;
            t = (int) ((height - dstHeight / sx) / 2);
            b = (int) ((height + dstHeight / sx) / 2);
        } else {
            sx = sy;
            l = (int) ((width - dstWidth / sx) / 2);
            r = (int) ((width + dstWidth / sx) / 2);
            t = 0;
            b = height;
        }
        m.setScale(sx, sy);
    }

    Bitmap result = Bitmap.createBitmap(source, l, t, r - l, b - t, m, true);

    if (result != null) {
        if (recycleSource && result != source) {
            source.recycle();
            source = null;
        }
    } else {
        result = source;
    }
    return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:52,代码来源:ImageDecoder.java


注:本文中的android.graphics.Matrix.setScale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。