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


Java Matrix.postScale方法代码示例

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


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

示例1: onAnimationUpdate

import android.graphics.Matrix; //导入方法依赖的package包/类
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    ImageMatrixCorrector corrector = getCorrector();
    ImageView imageView = corrector.getImageView();
    if(imageView.getDrawable() != null) {
        Matrix matrix = imageView.getImageMatrix();
        float[] values = getValues();
        matrix.getValues(values);

        float sx = (float) animation.getAnimatedValue();
        sx = corrector.correctAbsolute(Matrix.MSCALE_X, sx) / values[Matrix.MSCALE_X];

        if (translate) {
            matrix.postScale(sx, sx, px, py);
        } else {
            matrix.postScale(sx, sx);
        }
        corrector.performAbsoluteCorrections();
        imageView.invalidate();
    }
}
 
开发者ID:martinwithaar,项目名称:PinchToZoom,代码行数:22,代码来源:ScaleAnimatorHandler.java

示例2: drawLeafs

import android.graphics.Matrix; //导入方法依赖的package包/类
private void drawLeafs(Canvas canvas) {
    canvas.save();
    routing -= 2;
    //通过Matrix控制叶子的旋转
    Matrix matrix = new Matrix();
    //缩放
    float scaleX = mLeafPaintWidth / mLeafBitmapWidth;
    float scaleY = mLeafPaintHeight / mLeafBitmapHeight;
    matrix.postScale(scaleX, scaleY);
    //位移
    float transX = mLeftMargin + routing;
    float transY = mLeftMargin * 2;
    matrix.postTranslate(transX, transY);
    canvas.drawBitmap(mLeafBitmap, matrix, mBitmapPaint);
    canvas.restore();
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:17,代码来源:LeafView.java

示例3: configureTransform

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
public void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max(
                (float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
    overlay.setRect(CameraFragmentUtil.getScanRect(scanSegment));
}
 
开发者ID:digital-voting-pass,项目名称:polling-station-app,代码行数:34,代码来源:CameraFragment.java

示例4: getResizedBitmap

import android.graphics.Matrix; //导入方法依赖的package包/类
public static Bitmap getResizedBitmap(Bitmap bitmap, int newWidth, int newHeight){
    try {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        float scaleWidth = ((float) newWidth / width);
        float scaleHieght = ((float) newHeight / height);
        Matrix matrix = new Matrix();
        matrix.postScale(scaleWidth, scaleHieght);
        Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, false);
        bitmap.recycle();
        return resizedBitmap;
    } catch (NullPointerException e){
        log("Cannot load bitmap, " + e.getMessage());
        return null;
    }
}
 
开发者ID:thenewpotato,项目名称:Blogg,代码行数:17,代码来源:Tools.java

示例5: cropAndRescaleBitmap

import android.graphics.Matrix; //导入方法依赖的package包/类
public static void cropAndRescaleBitmap(final Bitmap src, final Bitmap dst, int sensorOrientation) {
    Assert.assertEquals(dst.getWidth(), dst.getHeight());
    final float minDim = Math.min(src.getWidth(), src.getHeight());

    final Matrix matrix = new Matrix();

    // We only want the center square out of the original rectangle.
    final float translateX = -Math.max(0, (src.getWidth() - minDim) / 2);
    final float translateY = -Math.max(0, (src.getHeight() - minDim) / 2);
    matrix.preTranslate(translateX, translateY);

    final float scaleFactor = dst.getHeight() / minDim;
    matrix.postScale(scaleFactor, scaleFactor);

    // Rotate around the center if necessary.
    if (sensorOrientation != 0) {
        matrix.postTranslate(-dst.getWidth() / 2.0f, -dst.getHeight() / 2.0f);
        matrix.postRotate(sensorOrientation);
        matrix.postTranslate(dst.getWidth() / 2.0f, dst.getHeight() / 2.0f);
    }

    final Canvas canvas = new Canvas(dst);
    canvas.drawBitmap(src, matrix, null);
}
 
开发者ID:PallabPaul,项目名称:AI_Calorie_Counter_Demo,代码行数:25,代码来源:ImageUtils.java

示例6: configureTransform

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max(
                (float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}
 
开发者ID:wingskyer,项目名称:android-Camera2Basic-master,代码行数:33,代码来源:Camera2BasicFragment.java

示例7: resizeImage

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * 对图片进行缩放
 *
 * @param bitmap
 * @param w
 * @param h
 * @return
 */
public static Bitmap resizeImage(Bitmap bitmap, int w, int h) {
    Bitmap BitmapOrg = bitmap;
    int width = BitmapOrg.getWidth();
    int height = BitmapOrg.getHeight();
    int newWidth = w;
    int newHeight = h;

    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    // if you want to rotate the Bitmap
    // matrix.postRotate(45);
    return Bitmap.createBitmap(BitmapOrg, 0, 0, width,
            height, matrix, true);
}
 
开发者ID:smartbeng,项目名称:PaoMovie,代码行数:26,代码来源:ImageUtils.java

示例8: testCreation_transverse

import android.graphics.Matrix; //导入方法依赖的package包/类
@Test
public void testCreation_transverse() {
  OrientedDrawable drawable =
      new OrientedDrawable(mDrawable, 0, ExifInterface.ORIENTATION_TRANSVERSE);
  drawable.setBounds(mBounds);
  drawable.draw(mCanvas);

  Matrix expectedMatrix = new Matrix();
  expectedMatrix.setRotate(270, drawable.getBounds().centerX(), drawable.getBounds().centerY());
  expectedMatrix.postScale(-1, 1);
  assertFalse(drawable.mRotationMatrix.isIdentity());
  AndroidGraphicsTestUtils.assertEquals(expectedMatrix, drawable.mRotationMatrix);
  verifySetBounds(expectedMatrix);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:OrientedDrawableTest.java

示例9: considerExactScaleAndOrientatiton

import android.graphics.Matrix; //导入方法依赖的package包/类
protected Bitmap considerExactScaleAndOrientatiton(Bitmap subsampledBitmap, ImageDecodingInfo
        decodingInfo, int rotation, boolean flipHorizontal) {
    Matrix m = new Matrix();
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    if (scaleType == ImageScaleType.EXACTLY || scaleType == ImageScaleType.EXACTLY_STRETCHED) {
        float scale = ImageSizeUtils.computeImageScale(new ImageSize(subsampledBitmap
                .getWidth(), subsampledBitmap.getHeight(), rotation), decodingInfo
                .getTargetSize(), decodingInfo.getViewScaleType(), scaleType ==
                ImageScaleType.EXACTLY_STRETCHED);
        if (Float.compare(scale, 1.0f) != 0) {
            m.setScale(scale, scale);
            if (this.loggingEnabled) {
                L.d(LOG_SCALE_IMAGE, srcSize, srcSize.scale(scale), Float.valueOf(scale),
                        decodingInfo.getImageKey());
            }
        }
    }
    if (flipHorizontal) {
        m.postScale(-1.0f, 1.0f);
        if (this.loggingEnabled) {
            L.d(LOG_FLIP_IMAGE, decodingInfo.getImageKey());
        }
    }
    if (rotation != 0) {
        m.postRotate((float) rotation);
        if (this.loggingEnabled) {
            L.d(LOG_ROTATE_IMAGE, Integer.valueOf(rotation), decodingInfo.getImageKey());
        }
    }
    Bitmap finalBitmap = Bitmap.createBitmap(subsampledBitmap, 0, 0, subsampledBitmap
            .getWidth(), subsampledBitmap.getHeight(), m, true);
    if (finalBitmap != subsampledBitmap) {
        subsampledBitmap.recycle();
    }
    return finalBitmap;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:37,代码来源:BaseImageDecoder.java

示例10: drawDrawable

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * draw Rounded Rectangle
 *
 * @param canvas
 * @param bitmap
 */
private void drawDrawable(Canvas canvas, Bitmap bitmap) {
    Paint paint = new Paint();
    paint.setColor(0xffffffff);
    paint.setAntiAlias(true); //smooths out the edges of what is being drawn
    PorterDuffXfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
    // set flags
    int saveFlags = Canvas.MATRIX_SAVE_FLAG
            | Canvas.CLIP_SAVE_FLAG
            | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG
            | Canvas.FULL_COLOR_LAYER_SAVE_FLAG
            | Canvas.CLIP_TO_LAYER_SAVE_FLAG;
    canvas.saveLayer(0, 0, width, height, null, saveFlags);

    if (shapeType == 1) {
        canvas.drawCircle(width / 2, height / 2, width / 2 - 1, paint);
    } else if (shapeType == 2) {
        RectF rectf = new RectF(1, 1, getWidth() - 1, getHeight() - 1);
        canvas.drawRoundRect(rectf, radius + 1, radius + 1, paint);
    }

    paint.setXfermode(xfermode);

    float scaleWidth = ((float) getWidth()) / bitmap.getWidth();
    float scaleHeight = ((float) getHeight()) / bitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);

    //bitmap scale
    bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

    canvas.drawBitmap(bitmap, 0, 0, paint);
    canvas.restore();
}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:41,代码来源:EaseImageView.java

示例11: zoomDrawable

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * 缩放Drawable
 * 
 * @author 2013-10-12 下午3:56:40
 * @param drawable
 * @param w
 * @param h
 * @return Drawable
 */
public static Drawable zoomDrawable(Drawable drawable, int w, int h)
{
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    Bitmap oldbmp = drawableToBitmap(drawable); // drawable转换成bitmap
    Matrix matrix = new Matrix(); // 创建操作图片用的Matrix对象
    float scaleWidth = ((float)w / width); // 计算缩放比例
    float scaleHeight = ((float)h / height);
    matrix.postScale(scaleWidth, scaleHeight); // 设置缩放比例
    Bitmap newbmp = Bitmap.createBitmap(oldbmp, 0, 0, width, height, matrix, true); // 建立新的bitmap,其内容是对原bitmap的缩放后的图
    return new BitmapDrawable(newbmp); // 把bitmap转换成drawable并返回
}
 
开发者ID:zhuyu1022,项目名称:amap,代码行数:22,代码来源:MIP_BitmapUtils.java

示例12: convert

import android.graphics.Matrix; //导入方法依赖的package包/类
public static Bitmap convert(Bitmap a) {
    int w = a.getWidth();
    int h = a.getHeight();
    Bitmap newb = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图
    Canvas cv = new Canvas(newb);
    Matrix m = new Matrix();
    //m.postScale(1, -1);   //镜像垂直翻转
    m.postScale(-1, 1);   //镜像水平翻转
    //m.postRotate(-90);  //旋转-90度
    Bitmap new2 = Bitmap.createBitmap(a, 0, 0, w, h, m, true);
    cv.drawBitmap(new2, new Rect(0, 0, new2.getWidth(), new2.getHeight()),new Rect(0, 0, w, h), null);
    return newb;
}
 
开发者ID:MarukoZ,项目名称:FaceRecognition,代码行数:14,代码来源:ImageUtil.java

示例13: ScaleCompressFormBitmap

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * 按目标宽高缩放
 * @param bitmap 目标bitmap
 * @param newW 目标宽度
 * @param newH 目标高度
 * @return
 */
public static Bitmap ScaleCompressFormBitmap(Bitmap bitmap, float newW, float newH) {
    int oldW = bitmap.getWidth();
    int oldH = bitmap.getHeight();
    // 计算缩放比例
    float scaleWidth = newW / oldW;
    float scaleHeight = newH / oldH;
    // 取得想要缩放的matrix参数
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    // 得到新的图片
    bitmap = Bitmap.createBitmap(bitmap, 0, 0, oldW, oldH, matrix, true);
    return bitmap;
}
 
开发者ID:AnliaLee,项目名称:PhotoFactory,代码行数:21,代码来源:CompressUtils.java

示例14: zoomImage

import android.graphics.Matrix; //导入方法依赖的package包/类
public static Bitmap zoomImage(Bitmap bgimage, double newWidth, double newHeight) {
    float width = (float) bgimage.getWidth();
    float height = (float) bgimage.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale(((float) newWidth) / width, ((float) newHeight) / height);
    return Bitmap.createBitmap(bgimage, 0, 0, (int) width, (int) height, matrix, true);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:8,代码来源:ResolutionUtils.java

示例15: createBitmapThumbnail

import android.graphics.Matrix; //导入方法依赖的package包/类
public static Bitmap createBitmapThumbnail(Bitmap bitMap, boolean needRecycle, int newHeight, int newWidth) {
    int width = bitMap.getWidth();
    int height = bitMap.getHeight();
    // 计算缩放比例
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // 取得想要缩放的matrix参数
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    // 得到新的图片
    Bitmap newBitMap = Bitmap.createBitmap(bitMap, 0, 0, width, height, matrix, true);
    if (needRecycle)
        bitMap.recycle();
    return newBitMap;
}
 
开发者ID:penghuanliang,项目名称:Rxjava2.0Demo,代码行数:16,代码来源:BitmapUtil.java


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