當前位置: 首頁>>代碼示例>>Java>>正文


Java Canvas.scale方法代碼示例

本文整理匯總了Java中android.graphics.Canvas.scale方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.scale方法的具體用法?Java Canvas.scale怎麽用?Java Canvas.scale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.Canvas的用法示例。


在下文中一共展示了Canvas.scale方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: blurBitmap

import android.graphics.Canvas; //導入方法依賴的package包/類
public static Bitmap blurBitmap(Bitmap bkg, int width, int height) {
    long startMs = System.currentTimeMillis();
    float radius = 15;//越大模糊效果越大
    float scaleFactor = 8;
    //放大到整個view的大小
    bkg = DrawableProvider.getReSizeBitmap(bkg, width, height);
    Bitmap overlay = Bitmap.createBitmap((int) (width / scaleFactor)
            , (int) (height / scaleFactor), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bkg, 0, 0, paint);
    overlay = FastBlur.doBlur(overlay, (int) radius, true);
    Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
    return overlay;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:FastBlur.java

示例2: onDraw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    Log.e(TAG, "onDraw....");
    float radius = getWidth() / 10;
    for (int i = 0; i < 8; i++) {
        canvas.save();
        // 獲取繪製小圓的原點
        Point point = circleAt(getWidth(), getHeight(), getWidth() / 2 - radius, i * (Math.PI / 4));
        // 以point為原點坐標
        canvas.translate(point.x, point.y);
        // 設置尺寸
        canvas.scale(scaleFloats[i], scaleFloats[i]);
        // 設置透明度
        mPaint.setAlpha(alphas[i]);
        canvas.drawCircle(0, 0, radius, mPaint);
        canvas.restore();
    }
}
 
開發者ID:wuhighway,項目名稱:DailyStudy,代碼行數:20,代碼來源:BallSpinFadeLoadingView.java

示例3: restoreBitmap

import android.graphics.Canvas; //導入方法依賴的package包/類
public static Bitmap restoreBitmap(Bitmap src, Matrix matrix, int w, int h) {
    Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());
    result.setDensity(src.getDensity());
    Canvas canvas = new Canvas(result);
    float[] data = new float[9];
    matrix.getValues(data);// 底部圖片變化記錄矩陣原始數據
    Matrix3 cal = new Matrix3(data);// 輔助矩陣計算類
    Matrix3 inverseMatrix = cal.inverseMatrix();// 計算逆矩陣
    Matrix m = new Matrix();
    m.setValues(inverseMatrix.getValues());
    float[] f = new float[9];
    m.getValues(f);
    int dx = (int) f[Matrix.MTRANS_X];
    int dy = (int) f[Matrix.MTRANS_Y];
    float scale_x = f[Matrix.MSCALE_X];
    float scale_y = f[Matrix.MSCALE_Y];
    canvas.save();
    canvas.translate(dx, dy);
    canvas.scale(scale_x, scale_y);
    canvas.drawBitmap(src, 0, 0, null);
    canvas.restore();
    return result;
}
 
開發者ID:viseator,項目名稱:MontageCam,代碼行數:24,代碼來源:BitmapUtils.java

示例4: stickerDraw

import android.graphics.Canvas; //導入方法依賴的package包/類
protected void stickerDraw(Canvas canvas) {
    if (containerView == null) {
        return;
    }

    canvas.save();
    Bitmap bitmap = centerImage.getBitmap();
    if (bitmap != null) {
        if (mirrored) {
            canvas.scale(-1.0f, 1.0f);
            canvas.translate(-baseSize.width, 0);
        }
        centerImage.setImageCoords(0, 0, (int) baseSize.width, (int) baseSize.height);
        centerImage.draw(canvas);
    }
    canvas.restore();
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:18,代碼來源:StickerView.java

示例5: addLogoToQRCode

import android.graphics.Canvas; //導入方法依賴的package包/類
/**
 * 添加logo到二維碼圖片上
 *
 * @param src
 * @param logo
 * @return
 */
private static Bitmap addLogoToQRCode(Bitmap src, Bitmap logo) {
    if (src == null || logo == null) {
        return src;
    }

    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    int logoWidth = logo.getWidth();
    int logoHeight = logo.getHeight();

    float scaleFactor = srcWidth * 1.0f / 5 / logoWidth;
    Bitmap bitmap = Bitmap.createBitmap(srcWidth, srcHeight, Bitmap.Config.ARGB_8888);
    try {
        Canvas canvas = new Canvas(bitmap);
        canvas.drawBitmap(src, 0, 0, null);
        canvas.scale(scaleFactor, scaleFactor, srcWidth / 2, srcHeight / 2);
        canvas.drawBitmap(logo, (srcWidth - logoWidth) / 2, (srcHeight - logoHeight) / 2, null);
        canvas.save(Canvas.ALL_SAVE_FLAG);
        canvas.restore();
    } catch (Exception e) {
        bitmap = null;
    }
    return bitmap;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:32,代碼來源:QRCodeEncoder.java

示例6: onDraw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    float circleSpacing = 4;
    float radius = (Math.min(getWidth(), getHeight()) - circleSpacing * 2) / 6;
    float x = getWidth() / 2 - (radius * 2 + circleSpacing);
    float y = getHeight() / 2;
    for (int i = 0; i < 3; i++) {
        canvas.save();
        float translateX = x + (radius * 2) * i + circleSpacing * i;
        canvas.translate(translateX, y);
        canvas.scale(scaleFloats[i], scaleFloats[i]);
        canvas.drawCircle(0, 0, radius, mPaint);
        canvas.restore();
    }
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:18,代碼來源:ProgressIndicatorView.java

示例7: draw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
    float progressWidth = mWidth * progressPercent / 100f;
    float halfWidth = progressWidth / 2;
    // 畫背景圖
    canvas.save();
    canvas.rotate(mRotation, getBounds().centerX(), getBounds().centerY());
    float scale = 1 - progressWidth * 2.0f / mWidth;
    canvas.scale(scale, scale, mWidth / 2.0f, mWidth / 2.0f);
    canvas.drawCircle(mWidth / 2, mWidth / 2, mWidth / 2, mPaint);
    canvas.restore();
    // 畫進度條
    rectF.set(halfWidth, halfWidth, mWidth - halfWidth, mWidth - halfWidth);
    canvas.drawArc(rectF, -90, progress, false, progressPaint);
}
 
開發者ID:cpacm,項目名稱:FloatingMusicMenu,代碼行數:16,代碼來源:RotatingProgressDrawable.java

示例8: draw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override public void draw(Canvas canvas) {
  canvas.save();
  canvas.scale(scale, scale, center.x, center.y);
  canvas.rotate(rotate, center.x, center.y);
  eye.draw(canvas);
  eyeBound.draw(canvas);
  for (int i = 0; i < numberOfSharingan; i++) {
    canvas.save();
    canvas.rotate(i * 120, center.x, center.y);
    sharingans[i].draw(canvas);
    canvas.restore();
  }
  canvas.restore();
}
 
開發者ID:nntuyen,項目名稱:mkloader,代碼行數:15,代碼來源:Sharingan.java

示例9: drawTown

import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawTown(Canvas canvas, int width, int height) {
        Matrix matrix = mMatrix;
        matrix.reset();

        int bWidth = mDrawableTown.width();//mTown.getWidth();
        int bHeight = mDrawableTown.height();//mTown.getHeight();
        float townScale = 1f * width / bWidth;
        float amplification = (0.3f * Math.max(mPercent - 1, 0) + 1);
        float offsetx = width / 2 - (int) (width * amplification) / 2;
        float offsety = mHeaderHeight * 0.1f * mPercent;
        townScale = amplification * townScale;

        if (offsety + bHeight * townScale < height) {
            offsety = height - bHeight * townScale;
        }

//        matrix.postScale(townScale, townScale, mDrawableTown.width() / 2, mDrawableTown.height() / 2);
//        matrix.postTranslate(offsetx, offsety);
//        canvas.drawBitmap(mTown, matrix, null);

        final int saveCount = canvas.getSaveCount();
        canvas.save();
        canvas.translate(offsetx, offsety);
        canvas.scale(townScale, townScale);
        mDrawableTown.draw(canvas);
        canvas.restoreToCount(saveCount);
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:28,代碼來源:PhoenixHeader.java

示例10: draw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas, Paint paint) {
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(3);

    float circleSpacing=12;
    float x = (getWidth()) / 2;
    float y=(getHeight()) / 2;
    canvas.translate(x, y);
    canvas.scale(scaleFloat, scaleFloat);
    canvas.rotate(degrees);
    RectF rectF=new RectF(-x+circleSpacing,-y+circleSpacing,0+x-circleSpacing,0+y-circleSpacing);
    canvas.drawArc(rectF, -45, 270, false, paint);
}
 
開發者ID:leobert-lan,項目名稱:UiLib,代碼行數:15,代碼來源:BallClipRotateIndicator.java

示例11: drawDragShadow

import android.graphics.Canvas; //導入方法依賴的package包/類
@SuppressLint("WrongCall")
public void drawDragShadow(Canvas canvas) {
    final int saveCount = canvas.save(Canvas.MATRIX_SAVE_FLAG);
    canvas.scale(getScaleX(), getScaleY());
    onDraw(canvas);
    canvas.restoreToCount(saveCount);
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:8,代碼來源:DragView.java

示例12: onDraw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
   protected void onDraw(final Canvas canvas)
   {
   	try {
        if (recycled)
            return;

        repaint(getContext());
        final int canvasSave = canvas.save();
        canvas.translate(getPaddingLeft(), getPaddingTop());
        canvas.translate(0, internalPaddingTop);
        canvas.scale(scale, scale);
        
        if (!genBackgroundBitmap.isRecycled()) {
        	canvas.drawBitmap(genBackgroundBitmap, 0, 0, bitmapPaint);
        }
  
       	gridBitmap = null;
       	gridBitmap = generateGridBitmap(canvas);
        
    	canvas.drawBitmap(gridBitmap, gridX, gridY, bitmapPaint);
        
        final int canvasSave2 = canvas.save();
        canvas.translate(graphX, graphY);

        for (final GraphService graph : graphs)
            graph.draw(canvas);
        
        canvas.restoreToCount(canvasSave2);
//        if (!reflectionBitmap.isRecycled()) {
//        	canvas.drawBitmap(reflectionBitmap, reflectionX, reflectionY, bitmapPaint);
//        }
        
        canvas.restoreToCount(canvasSave);
   	}
   	catch (Exception e) {
   		e.printStackTrace();
   	}
   }
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:40,代碼來源:CustomizableGraphView.java

示例13: getBitmapWithBorder

import android.graphics.Canvas; //導入方法依賴的package包/類
private Bitmap getBitmapWithBorder(View v, float scale) {
    Bitmap bitmap = getBitmapFromView(v,0);
    Bitmap b = getBitmapFromView(v,1);
    Canvas can = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAlpha(150);
    can.scale(scale,scale,mDownX,mDownY);
    can.rotate(3);
    can.drawBitmap(b,0,0,paint);
    return bitmap;
}
 
開發者ID:tangqipeng,項目名稱:draggable-tree-itemview,代碼行數:12,代碼來源:DraggableTreeView.java

示例14: draw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas)
{
    final float scaleFactorX = getWidth()/(WIDTH * 1.f);
    final float scaleFactorY = getHeight()/(HEIGHT * 1.f);
    if(canvas!=null) {
        final int savedState = canvas.save();
        canvas.scale(scaleFactorX, scaleFactorY);
        bg.draw(canvas);
        player.draw(canvas);
        canvas.restoreToCount(savedState);
    }
}
 
開發者ID:ZetaPhase,項目名稱:BulletNova,代碼行數:14,代碼來源:GamePanel.java

示例15: zoom

import android.graphics.Canvas; //導入方法依賴的package包/類
public CanvasTransformer zoom(final int openedX, final int closedX, 
		final int openedY, final int closedY,
		final int px, final int py, final Interpolator interp) {
	initTransformer();
	mTrans = new CanvasTransformer() {
		public void transformCanvas(Canvas canvas, float percentOpen) {
			mTrans.transformCanvas(canvas, percentOpen);
			float f = interp.getInterpolation(percentOpen);
			canvas.scale((openedX - closedX) * f + closedX,
					(openedY - closedY) * f + closedY, px, py);
		}			
	};
	return mTrans;
}
 
開發者ID:ChenTianSaber,項目名稱:DailyZhiHu,代碼行數:15,代碼來源:CanvasTransformerBuilder.java


注:本文中的android.graphics.Canvas.scale方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。