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


Java Matrix.preScale方法代码示例

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


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

示例1: doubleClick

import android.graphics.Matrix; //导入方法依赖的package包/类
private void doubleClick(MotionEvent event) {
    // this is still broken
    if (DOUBLE_TAP_FATBITS) {
        final float density = mSlate.getDrawingDensity();
        final float scale = 1f/density;
        final Matrix m = new Matrix();
        mTouchPointDoc[0] = mTouchPointDoc[1] = 0f;
        if (getScale(mSlate.getZoom()) == scale) {
            getCenter(event, mTouchPoint);
            mTouchPoint[0] *= density;
            mTouchPoint[1] *= density;
            mTouchPointDoc[0] = mTouchPoint[0] - mSlate.getZoomPosX();
            mTouchPointDoc[1] = mTouchPoint[1] - mSlate.getZoomPosY();
            mSlate.getZoomInv().mapPoints(mTouchPointDoc);
            m.preScale(scale*DOUBLE_TAP_ZOOM_LEVEL, scale*DOUBLE_TAP_ZOOM_LEVEL);

            mSlate.setZoomPosNoInval(mTouchPointDoc);
            mSlate.setZoom(m);
        } else {
            mSlate.resetZoom();
        }
    }
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:24,代码来源:ZoomTouchView.java

示例2: makeReflectionImage

import android.graphics.Matrix; //导入方法依赖的package包/类
public static Bitmap makeReflectionImage(Bitmap bitmap) {
    int reflectionGap = 4;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height/2, width, height/2, matrix,
            false);
    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height/2),
            Bitmap.Config.ARGB_8888);
    Paint defaultPaint = new Paint();
    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    canvas.drawRect(0, height,width,height + reflectionGap, defaultPaint);
    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
            bitmapWithReflection.getHeight()+reflectionGap, 0x70FFFFFF, 0x00FFFFFF,
            Shader.TileMode.CLAMP);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()+reflectionGap, paint);
    return bitmapWithReflection;
}
 
开发者ID:JackWHLiu,项目名称:jackknife,代码行数:25,代码来源:ImageUtils.java

示例3: mirrorImage

import android.graphics.Matrix; //导入方法依赖的package包/类
public void mirrorImage() throws ImageMutationFailedException {
    Matrix m = new Matrix();

    m.preScale(-1, 1);

    Bitmap bitmap = Bitmap.createBitmap(
            currentRepresentation,
            0,
            0,
            currentRepresentation.getWidth(),
            currentRepresentation.getHeight(),
            m,
            false
    );

    if (bitmap == null)
        throw new ImageMutationFailedException("failed to mirror");

    this.currentRepresentation = bitmap;
}
 
开发者ID:entria,项目名称:react-native-camera-face-detector,代码行数:21,代码来源:MutableImage.java

示例4: drawSun

import android.graphics.Matrix; //导入方法依赖的package包/类
private void drawSun(Canvas canvas, int width, int height) {
        Matrix matrix = mMatrix;
        matrix.reset();


        float mSunLeftOffset = 0.3f * (float) width;
        float mSunTopOffset = (mHeaderHeight * 0.1f);

        float sunRadius = (float) mSunSize / 2.0f;
        float offsetX = mSunLeftOffset + sunRadius;
        float offsetY = mSunTopOffset + (mHeaderHeight / 2) * (1.0f - Math.min(mPercent, 1)); // Move the sun up

        int bWidth = mDrawableSun.width();
        float sunScale = 1f * mSunSize / bWidth;

        if (mPercent > 1) {
            sunScale = sunScale * (1.0f - 0.5f * (mPercent - 1));
            sunRadius = sunRadius * (1.0f - 0.5f * (mPercent - 1));
        }

        matrix.preScale(sunScale, sunScale);
        matrix.postRotate((isRefreshing ? -360 : 360) * mRotate * (isRefreshing ? 1 : SUN_INITIAL_ROTATE_GROWTH),
                sunRadius,
                sunRadius);

//        canvas.save();
//        canvas.translate(offsetX, offsetY);
//        canvas.drawBitmap(mSun, matrix, null);
//        canvas.restore();

        final int saveCount = canvas.getSaveCount();
        canvas.save();
        canvas.translate(offsetX, offsetY);
        canvas.concat(matrix);
        mDrawableSun.draw(canvas);
        canvas.restoreToCount(saveCount);
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:38,代码来源:PhoenixHeader.java

示例5: createTransformationMatrix

import android.graphics.Matrix; //导入方法依赖的package包/类
private Matrix createTransformationMatrix (int size) {
    Matrix matrix = new Matrix();

    // get size of original image and calculate padding
    float inputImageHeight = (float)mInputImage.getHeight();
    float inputImageWidth = (float)mInputImage.getWidth();
    float padding = (float)size/4;

    // define variables needed for transformation matrix
    float aspectRatio = 0.0f;
    float xTranslation = 0.0f;
    float yTranslation = 0.0f;

    // landscape format and square
    if (inputImageWidth >= inputImageHeight) {
        aspectRatio = (size - padding*2) / inputImageWidth;
        xTranslation = 0.0f + padding;
        yTranslation = (size - inputImageHeight * aspectRatio)/2.0f;
    }
    // portrait format
    else if (inputImageHeight > inputImageWidth) {
        aspectRatio = (size - padding*2) / inputImageHeight;
        yTranslation = 0.0f + padding;
        xTranslation = (size - inputImageWidth * aspectRatio)/2.0f;
    }

    // construct transformation matrix
    matrix.postTranslate(xTranslation, yTranslation);
    matrix.preScale(aspectRatio, aspectRatio);

    return matrix;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:33,代码来源:ImageHelper.java

示例6: addReflection

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * 添加倒影
 *
 * @param src              源图片的
 * @param reflectionHeight 倒影高度
 * @param recycle          是否回收
 * @return 带倒影图片
 */
public static Bitmap addReflection(final Bitmap src,
                                   final int reflectionHeight,
                                   final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    // 原图与倒影之间的间距
    final int REFLECTION_GAP = 0;
    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight - reflectionHeight,
            srcWidth, reflectionHeight, matrix, false);
    Bitmap ret = Bitmap.createBitmap(srcWidth, srcHeight + reflectionHeight, src.getConfig());
    Canvas canvas = new Canvas(ret);
    canvas.drawBitmap(src, 0, 0, null);
    canvas.drawBitmap(reflectionBitmap, 0, srcHeight + REFLECTION_GAP, null);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    LinearGradient shader = new LinearGradient(
            0, srcHeight,
            0, ret.getHeight() + REFLECTION_GAP,
            0x70FFFFFF,
            0x00FFFFFF,
            Shader.TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN));
    canvas.drawRect(0, srcHeight + REFLECTION_GAP, srcWidth, ret.getHeight(), paint);
    if (!reflectionBitmap.isRecycled()) reflectionBitmap.recycle();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:39,代码来源:ImageUtils.java

示例7: scaleBitmap

import android.graphics.Matrix; //导入方法依赖的package包/类
private Bitmap scaleBitmap(Bitmap origin, float ratio) {
    if (origin == null) {
        return null;
    }
    int width = origin.getWidth();
    int height = origin.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(ratio, ratio);
    Bitmap newBM = Bitmap.createBitmap(origin, 0, 0, width, height, matrix, false);
    if (newBM.equals(origin)) {
        return newBM;
    }
    origin.recycle();
    return newBM;
}
 
开发者ID:MarcusMa,项目名称:MyCreditCardDemo,代码行数:16,代码来源:CmbChinaLoginActivity.java

示例8: drawOverlay

import android.graphics.Matrix; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public synchronized void drawOverlay(final GL10 gl,
    final Size cameraViewSize, final Matrix matrix) {
  final Matrix tempMatrix = new Matrix(matrix);
  tempMatrix.preScale(DOWNSAMPLE_FACTOR, DOWNSAMPLE_FACTOR);
  tempMatrix.getValues(matrixValues);
  drawNative(cameraViewSize.width, cameraViewSize.height, matrixValues);
}
 
开发者ID:apacha,项目名称:TensorflowAndroidDemo,代码行数:9,代码来源:ObjectTracker.java

示例9: createTransformationMatrix

import android.graphics.Matrix; //导入方法依赖的package包/类
private Matrix createTransformationMatrix (int size) {
    Matrix matrix = new Matrix();

    // get size of original image and calculate padding
    float inputImageHeight = (float)mInputImage.getHeight();
    float inputImageWidth = (float)mInputImage.getWidth();
    float padding = (float)size/32;

    // define variables needed for transformation matrix
    float aspectRatio = 0.0f;
    float xTranslation = 0.0f;
    float yTranslation = 0.0f;

    // landscape format and square
    if (inputImageWidth >= inputImageHeight) {
        aspectRatio = (size - padding*2) / inputImageWidth;
        xTranslation = 0.0f + padding;
        yTranslation = (size - inputImageHeight * aspectRatio)/2.0f;
    }
    // portrait format
    else if (inputImageHeight > inputImageWidth) {
        aspectRatio = (size - padding*2) / inputImageHeight;
        yTranslation = 0.0f + padding;
        xTranslation = (size - inputImageWidth * aspectRatio)/2.0f;
    }

    // construct transformation matrix
    matrix.postTranslate(xTranslation, yTranslation);
    matrix.preScale(aspectRatio, aspectRatio);

    return matrix;
}
 
开发者ID:malah-code,项目名称:Open-Quran-Radio,代码行数:33,代码来源:ImageHelper.java

示例10: getFrameBitmap

import android.graphics.Matrix; //导入方法依赖的package包/类
public Bitmap getFrameBitmap() {
    if (!mEglCore.isCurrent(mEGLSurface)) {
        throw new RuntimeException("Expected EGL context/surface is not current");
    }

    // glReadPixels fills in a "direct" ByteBuffer with what is essentially big-endian RGBA
    // data (i.e. a byte of red, followed by a byte of green...).  While the Bitmap
    // constructor that takes an int[] wants little-endian ARGB (blue/red swapped), the
    // Bitmap "copy pixels" method wants the same format GL provides.
    //
    // Ideally we'd have some way to re-use the ByteBuffer, especially if we're calling
    // here often.
    //
    // Making this even more interesting is the upside-down nature of GL, which means
    // our output will look upside down relative to what appears on screen if the
    // typical GL conventions are used.

    int width = getWidth();
    int height = getHeight();
    ByteBuffer buf = ByteBuffer.allocateDirect(width * height * 4);
    buf.order(ByteOrder.LITTLE_ENDIAN);
    GLES20.glReadPixels(0, 0, width, height,
            GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buf);
    //GlUtil.checkGlError("glReadPixels");
    buf.rewind();

    Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bmp.copyPixelsFromBuffer(buf);

    Matrix matrix = new Matrix();
    matrix.preScale(1f, -1f);
    Bitmap bmp2 = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, false);

    bmp.recycle();
    bmp = null;
    return bmp2;
}
 
开发者ID:vipycm,项目名称:mao-android,代码行数:38,代码来源:EglSurfaceBase.java

示例11: reverseByHorizontal

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * 水平翻转图片
 *
 * @param bitmap 原图
 * @return 水平翻转后的图片
 */
public static Bitmap reverseByHorizontal(Bitmap bitmap) {
    Matrix matrix = new Matrix();
    matrix.preScale(-1, 1);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
            bitmap.getHeight(), matrix, false);
}
 
开发者ID:youth5201314,项目名称:XFrame,代码行数:13,代码来源:XBitmapUtils.java

示例12: resizeBitmapByCanvas

import android.graphics.Matrix; //导入方法依赖的package包/类
public Bitmap resizeBitmapByCanvas() {
    float width;
    float heigth;
    float orginalWidth = (float) originalBitmap.getWidth();
    float orginalHeight = (float) originalBitmap.getHeight();
    if (orginalWidth > orginalHeight) {
        width = (float) imageViewWidth;
        heigth = (((float) imageViewWidth) * orginalHeight) / orginalWidth;
    } else {
        heigth = (float) imageViewHeight;
        width = (((float) imageViewHeight) * orginalWidth) / orginalHeight;
    }
    if (width > orginalWidth || heigth > orginalHeight) {
        return originalBitmap;
    }
    Bitmap background = Bitmap.createBitmap((int) width, (int) heigth, Config.ARGB_8888);
    Canvas canvas = new Canvas(background);
    float scale = width / orginalWidth;
    float yTranslation = (heigth - (orginalHeight * scale)) / 2.0f;
    Matrix transformation = new Matrix();
    transformation.postTranslate(0.0f, yTranslation);
    transformation.preScale(scale, scale);
    Paint paint = new Paint();
    paint.setFilterBitmap(true);
    canvas.drawBitmap(originalBitmap, transformation, paint);
    this.isImageResized = true;
    return background;
}
 
开发者ID:asif-patel,项目名称:ImageEraser,代码行数:29,代码来源:MainActivity.java

示例13: resizeBitmapByCanvas

import android.graphics.Matrix; //导入方法依赖的package包/类
public Bitmap resizeBitmapByCanvas() {
    float width;
    float height;
    float originalWidth = (float) this.originalBitmap.getWidth();
    float originalHeight = (float) this.originalBitmap.getHeight();
    if (originalWidth > originalHeight) {
        width = (float) this.containerWidth;
        height = (((float) this.containerWidth) * originalHeight) / originalWidth;
    } else {
        height = (float) this.containerHeight;
        width = (((float) this.containerHeight) * originalWidth) / originalHeight;
    }
    if (width > originalWidth || height > originalHeight) {
        return this.originalBitmap;
    }
    Bitmap background = Bitmap.createBitmap((int) width, (int) height, Config.ARGB_8888);
    Canvas canvas = new Canvas(background);
    float scale = width / originalWidth;
    float yTranslation = (height - (originalHeight * scale)) / 2.0f;
    Matrix transformation = new Matrix();
    transformation.postTranslate(0.0f, yTranslation);
    transformation.preScale(scale, scale);
    Paint paint = new Paint();
    paint.setFilterBitmap(true);
    canvas.drawBitmap(this.originalBitmap, transformation, paint);
    return background;
}
 
开发者ID:asif-patel,项目名称:ImageMagnifier,代码行数:28,代码来源:MainActivity.java

示例14: 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

示例15: addReflection

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * 添加倒影
 *
 * @param src              源图片的
 * @param reflectionHeight 倒影高度
 * @param recycle          是否回收
 * @return 带倒影图片
 */
public static Bitmap addReflection(Bitmap src, int reflectionHeight, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    // 原图与倒影之间的间距
    final int REFLECTION_GAP = 0;
    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight - reflectionHeight,
            srcWidth, reflectionHeight, matrix, false);
    Bitmap ret = Bitmap.createBitmap(srcWidth, srcHeight + reflectionHeight, src.getConfig());
    Canvas canvas = new Canvas(ret);
    canvas.drawBitmap(src, 0, 0, null);
    canvas.drawBitmap(reflectionBitmap, 0, srcHeight + REFLECTION_GAP, null);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    LinearGradient shader = new LinearGradient(0, srcHeight,
            0, ret.getHeight() + REFLECTION_GAP,
            0x70FFFFFF, 0x00FFFFFF, Shader.TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    canvas.drawRect(0, srcHeight + REFLECTION_GAP,
            srcWidth, ret.getHeight(), paint);
    if (!reflectionBitmap.isRecycled()) reflectionBitmap.recycle();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
开发者ID:tututututututu,项目名称:BaseCore,代码行数:36,代码来源:ImageUtils.java


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