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


Java Canvas.setMatrix方法代码示例

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


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

示例1: createMaskBitmap

import android.graphics.Canvas; //导入方法依赖的package包/类
public static final Bitmap createMaskBitmap(Bitmap bitmap, int viewBoxW, int viewBoxH,
                                            int rotation, float gapSize) {

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    paint.setAntiAlias(true);// 抗锯齿
    paint.setFilterBitmap(true);
    int center = Math.round(viewBoxW / 2f);
    canvas.drawCircle(center, center, center, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, 0, 0, paint);

    if (rotation != 360) {
        Matrix matrix = new Matrix();
        // 根据原图的中心位置旋转
        matrix.setRotate(rotation, viewBoxW / 2, viewBoxH / 2);
        canvas.setMatrix(matrix);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        canvas.drawCircle(viewBoxW * (1.5f - gapSize), center, center, paint);
    }
    return output;
}
 
开发者ID:zuoweitan,项目名称:Hitalk,代码行数:25,代码来源:JoinBitmaps.java

示例2: scaleBitmap

import android.graphics.Canvas; //导入方法依赖的package包/类
private static void scaleBitmap(Bitmap src, Bitmap dst) {
    Paint cPaint = new Paint();
    cPaint.setAntiAlias(true);
    cPaint.setDither(true);
    cPaint.setFilterBitmap(true);

    float ratioX = dst.getWidth() / (float) src.getWidth();
    float ratioY = dst.getHeight() / (float) src.getHeight();
    float middleX = dst.getWidth() * 0.5f;
    float middleY = dst.getHeight() * 0.5f;

    Matrix scaleMatrix = new Matrix();
    scaleMatrix.setScale(ratioX, ratioY, middleX, middleY);
    Canvas canvas = new Canvas(dst);
    canvas.setMatrix(scaleMatrix);
    canvas.drawBitmap(src, middleX - src.getWidth() / 2,
            middleY - src.getHeight() / 2, cPaint);
}
 
开发者ID:SumiMakito,项目名称:AwesomeQRCode,代码行数:19,代码来源:AwesomeQRCode.java

示例3: scaleBitmap

import android.graphics.Canvas; //导入方法依赖的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,项目名称:My-Android-Base-Code,代码行数:18,代码来源:SubUtils.java

示例4: combine

import android.graphics.Canvas; //导入方法依赖的package包/类
private void combine() {
    Bitmap out = null;
    if (mSrc != null && mDst != null) {
        int width = Math.max(mSrc.getWidth(), mDst.getWidth());
        int height = Math.max(mSrc.getHeight(), mDst.getHeight());
        out = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

        int sOffsetX = (out.getWidth() - mSrc.getWidth()) / 2;
        int sOffsetY = (out.getHeight() - mSrc.getHeight()) / 2;
        int dOffsetX = (out.getWidth() - mDst.getWidth()) / 2;
        int dOffsetY = (out.getHeight() - mDst.getHeight()) / 2;

        Canvas canvas = new Canvas(out);
        canvas.setMatrix(getMatrix());
        canvas.drawBitmap(mDst, sOffsetX, sOffsetY, null);
        Paint paint = new Paint();
        paint.setXfermode(new PorterDuffXfermode(mMode));
        canvas.drawBitmap(mSrc, dOffsetX, dOffsetY, paint);
    }
    setImageBitmap(out);
}
 
开发者ID:StylingAndroid,项目名称:PresenterLite,代码行数:22,代码来源:PorterDuffImageView.java

示例5: drawDebug

import android.graphics.Canvas; //导入方法依赖的package包/类
public synchronized void drawDebug(final Canvas canvas, final Matrix frameToCanvas) {
  canvas.save();
  canvas.setMatrix(frameToCanvas);

  drawHistoryDebug(canvas);
  drawKeypointsDebug(canvas);

  canvas.restore();
}
 
开发者ID:Jamjomjara,项目名称:snu-artoon,代码行数:10,代码来源:ObjectTracker.java

示例6: drawBitmapAR

import android.graphics.Canvas; //导入方法依赖的package包/类
/**
 * Draw the bitmap / drawable on screen
 * @param canvas canvas to be applied to the drawable
 * @param drawable drawable with bitmap
 * @param w width of face
 * @param h height of face
 * @param x face x coordinate starting point
 * @param y face y coordinate starting point point
 */
private void drawBitmapAR(Canvas canvas, Drawable drawable, int w, int h, int x, int y) {
    if (drawable != null) {
        int widthGraphic = drawable.getIntrinsicWidth();
        int heightGraphic = drawable.getIntrinsicHeight();
        setTransformation(w, h, x, y, widthGraphic, heightGraphic);
        canvas.setMatrix(transformation);
        drawable.draw(canvas);
    }
}
 
开发者ID:raulh82vlc,项目名称:Image-Detection-Samples,代码行数:19,代码来源:FaceDrawer.java

示例7: onDraw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void onDraw(Canvas canvas, Rect bounds) {
    if (mDegree > 360) {
        mDegree = 0;
    } else {
        mDegree += 0.5;
    }
    mMatrix.setRotate(mDegree, mCenterX, mCenterY);
    canvas.setMatrix(mMatrix);
    canvas.drawBitmap(mBackground, mMatrix, mBackgroundPaint);

    if (isVisible() && !isInAmbientMode()) {
        invalidate();
    }
}
 
开发者ID:mightyfrog,项目名称:Watch-Face-Animation-Sample,代码行数:16,代码来源:MyWatchFace.java

示例8: onDrawShadow

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void onDrawShadow(Canvas canvas) {
    Matrix matrix = new Matrix();
    matrix.reset();
    matrix.setScale(1.3f, 1.3f);
    canvas.setMatrix(matrix);
    super.onDrawShadow(canvas);
}
 
开发者ID:monthlypub,项目名称:SmingZZick_App,代码行数:9,代码来源:StickerApplyAdapter.java

示例9: draw

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Context context, Canvas canvas) {
    TextSticker textSticker = (TextSticker) sticker;
    if (textSticker.textFile == null || textSticker.textFile.exists() == false) {
        return;
    }

    TextMakingInfo textMakingInfo = textSticker.getTextMakeInfo(context);

    int canvasWidth = canvas.getWidth();
    int canvasHeight = canvas.getHeight();

    float targetWidthDP = Util.px2dp(context, canvasWidth * widthRatio);
    float textSize = targetWidthDP / textMakingInfo.getWidthTextRatio();

    textMakingInfo.setTextSize(textSize);

    Rect rect = new Rect();
    textMakingInfo.getTextRect(context, rect);

    float textRectWidth = rect.width();
    float textRectHeight = rect.height();

    Matrix matrix = new Matrix();
    matrix.reset();

    matrix.postTranslate((canvasWidth - textRectWidth) / 2, (canvasHeight - textRectHeight) / 2);
    matrix.postRotate(angle, canvasWidth / 2, canvasHeight / 2);
    matrix.postTranslate(canvasWidth / 2 * posX, canvasHeight / 2 * posY);

    canvas.setMatrix(matrix);
    canvas.saveLayerAlpha(0, 0, textRectWidth, textRectHeight, (int) (alpha * 255), Canvas.ALL_SAVE_FLAG);
    textMakingInfo.draw(context, (int) textRectWidth, (int) textRectHeight, canvas);
    canvas.restore();
    matrix.reset();
    canvas.setMatrix(matrix);
}
 
开发者ID:monthlypub,项目名称:SmingZZick_App,代码行数:38,代码来源:TextStickerAttachInfo.java

示例10: duplicateCanvas

import android.graphics.Canvas; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private void duplicateCanvas() {
	try {
		Bitmap newBM = Bitmap.createBitmap(canvas.getWidth(),
				canvas.getHeight(), Bitmap.Config.ARGB_8888);
		bitmapStack.push(newBM);
		Canvas newCanvas = new Canvas(newBM);
		newCanvas.setMatrix(canvas.getMatrix());
		canvas = newCanvas;
	} catch (OutOfMemoryError e) {
		error("Not enough memory to create temporary bitmaps for mask processing");
		throw e;
	}
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:15,代码来源:SVGAndroidRenderer.java

示例11: drawChild

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    if (!mHasClickableChildren) {
        int save = canvas.save();
        canvas.setMatrix(mMatrix);
        boolean result = super.drawChild(canvas, child, drawingTime);
        canvas.restoreToCount(save);
        return result;
    } else {
        return super.drawChild(canvas, child, drawingTime);
    }
}
 
开发者ID:natario1,项目名称:ZoomLayout,代码行数:13,代码来源:ZoomLayout.java

示例12: compressImage

import android.graphics.Canvas; //导入方法依赖的package包/类
private Bitmap compressImage() {

            Bitmap scaledBitmap = null;
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;

            Bitmap  bm  =  BitmapFactory.decodeFile(this.string, options);


            int actualHeight = options.outHeight;
            int actualWidth = options.outWidth;

            float imgRatio = (float) actualWidth / actualHeight;
            float maxRatio  = maxWidth / maxHeight;

            if (actualHeight > maxHeight || actualWidth > maxWidth) {

                if (imgRatio < maxRatio) {
                    imgRatio = maxHeight / actualHeight;
                    actualWidth = (int) (imgRatio * actualWidth);
                    actualHeight = (int) maxHeight;
                }
                else if (imgRatio > maxRatio) {
                    imgRatio = maxWidth / actualWidth;
                    actualHeight = (int) (imgRatio * actualHeight);
                    actualWidth = (int) maxWidth;
                }
                else {
                    actualHeight = (int) maxHeight;
                    actualWidth = (int) maxWidth;
                }

            }

            options.inSampleSize = calculateInSampleSize(options, actualWidth, actualHeight);
            options.inJustDecodeBounds = false;
            options.inDither = false;
            options.inPurgeable = true;
            options.inTempStorage = new byte[16 * 1024];
            try {
                bm = BitmapFactory.decodeFile(string, options);
            } catch (OutOfMemoryError exc) {
                exc.printStackTrace();
            }
            try {
                scaledBitmap = Bitmap.createBitmap(actualWidth, actualHeight, Bitmap.Config.RGB_565);
            }catch (OutOfMemoryError exp) {
                exp.printStackTrace();
            }
            float ratioX = actualWidth / (float) options.outWidth;
            float ratioY = actualHeight / (float) options.outHeight;
            float middleX = actualWidth / 2.0f;
            float middleY = actualHeight / 2.0f;
            Matrix scaleMatrix = new Matrix();
            scaleMatrix.setScale(ratioX, ratioY, middleX, middleY);
            Canvas canvas = new Canvas(scaledBitmap);
            canvas.setMatrix(scaleMatrix);
            canvas.drawBitmap(bm, middleX - bm.getWidth()/2, middleY - bm.getHeight()/2, new Paint(Paint.FILTER_BITMAP_FLAG));
            bm.recycle();

            return scaledBitmap;
        }
 
开发者ID:sparrow007,项目名称:CircularImageview,代码行数:63,代码来源:ImageCompress.java


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