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


Java Matrix.setTranslate方法代码示例

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


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

示例1: onSizeChanged

import android.graphics.Matrix; //导入方法依赖的package包/类
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    mScaledBitmap = Bitmap.createScaledBitmap(mOriBitmap, w, h, true);
    mRippleScaledBitmap = Bitmap.createScaledBitmap(mOriBitmap,
            (int) (w * RIPPLE_SCALE_FACTOR), (int) (h * RIPPLE_SCALE_FACTOR), true);
    int width1 = mScaledBitmap.getWidth();
    int height1 = mScaledBitmap.getHeight();
    int width2 = mRippleScaledBitmap.getWidth();
    int height2 = mRippleScaledBitmap.getHeight();
    mDisW = Math.abs(width1 - width2) / 2;
    mDisH = Math.abs(height1 - height2) / 2;//算出两图中点相聚的距离,就是放大后需要矫正的位移距离
    mOriBitmap.recycle();
    mOriBitmap = null;
    //这里的模式无所谓,因为在屏幕外看不到
    mBitmapShader = new BitmapShader(mRippleScaledBitmap,
            Shader.TileMode.MIRROR,//这里的模式无所谓,因为在屏幕外看不到
            Shader.TileMode.MIRROR);
    Matrix matrix = new Matrix();
    matrix.setTranslate(-mDisW, -mDisH);
    mBitmapShader.setLocalMatrix(matrix);
}
 
开发者ID:halohoop,项目名称:AndroidDigIn,代码行数:23,代码来源:RadialGradientRippleView.java

示例2: setBackground

import android.graphics.Matrix; //导入方法依赖的package包/类
public static void setBackground(View v, Bitmap bm) {

        if (bm == null) {
            v.setBackgroundResource(0);
            return;
        }

        int vwidth = v.getWidth()/4;
        int vheight = v.getHeight()/4;
        int bwidth = bm.getWidth();
        int bheight = bm.getHeight();
        float scalex = (float) vwidth / bwidth;
        float scaley = (float) vheight / bheight;
        float scale = Math.max(scalex, scaley) * 1.3f;

        Bitmap.Config config = Bitmap.Config.ARGB_8888;
        Bitmap bg = Bitmap.createBitmap(vwidth, vheight, config);
        Canvas c = new Canvas(bg);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);
        ColorMatrix greymatrix = new ColorMatrix();
        greymatrix.setSaturation(0);
        ColorMatrix darkmatrix = new ColorMatrix();
        darkmatrix.setScale(1f, 1f, 1f, .1f);
        greymatrix.postConcat(darkmatrix);
        ColorFilter filter = new ColorMatrixColorFilter(greymatrix);
        paint.setColorFilter(filter);
        Matrix matrix = new Matrix();
        matrix.setTranslate(-bwidth/2, -bheight/2); // move bitmap center to origin
        matrix.postRotate(10);
        matrix.postScale(scale, scale);
        matrix.postTranslate(vwidth/2, vheight/2);  // Move bitmap center to view center
        c.drawBitmap(bm, matrix, paint);
        v.setBackgroundDrawable(new BitmapDrawable(bg));
    }
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:37,代码来源:Utils.java

示例3: toRound

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * 转为圆形图片
 *
 * @param src         源图片
 * @param recycle     是否回收
 * @param borderSize  边框尺寸
 * @param borderColor 边框颜色
 * @return 圆形图片
 */
public static Bitmap toRound(final Bitmap src,
                             @IntRange(from = 0) int borderSize,
                             @ColorInt int borderColor,
                             final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    int size = Math.min(width, height);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
    float center = size / 2f;
    RectF rectF = new RectF(0, 0, width, height);
    rectF.inset((width - size) / 2f, (height - size) / 2f);
    Matrix matrix = new Matrix();
    matrix.setTranslate(rectF.left, rectF.top);
    matrix.preScale((float) size / width, (float) size / height);
    BitmapShader shader = new BitmapShader(src, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    shader.setLocalMatrix(matrix);
    paint.setShader(shader);
    Canvas canvas = new Canvas(ret);
    canvas.drawRoundRect(rectF, center, center, paint);
    if (borderSize > 0) {
        paint.setShader(null);
        paint.setColor(borderColor);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(borderSize);
        float radius = center - borderSize / 2f;
        canvas.drawCircle(width / 2f, height / 2f, radius, paint);
    }
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:42,代码来源:ImageUtils.java

示例4: 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 dx = parentRect.left + (parentRect.width() - childWidth) * 0.5f;
  float dy = parentRect.top + (parentRect.height() - childHeight) * 0.5f;
  outTransform.setTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:ScalingUtils.java

示例5: createBitmap

import android.graphics.Matrix; //导入方法依赖的package包/类
private Bitmap createBitmap(int x, int y, int w, int h) {
    Bitmap newBimap = delegate.getBitmap();
    if (newBimap != null) {
        bitmapToEdit = newBimap;
    }

    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);

    Matrix matrix = new Matrix();
    matrix.setTranslate(-bitmapToEdit.getWidth() / 2, -bitmapToEdit.getHeight() / 2);
    matrix.postRotate(orientation);
    if (orientation % 360 == 90 || orientation % 360 == 270) {
        matrix.postTranslate(bitmapToEdit.getHeight() / 2 - x, bitmapToEdit.getWidth() / 2 - y);
    } else {
        matrix.postTranslate(bitmapToEdit.getWidth() / 2 - x, bitmapToEdit.getHeight() / 2 - y);
    }
    canvas.drawBitmap(bitmapToEdit, matrix, paint);
    try {
        canvas.setBitmap(null);
    } catch (Exception e) {
        //don't promt, this will crash on 2.x
    }

    return bitmap;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:28,代码来源:PhotoCropView.java

示例6: updateScale

import android.graphics.Matrix; //导入方法依赖的package包/类
private void updateScale() {
    Drawable d = getDrawable();
    if(d instanceof BitmapDrawable) {
        BitmapDrawable bd = (BitmapDrawable) d;

        // Don't upscale if more than 2x larger
        if (getWidth() > mMaxScale * bd.getIntrinsicWidth()
                && getHeight() > mMaxScale * bd.getIntrinsicHeight()) {
            setScaleType(ScaleType.MATRIX);
            Matrix trans = new Matrix();
            Matrix scale = new Matrix();
            trans.setTranslate((getWidth() - mMaxScale * bd.getIntrinsicWidth())/2, (getHeight() - mMaxScale * bd.getIntrinsicHeight())/2);
            scale.setScale(mMaxScale, mMaxScale);
            Matrix m = new Matrix();
            
            if(isInEditMode()) {
                // WTF? Edit mode consider inversed matrix??
                m.setConcat(scale, trans);
            }else {
                m.setConcat(trans, scale);
            }
            setImageMatrix(m);
        }else {
            setScaleType(ScaleType.CENTER_CROP);
        }
    }
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:28,代码来源:MaxScaleImageView.java

示例7: drawCirclesAndText

import android.graphics.Matrix; //导入方法依赖的package包/类
private void drawCirclesAndText(int index, Canvas canvas) {
    boolean current = (index == mCurrentRank);

    int centerX = index * 2 * smallRadius + smallRadius - index * offset * 2;

    if (current) {
        centerX += bigRadius - smallRadius;
    } else if (index > mCurrentRank) {
        centerX += 2 * (bigRadius - smallRadius);
    }

    if (index <= mCurrentRank) {
        currentShader = current ? bigPicShaders.get(index) : smallPicShaders.get(index);

        if (currentShader != null) {
            Matrix matrix = new Matrix();
            matrix.setTranslate(centerX - (current ? getBigRadius() : getSmallRadius()), current ? 0 : getBigRadius() - getSmallRadius());
            currentShader.setLocalMatrix(matrix);
            mCirclePaint.setShader(currentShader);
        }
    } else {
        mCirclePaint.setShader(null);
    }

    int radius = current ? bigRadius : smallRadius;

    canvas.drawCircle(centerX, centerY, radius, mCirclePaint);
    canvas.drawCircle(centerX, centerY, radius, mCircleBorderPaint);

    if (!current) {
        mTextPaint.setTextSize(getResources().getDimension(R.dimen.rank_default_text_size));
        mTextPaint.getTextBounds("4", 0, 1, mBounds);
        canvas.drawText(String.valueOf(index + 1), centerX, centerY + mBounds.height() / 2, mTextPaint);
    }
}
 
开发者ID:stockx,项目名称:bubble-rank,代码行数:36,代码来源:BubbleRank.java

示例8: toRound

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * 转为圆形图片
 *
 * @param src         源图片
 * @param recycle     是否回收
 * @param borderSize  边框尺寸
 * @param borderColor 边框颜色
 * @return 圆形图片
 */
public static Bitmap toRound(final Bitmap src, int borderSize, int borderColor, final boolean recycle) {
	if (isEmptyBitmap(src)) {
		return null;
	}
	int width = src.getWidth();
	int height = src.getHeight();
	int size = Math.min(width, height);
	Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
	Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
	float center = size / 2f;
	RectF rectF = new RectF(0, 0, width, height);
	rectF.inset((width - size) / 2f, (height - size) / 2f);
	Matrix matrix = new Matrix();
	matrix.setTranslate(rectF.left, rectF.top);
	matrix.preScale((float) size / width, (float) size / height);
	BitmapShader shader = new BitmapShader(src, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
	shader.setLocalMatrix(matrix);
	paint.setShader(shader);
	Canvas canvas = new Canvas(ret);
	canvas.drawRoundRect(rectF, center, center, paint);
	if (borderSize > 0) {
		paint.setShader(null);
		paint.setColor(borderColor);
		paint.setStyle(Paint.Style.STROKE);
		paint.setStrokeWidth(borderSize);
		float radius = center - borderSize / 2f;
		canvas.drawCircle(width / 2f, height / 2f, radius, paint);
	}
	if (recycle && !src.isRecycled()) {
		src.recycle();
	}
	return ret;
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:43,代码来源:ImageUtils.java

示例9: transform

import android.graphics.Matrix; //导入方法依赖的package包/类
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();
  int size = Math.min(source.getWidth(), source.getHeight());

  int width = (source.getWidth() - size) / 2;
  int height = (source.getHeight() - size) / 2;

  Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
  }

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  BitmapShader shader =
      new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
  if (width != 0 || height != 0) {
    // source isn't square, move viewport to center
    Matrix matrix = new Matrix();
    matrix.setTranslate(-width, -height);
    shader.setLocalMatrix(matrix);
  }
  paint.setShader(shader);
  paint.setAntiAlias(true);

  float r = size / 2f;
  canvas.drawCircle(r, r, r, paint);

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
 
开发者ID:open-android,项目名称:Glide-transformations,代码行数:32,代码来源:CropCircleTransformation.java

示例10: transform

import android.graphics.Matrix; //导入方法依赖的package包/类
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();
    int size = Math.min(source.getWidth(), source.getHeight());

    int width = (source.getWidth() - size) / 2;
    int height = (source.getHeight() - size) / 2;

    Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    BitmapShader shader =
            new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
    if (width != 0 || height != 0) {
        Matrix matrix = new Matrix();
        matrix.setTranslate(-width, -height);
        shader.setLocalMatrix(matrix);
    }
    paint.setShader(shader);
    paint.setAntiAlias(true);

    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);

    return BitmapResource.obtain(bitmap, mBitmapPool);
}
 
开发者ID:dengyuhan,项目名称:GlidePlus,代码行数:31,代码来源:BitmapCircleTransformation.java

示例11: setRectToRect

import android.graphics.Matrix; //导入方法依赖的package包/类
public static void setRectToRect(Matrix matrix, RectF src, RectF dst, int rotation, Matrix.ScaleToFit align) {
    float tx, sx;
    float ty, sy;
    if (rotation == 90 || rotation == 270) {
        sx = dst.height() / src.width();
        sy = dst.width() / src.height();
    } else {
        sx = dst.width() / src.width();
        sy = dst.height() / src.height();
    }
    if (align != Matrix.ScaleToFit.FILL) {
        if (sx > sy) {
            sx = sy;
        } else {
            sy = sx;
        }
    }
    tx = -src.left * sx;
    ty = -src.top * sy;

    matrix.setTranslate(dst.left, dst.top);
    if (rotation == 90) {
        matrix.preRotate(90);
        matrix.preTranslate(0, -dst.width());
    } else if (rotation == 180) {
        matrix.preRotate(180);
        matrix.preTranslate(-dst.width(), -dst.height());
    } else if (rotation == 270) {
        matrix.preRotate(270);
        matrix.preTranslate(-dst.height(), 0);
    }

    matrix.preScale(sx, sy);
    matrix.preTranslate(tx, ty);
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:36,代码来源:AndroidUtilities.java

示例12: GetCenterCropMatrix

import android.graphics.Matrix; //导入方法依赖的package包/类
public static Matrix GetCenterCropMatrix(RectF srcSize, RectF destSize){
    Matrix matrix = new Matrix();
    float scale = Math.max(destSize.width() / srcSize.width(),
            destSize.height() / srcSize.height());
    matrix.setTranslate(-(destSize.width() / 2), - (destSize.height() / 2));
    matrix.setScale(scale, scale);

    return matrix;
}
 
开发者ID:rosenpin,项目名称:QuickDrawEverywhere,代码行数:10,代码来源:MatrixUtils.java

示例13: transform

import android.graphics.Matrix; //导入方法依赖的package包/类
@Override public Bitmap transform(Bitmap source) {
  int size = Math.min(source.getWidth(), source.getHeight());

  int width = (source.getWidth() - size) / 2;
  int height = (source.getHeight() - size) / 2;

  Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  BitmapShader shader =
      new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
  if (width != 0 || height != 0) {
    // source isn't square, move viewport to center
    Matrix matrix = new Matrix();
    matrix.setTranslate(-width, -height);
    shader.setLocalMatrix(matrix);
  }
  paint.setShader(shader);
  paint.setAntiAlias(true);

  float r = size / 2f;
  canvas.drawCircle(r, r, r, paint);

  source.recycle();

  return bitmap;
}
 
开发者ID:open-android,项目名称:Picasso-transformations,代码行数:29,代码来源:CropCircleTransformation.java

示例14: drawFan

import android.graphics.Matrix; //导入方法依赖的package包/类
private void drawFan(Canvas canvas){
    int centerX = (int) mTotalProgressWidth;
    int centerY = 8;
    if(mProgress == 100){
        String text = "100%";
        canvas.drawText(text,centerX,mPicHeight/2+getTextHeight(text)/2,mFanPaint);
    }else{
        Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.fengshan);
        int bitmapWidth = bitmap.getWidth();
        int bitmapHeight = bitmap.getHeight();

        Matrix matrix = new Matrix();
        matrix.setTranslate(centerX, centerY);     //设置图片的原点坐标
        if (this.mProgress >= 95 && this.mProgress < 100){
            float scale = Math.abs(this.mProgress - 100) * 0.2f;
            //缩放 参数1:X轴缩放倍数,参数2:Y轴缩放倍数 参数3,4:缩放中心点
            matrix.preScale(scale,scale,(float)bitmapWidth/2, (float)bitmapHeight/2);
        }else{
            //旋转 参数1:角度,参数2,3:旋转中心点
            matrix.preRotate(mAngle, (float)bitmapWidth/2, (float)bitmapHeight/2);
        }
        canvas.drawBitmap(bitmap, matrix, mFanPaint);
        if (this.mProgress != 100){
            mAngle += 60;
        }
    }
}
 
开发者ID:hacjy,项目名称:LeafLoadingView,代码行数:28,代码来源:LeafLoadingView.java

示例15: calculateTypeAndScale

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * 设置最佳的运动类型
 * 计算缩放比例
 *
 * @return image scale.
 */
private float calculateTypeAndScale() {
    movementType = MovingViewAnimator.AUTO_MOVE;
    float scale = 1f;
    float scaleByImage = Math.max(imageWidth / canvasWidth, imageHeight / canvasHeight);
    Matrix matrix = new Matrix();

    if (offsetWidth == 0 && offsetHeight == 0) {//图片太小,无法动画,需要放大
        //画布宽度/图片宽度
        float sW = canvasWidth / imageWidth;
        //画布高度/图片高度
        float sH = canvasHeight / imageHeight;

        if (sW > sH) {
            scale = Math.min(sW, maxRelativeSize);//限定最大缩放值
            matrix.setTranslate((canvasWidth - imageWidth * scale) / 2f, 0);
            movementType = MovingViewAnimator.VERTICAL_MOVE;//垂直移动

        } else if (sW < sH) {
            scale = Math.min(sH, maxRelativeSize);//限定最大缩放值
            matrix.setTranslate(0, (canvasHeight - imageHeight * scale) / 2f);
            movementType = MovingViewAnimator.HORIZONTAL_MOVE;//水平移动

        } else {
            scale = Math.max(sW, maxRelativeSize);//限定最大缩放值
            movementType = (scale == sW) ? MovingViewAnimator.NONE_MOVE :
                    MovingViewAnimator.DIAGONAL_MOVE;//对角线移动
        }
    } else if (offsetWidth == 0) {//宽度太小,无法执行水平动画,放大宽度
        scale = canvasWidth / imageWidth;
        movementType = MovingViewAnimator.VERTICAL_MOVE;

    } else if (offsetHeight == 0) {//高度太小,无法执行垂直动画,放大高度
        scale = canvasHeight / imageHeight;//求出画布高度和图片高度的比值用于确定画布起始坐标
        movementType = MovingViewAnimator.HORIZONTAL_MOVE;

    } else if (scaleByImage > maxRelativeSize) {//图片太大,根据最大比值设定图片缩放值
        scale = maxRelativeSize / scaleByImage;
        if (imageWidth * scale < canvasWidth || imageHeight * scale < canvasHeight) {
            scale = Math.max(canvasWidth / imageWidth, canvasHeight / imageHeight);
        }
    }

    matrix.preScale(scale, scale);
    setImageMatrix(matrix);
    return scale;
}
 
开发者ID:Horrarndoo,项目名称:YiZhi,代码行数:53,代码来源:MovingImageView.java


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