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


Java Matrix类代码示例

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


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

示例1: setDisplayMatrix

import android.graphics.Matrix; //导入依赖的package包/类
@Override
public boolean setDisplayMatrix(Matrix finalMatrix) {
    if (finalMatrix == null)
        throw new IllegalArgumentException("Matrix cannot be null");

    ImageView imageView = getImageView();
    if (null == imageView)
        return false;

    if (null == imageView.getDrawable())
        return false;

    mSuppMatrix.set(finalMatrix);
    setImageViewMatrix(getDrawMatrix());
    checkMatrixBounds();

    return true;
}
 
开发者ID:snowwolf10285,项目名称:PicShow-zhaipin,代码行数:19,代码来源:PhotoViewAttacher.java

示例2: RotateLoadingLayout

import android.graphics.Matrix; //导入依赖的package包/类
public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
	super(context, mode, scrollDirection, attrs);

	mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true);

	mHeaderImage.setScaleType(ScaleType.MATRIX);
	mHeaderImageMatrix = new Matrix();
	mHeaderImage.setImageMatrix(mHeaderImageMatrix);

	mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
			0.5f);
	mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
	mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION);
	mRotateAnimation.setRepeatCount(Animation.INFINITE);
	mRotateAnimation.setRepeatMode(Animation.RESTART);
}
 
开发者ID:ultrasonic,项目名称:ultrasonic,代码行数:17,代码来源:RotateLoadingLayout.java

示例3: onPreviewSizeChosen

import android.graphics.Matrix; //导入依赖的package包/类
public void onPreviewSizeChosen(final Size size, final int rotation) {

    previewWidth = size.getWidth();
    previewHeight = size.getHeight();

    final Display display = getWindowManager().getDefaultDisplay();
    final int screenOrientation = display.getRotation();

    LOGGER.i("Sensor orientation: %d, Screen orientation: %d", rotation, screenOrientation);

    sensorOrientation = rotation + screenOrientation;

    LOGGER.i("Initializing at size %dx%d", previewWidth, previewHeight);
    rgbBytes = new int[previewWidth * previewHeight];
    rgbFrameBitmap = Bitmap.createBitmap(previewWidth, previewHeight, Bitmap.Config.ARGB_8888);
    croppedBitmap = Bitmap.createBitmap(INPUT_SIZE, INPUT_SIZE, Bitmap.Config.ARGB_8888);

    frameToCropTransform =
        ImageUtils.getTransformationMatrix(previewWidth, previewHeight, INPUT_SIZE, INPUT_SIZE,
            sensorOrientation, MAINTAIN_ASPECT);

    Matrix cropToFrameTransform = new Matrix();
    frameToCropTransform.invert(cropToFrameTransform);

    yuvBytes = new byte[3][];
  }
 
开发者ID:flipper83,项目名称:SortingHatAndroid,代码行数:27,代码来源:CameraActivity.java

示例4: 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(final int viewWidth, final int viewHeight) {
  final Activity activity = getActivity();
  if (null == textureView || null == previewSize || null == activity) {
    return;
  }
  final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
  final Matrix matrix = new Matrix();
  final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
  final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
  final float centerX = viewRect.centerX();
  final 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);
    final float scale =
        Math.max(
            (float) viewHeight / previewSize.getHeight(),
            (float) viewWidth / previewSize.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);
  }
  textureView.setTransform(matrix);
}
 
开发者ID:hpi-xnor,项目名称:android-image-classification,代码行数:34,代码来源:CameraConnectionFragment.java

示例5: drawIcon

import android.graphics.Matrix; //导入依赖的package包/类
@Override
public void drawIcon(Canvas canvas, float fraction, Drawable drawable, int colorOfIcon,
                     WidthAndHeightOfView widthAndHeightOfView) {
    int centerX = widthAndHeightOfView.getWidth() / 2;
    int centerY = widthAndHeightOfView.getHeight() / 2 - 150;
    canvas.save();
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    float newFraction = (fraction - 0.65f) / 0.35f;
    paint.setColor(Color.parseColor("#e53935"));
    canvas.drawCircle(centerX, centerY - 50, 100 * (1 - newFraction), paint);
    paint.setColor(Color.parseColor("#fdd835"));
    canvas.drawCircle(centerX -35, centerY + 35,100 * (1 - newFraction), paint);
    paint.setColor(Color.parseColor("#1e88e5"));
    canvas.drawCircle(centerX + 35, centerY + 35, 100 * (1 - newFraction), paint);
    canvas.restore();
    canvas.save();
    Path path = new Path();
    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    Matrix matrix = new Matrix();
    matrix.postScale(1.7f, 1.7f, centerX, centerY);
    canvas.concat(matrix);
    path.addCircle(centerX, centerY, bitmap.getHeight() * 1.5f * newFraction, Path.Direction.CW);
    canvas.clipPath(path);
    canvas.drawBitmap(bitmap, centerX - bitmap.getWidth() / 2, centerY - bitmap.getHeight() / 2, paint);
    canvas.restore();
}
 
开发者ID:JoshuaRogue,项目名称:FancyView,代码行数:27,代码来源:RYBDrawStrategyStateTwo.java

示例6: applyTransformation

import android.graphics.Matrix; //导入依赖的package包/类
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float fromDegrees = mFromDegrees;
    float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);

    final Matrix matrix = t.getMatrix();

    mCamera.save();
    switch (mRollType) {
        case ROLL_BY_X:
            mCamera.rotateX(degrees);
            break;
        case ROLL_BY_Y:
            mCamera.rotateY(degrees);
            break;
        case ROLL_BY_Z:
            mCamera.rotateZ(degrees);
            break;
    }
    mCamera.getMatrix(matrix);
    mCamera.restore();

    matrix.preTranslate(-mPivotX, -mPivotY);
    matrix.postTranslate(mPivotX, mPivotY);
}
 
开发者ID:weimin96,项目名称:shareNote,代码行数:26,代码来源:Rotate3dAnimation.java

示例7: zoomOut

import android.graphics.Matrix; //导入依赖的package包/类
protected void zoomOut(float rate) {
    if (bitmapDisplayed.getBitmap() == null) {
        return;
    }

    float cx = getWidth() / 2F;
    float cy = getHeight() / 2F;

    // Zoom out to at most 1x
    Matrix tmp = new Matrix(suppMatrix);
    tmp.postScale(1F / rate, 1F / rate, cx, cy);

    if (getScale(tmp) < 1F) {
        suppMatrix.setScale(1F, 1F, cx, cy);
    } else {
        suppMatrix.postScale(1F / rate, 1F / rate, cx, cy);
    }
    setImageMatrix(getImageViewMatrix());
    center();
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:21,代码来源:ImageViewTouchBase.java

示例8: limitTranslation

import android.graphics.Matrix; //导入依赖的package包/类
/**
 * Limits the translation so that there are no empty spaces on the sides if possible.
 *
 * <p> The image is attempted to be centered within the view bounds if the transformed image is
 * smaller. There will be no empty spaces within the view bounds if the transformed image is
 * bigger. This applies to each dimension (horizontal and vertical) independently.
 *
 * @param limitTypes whether to limit translation along the specific axis.
 * @return whether limiting has been applied or not
 */
private boolean limitTranslation(Matrix transform, @LimitFlag int limitTypes) {
  if (!shouldLimit(limitTypes, LIMIT_TRANSLATION_X | LIMIT_TRANSLATION_Y)) {
    return false;
  }
  RectF b = mTempRect;
  b.set(mImageBounds);
  transform.mapRect(b);
  float offsetLeft = shouldLimit(limitTypes, LIMIT_TRANSLATION_X) ?
      getOffset(b.left, b.right, mViewBounds.left, mViewBounds.right, mImageBounds.centerX()) : 0;
  float offsetTop = shouldLimit(limitTypes, LIMIT_TRANSLATION_Y) ?
      getOffset(b.top, b.bottom, mViewBounds.top, mViewBounds.bottom, mImageBounds.centerY()) : 0;
  if (offsetLeft != 0 || offsetTop != 0) {
    transform.postTranslate(offsetLeft, offsetTop);
    return true;
  }
  return false;
}
 
开发者ID:idisfkj,项目名称:Zoomable,代码行数:28,代码来源:DefaultZoomableController.java

示例9: drawTexture

import android.graphics.Matrix; //导入依赖的package包/类
/**
 * Draws a VideoFrame.TextureBuffer. Calls either drawer.drawOes or drawer.drawRgb
 * depending on the type of the buffer. You can supply an additional render matrix. This is
 * used multiplied together with the transformation matrix of the frame. (M = renderMatrix *
 * transformationMatrix)
 */
static void drawTexture(RendererCommon.GlDrawer drawer, VideoFrame.TextureBuffer buffer,
    Matrix renderMatrix, int frameWidth, int frameHeight, int viewportX, int viewportY,
    int viewportWidth, int viewportHeight) {
  Matrix finalMatrix = new Matrix(buffer.getTransformMatrix());
  finalMatrix.preConcat(renderMatrix);
  float[] finalGlMatrix = RendererCommon.convertMatrixFromAndroidGraphicsMatrix(finalMatrix);
  switch (buffer.getType()) {
    case OES:
      drawer.drawOes(buffer.getTextureId(), finalGlMatrix, frameWidth, frameHeight, viewportX,
          viewportY, viewportWidth, viewportHeight);
      break;
    case RGB:
      drawer.drawRgb(buffer.getTextureId(), finalGlMatrix, frameWidth, frameHeight, viewportX,
          viewportY, viewportWidth, viewportHeight);
      break;
    default:
      throw new RuntimeException("Unknown texture type.");
  }
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:26,代码来源:VideoFrameDrawer.java

示例10: 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:tkrworks,项目名称:JinsMemeBRIDGE-Android,代码行数:33,代码来源:Camera2BasicFragment.java

示例11: scaleImage

import android.graphics.Matrix; //导入依赖的package包/类
public static Bitmap scaleImage(Bitmap bitmap, int boxSize){
    if (boxSize == 0)
        return null;

    // Determine how much to scale: the dimension requiring less scaling is
    // closer to the its side. This way the image always stays inside your
    // bounding box AND either x/y axis touches it.
    float xScale = ((float) boxSize) / bitmap.getWidth();
    float yScale = ((float) boxSize) / bitmap.getHeight();
    float scale = (xScale <= yScale) ? xScale : yScale;

    // Create a matrix for the scaling and add the scaling data
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);

    // Create a new bitmap and convert it to a format understood by the ImageView
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:19,代码来源:ImageUtils.java

示例12: rotateAndFlipBitmapInt

import android.graphics.Matrix; //导入依赖的package包/类
/**
 * Rotate the given bitmap by the given degrees.<br>
 * New bitmap is created and the old one is recycled.
 */
private static Bitmap rotateAndFlipBitmapInt(
    Bitmap bitmap, int degrees, boolean flipHorizontally, boolean flipVertically) {
  if (degrees > 0 || flipHorizontally || flipVertically) {
    Matrix matrix = new Matrix();
    matrix.setRotate(degrees);
    matrix.postScale(flipHorizontally ? -1 : 1, flipVertically ? -1 : 1);
    Bitmap newBitmap =
        Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
    if (newBitmap != bitmap) {
      bitmap.recycle();
    }
    return newBitmap;
  } else {
    return bitmap;
  }
}
 
开发者ID:prashantsaini1,项目名称:android-titanium-imagecropper,代码行数:21,代码来源:BitmapUtils.java

示例13: configureTransform

import android.graphics.Matrix; //导入依赖的package包/类
/**
 * Configures the necessary {@link Matrix} transformation to `mTextureView`.
 * This method should not to be called until the camera preview size is determined in
 * openCamera, or until 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);
    }
    mTextureView.setTransform(matrix);
}
 
开发者ID:CommonsLab,项目名称:CommonsLab,代码行数:31,代码来源:Camera2VideoFragment.java

示例14: 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(final int viewWidth, final int viewHeight) {
    if (mPreviewSize == null) return;

    final int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
    final Matrix matrix = new Matrix();
    final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    final RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    final float centerX = viewRect.centerX();
    final 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);
        final 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);
    }
    mAutoFitTextureView.setTransform(matrix);
}
 
开发者ID:kevalpatel2106,项目名称:smart-lens,代码行数:30,代码来源:Camera2Api.java

示例15: 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) {
    if (isViewAvailable()) {
        if (null == activityView.getTextureView()) {
            return;
        }
        int rotation = activityView.getWindowManager().getDefaultDisplay().getRotation();
        Matrix matrix = new Matrix();
        RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
        RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.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 / previewSize.getHeight(),
                    (float) viewWidth / previewSize.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);
        }
        activityView.getTextureView().setTransform(matrix);
    }
}
 
开发者ID:raulh82vlc,项目名称:Image-Detection-Samples,代码行数:34,代码来源:FDCamera2Presenter.java


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