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


Java Matrix.postTranslate方法代码示例

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


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

示例1: 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 scale = Math.min(scaleX, scaleY);
  float dx = parentRect.left;
  float dy = parentRect.top + (parentRect.height() - childHeight * scale);
  outTransform.setScale(scale, scale);
  outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:ScalingUtils.java

示例2: calculateZoomToPointTransform

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * Calculates the zoom transformation that would zoom to the desired scale and position the image
 * so that the given image point corresponds to the given view point.
 *
 * @param outTransform the matrix to store the result to
 * @param scale desired scale, will be limited to {min, max} scale factor
 * @param imagePoint 2D point in image's relative coordinate system (i.e. 0 <= x, y <= 1)
 * @param viewPoint 2D point in view's absolute coordinate system
 * @param limitFlags whether to limit translation and/or scale.
 * @return whether or not the transform has been corrected due to limitation
 */
protected boolean calculateZoomToPointTransform(
    Matrix outTransform,
    float scale,
    PointF imagePoint,
    PointF viewPoint,
    @LimitFlag int limitFlags) {
  float[] viewAbsolute = mTempValues;
  viewAbsolute[0] = imagePoint.x;
  viewAbsolute[1] = imagePoint.y;
  mapRelativeToAbsolute(viewAbsolute, viewAbsolute, 1);
  float distanceX = viewPoint.x - viewAbsolute[0];
  float distanceY = viewPoint.y - viewAbsolute[1];
  boolean transformCorrected = false;
  outTransform.setScale(scale, scale, viewAbsolute[0], viewAbsolute[1]);
  transformCorrected |= limitScale(outTransform, viewAbsolute[0], viewAbsolute[1], limitFlags);
  outTransform.postTranslate(distanceX, distanceY);
  transformCorrected |= limitTranslation(outTransform, limitFlags);
  return transformCorrected;
}
 
开发者ID:idisfkj,项目名称:Zoomable,代码行数:31,代码来源:DefaultZoomableController.java

示例3: renderDebug

import android.graphics.Matrix; //导入方法依赖的package包/类
private void renderDebug(final Canvas canvas) {
    if (!debug) {
        return;
    }
    final Bitmap copy = cropCopyBitmap;
    if (copy != null) {
        final Matrix matrix = new Matrix();
        final float scaleFactor = 2;
        matrix.postScale(scaleFactor, scaleFactor);
        matrix.postTranslate(
                canvas.getWidth() - copy.getWidth() * scaleFactor,
                canvas.getHeight() - copy.getHeight() * scaleFactor);
        canvas.drawBitmap(copy, matrix, new Paint());

        final Vector<String> lines = new Vector<>();

        lines.add("Frame: " + previewWidth + "x" + previewHeight);
        lines.add("Crop: " + copy.getWidth() + "x" + copy.getHeight());
        lines.add("View: " + canvas.getWidth() + "x" + canvas.getHeight());
        lines.add("Inference time: " + lasProcessingTimeMs + "ms");

        borderedText.drawLines(canvas, 10, canvas.getHeight() - 10, lines);
    }
}
 
开发者ID:hpi-xnor,项目名称:android-image-classification,代码行数:25,代码来源:MainActivity.java

示例4: rotateBitmap

import android.graphics.Matrix; //导入方法依赖的package包/类
public static Bitmap rotateBitmap(Bitmap bitmap, int rotation) {
    boolean reverseWidthHeight = ((rotation / 90) % 2) == 1;

    int width = reverseWidthHeight ? bitmap.getHeight() : bitmap.getWidth();
    int height = reverseWidthHeight ? bitmap.getWidth() : bitmap.getHeight();

    Bitmap.Config conf = Bitmap.Config.ARGB_8888;
    Bitmap newBitmap = Bitmap.createBitmap(width, height, conf);
    Canvas canvas = new Canvas(newBitmap);

    Matrix matrix = new Matrix();
    matrix.setRotate(rotation, bitmap.getWidth() / 2f, bitmap.getHeight() / 2f);
    matrix.postTranslate(
            canvas.getWidth() / 2f - bitmap.getWidth() / 2f,
            canvas.getHeight() / 2f - bitmap.getHeight() / 2f
    );

    canvas.drawBitmap(bitmap, matrix, new Paint());

    return newBitmap;
}
 
开发者ID:cuonghuynhvan,项目名称:react-native-camera-android-simple,代码行数:22,代码来源:ImageUtils.java

示例5: calculateTranslateTransform

import android.graphics.Matrix; //导入方法依赖的package包/类
protected void calculateTranslateTransform(Matrix outTransform, float distanceX, float distanceY) {
    outTransform.postTranslate(distanceX, distanceY);
    float[] viewAbsolute = mTempValues;
    viewAbsolute[0] = 0.5f;
    viewAbsolute[1] = 0.5f;
    mapRelativeToAbsolute(viewAbsolute, viewAbsolute, 1);
    float scale = (getViewBounds().height() - distanceY) / getViewBounds().height();
    outTransform.postScale(scale, scale, viewAbsolute[0], viewAbsolute[1]);
    limitScale(outTransform, viewAbsolute[0], viewAbsolute[1], LIMIT_ALL);
}
 
开发者ID:ibosong,项目名称:CommentGallery,代码行数:11,代码来源:DefaultZoomableController.java

示例6: 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:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:DefaultZoomableController.java

示例7: cropAndScale

import android.graphics.Matrix; //导入方法依赖的package包/类
@Override
public VideoFrame.Buffer cropAndScale(
    int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight) {
  retain();
  Matrix newMatrix = new Matrix(transformMatrix);
  newMatrix.postScale(cropWidth / (float) width, cropHeight / (float) height);
  newMatrix.postTranslate(cropX / (float) width, cropY / (float) height);

  return new TextureBufferImpl(
      scaleWidth, scaleHeight, type, id, newMatrix, surfaceTextureHelper, new Runnable() {
        @Override
        public void run() {
          release();
        }
      });
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:17,代码来源:TextureBufferImpl.java

示例8: translate

import android.graphics.Matrix; //导入方法依赖的package包/类
/**
 * Post-translates to the specified points.  Output matrix allows for caching objects.
 *
 * @param transformedPts
 * @return
 */
public void translate(final float[] transformedPts, Matrix outputMatrix) {
    outputMatrix.reset();
    outputMatrix.set(mMatrixTouch);
    final float x = transformedPts[0] - offsetLeft();
    final float y = transformedPts[1] - offsetTop();
    outputMatrix.postTranslate(-x, -y);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:ViewPortHandler.java

示例9: transformMatrix

import android.graphics.Matrix; //导入方法依赖的package包/类
private void transformMatrix(Matrix m, View view) {
    final float w = view.getWidth();
    final float h = view.getHeight();
    final boolean hasPivot = mHasPivot;
    final float pX = hasPivot ? mPivotX : w / 2f;
    final float pY = hasPivot ? mPivotY : h / 2f;

    final float rX = mRotationX;
    final float rY = mRotationY;
    final float rZ = mRotationZ;
    if ((rX != 0) || (rY != 0) || (rZ != 0)) {
        final Camera camera = mCamera;
        camera.save();
        camera.rotateX(rX);
        camera.rotateY(rY);
        camera.rotateZ(-rZ);
        camera.getMatrix(m);
        camera.restore();
        m.preTranslate(-pX, -pY);
        m.postTranslate(pX, pY);
    }

    final float sX = mScaleX;
    final float sY = mScaleY;
    if ((sX != 1.0f) || (sY != 1.0f)) {
        m.postScale(sX, sY);
        final float sPX = -(pX / w) * ((sX * w) - w);
        final float sPY = -(pY / h) * ((sY * h) - h);
        m.postTranslate(sPX, sPY);
    }

    m.postTranslate(mTranslationX, mTranslationY);
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:34,代码来源:AnimatorProxy.java

示例10: getRotateMatrix

import android.graphics.Matrix; //导入方法依赖的package包/类
public Matrix getRotateMatrix(Bitmap bitmap, int rotation) {
    Matrix matrix = new Matrix();
    if (bitmap != null && rotation != 0) {
        int cx = bitmap.getWidth() / 2;
        int cy = bitmap.getHeight() / 2;
        matrix.preTranslate(-cx, -cy);
        matrix.postRotate(rotation);
        matrix.postTranslate(bitmap.getWidth() / 2, bitmap.getHeight() / 2);
    }
    return matrix;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:ImageCropActivity.java

示例11: transformMatrix

import android.graphics.Matrix; //导入方法依赖的package包/类
private void transformMatrix(Matrix m, View view) {
    float w = (float) view.getWidth();
    float h = (float) view.getHeight();
    boolean hasPivot = this.mHasPivot;
    float pX = hasPivot ? this.mPivotX : w / 2.0f;
    float pY = hasPivot ? this.mPivotY : h / 2.0f;
    float rX = this.mRotationX;
    float rY = this.mRotationY;
    float rZ = this.mRotationZ;
    if (!(rX == 0.0f && rY == 0.0f && rZ == 0.0f)) {
        Camera camera = this.mCamera;
        camera.save();
        camera.rotateX(rX);
        camera.rotateY(rY);
        camera.rotateZ(-rZ);
        camera.getMatrix(m);
        camera.restore();
        m.preTranslate(-pX, -pY);
        m.postTranslate(pX, pY);
    }
    float sX = this.mScaleX;
    float sY = this.mScaleY;
    if (!(sX == 1.0f && sY == 1.0f)) {
        m.postScale(sX, sY);
        m.postTranslate((-(pX / w)) * ((sX * w) - w), (-(pY / h)) * ((sY * h) - h));
    }
    m.postTranslate(this.mTranslationX, this.mTranslationY);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:29,代码来源:AnimatorProxy.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: drawResizedBitmap

import android.graphics.Matrix; //导入方法依赖的package包/类
private void drawResizedBitmap(final Bitmap src, final Bitmap dst) {

        Display getOrient = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        int orientation = Configuration.ORIENTATION_UNDEFINED;
        Point point = new Point();
        getOrient.getSize(point);
        int screen_width = point.x;
        int screen_height = point.y;
        Log.d(TAG, String.format("screen size (%d,%d)", screen_width, screen_height));
        if (screen_width < screen_height) {
            orientation = Configuration.ORIENTATION_PORTRAIT;
            mScreenRotation = -90;
        } else {
            orientation = Configuration.ORIENTATION_LANDSCAPE;
            mScreenRotation = 0;
        }

        Assert.assertEquals(dst.getWidth(), dst.getHeight());
        final float minDim = Math.min(src.getWidth(), src.getHeight());

        final Matrix matrix = new Matrix();

        // We only want the center square out of the original rectangle.
        final float translateX = -Math.max(0, (src.getWidth() - minDim) / 2);
        final float translateY = -Math.max(0, (src.getHeight() - minDim) / 2);
        matrix.preTranslate(translateX, translateY);

        final float scaleFactor = dst.getHeight() / minDim;
        matrix.postScale(scaleFactor, scaleFactor);

        // Rotate around the center if necessary.
        if (mScreenRotation != 0) {
            matrix.postTranslate(-dst.getWidth() / 2.0f, -dst.getHeight() / 2.0f);
            matrix.postRotate(mScreenRotation);
            matrix.postTranslate(dst.getWidth() / 2.0f, dst.getHeight() / 2.0f);
        }

        final Canvas canvas = new Canvas(dst);
        canvas.drawBitmap(src, matrix, null);
    }
 
开发者ID:gicheonkang,项目名称:fast_face_android,代码行数:41,代码来源:OnGetImageListener.java

示例14: renderDebug

import android.graphics.Matrix; //导入方法依赖的package包/类
private void renderDebug(final Canvas canvas) {
  if (!isDebug()) {
    return;
  }
  final Bitmap copy = cropCopyBitmap;
  if (copy != null) {
    final Matrix matrix = new Matrix();
    final float scaleFactor = 2;
    matrix.postScale(scaleFactor, scaleFactor);
    matrix.postTranslate(
        canvas.getWidth() - copy.getWidth() * scaleFactor,
        canvas.getHeight() - copy.getHeight() * scaleFactor);
    canvas.drawBitmap(copy, matrix, new Paint());

    final Vector<String> lines = new Vector<String>();
    if (classifier != null) {
      String statString = classifier.getStatString();
      String[] statLines = statString.split("\n");
      for (String line : statLines) {
        lines.add(line);
      }
    }

    lines.add("Frame: " + previewWidth + "x" + previewHeight);
    lines.add("Crop: " + copy.getWidth() + "x" + copy.getHeight());
    lines.add("View: " + canvas.getWidth() + "x" + canvas.getHeight());
    lines.add("Rotation: " + sensorOrientation);
    lines.add("Inference time: " + lastProcessingTimeMs + "ms");

    borderedText.drawLines(canvas, 10, canvas.getHeight() - 10, lines);
  }
}
 
开发者ID:jxtz518,项目名称:Tensorflow_Andriod_With_Audio_Output,代码行数:33,代码来源:ClassifierActivity.java

示例15: onDraw

import android.graphics.Matrix; //导入方法依赖的package包/类
@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    float progress = mProgress;
    int c1 = canvas.save();
    int len = mItemList.size();

    for (int i = 0; i < len; i++) {

        canvas.save();
        StoreHouseBarItem storeHouseBarItem = mItemList.get(i);
        float offsetX = mOffsetX + storeHouseBarItem.midPoint.x;
        float offsetY = mOffsetY + storeHouseBarItem.midPoint.y;

        if (mIsInLoading) {
            storeHouseBarItem.getTransformation(getDrawingTime(), mTransformation);
            canvas.translate(offsetX, offsetY);
        } else {

            if (progress == 0) {
                storeHouseBarItem.resetPosition(mHorizontalRandomness);
                continue;
            }

            float startPadding = (1 - mInternalAnimationFactor) * i / len;
            float endPadding = 1 - mInternalAnimationFactor - startPadding;

            // done
            if (progress == 1 || progress >= 1 - endPadding) {
                canvas.translate(offsetX, offsetY);
                storeHouseBarItem.setAlpha(mBarDarkAlpha);
            } else {
                float realProgress;
                if (progress <= startPadding) {
                    realProgress = 0;
                } else {
                    realProgress = Math.min(1, (progress - startPadding) / mInternalAnimationFactor);
                }
                offsetX += storeHouseBarItem.translationX * (1 - realProgress);
                offsetY += -mDropHeight * (1 - realProgress);
                Matrix matrix = new Matrix();
                matrix.postRotate(360 * realProgress);
                matrix.postScale(realProgress, realProgress);
                matrix.postTranslate(offsetX, offsetY);
                storeHouseBarItem.setAlpha(mBarDarkAlpha * realProgress);
                canvas.concat(matrix);
            }
        }
        storeHouseBarItem.draw(canvas);
        canvas.restore();
    }
    if (mIsInLoading) {
        invalidate();
    }
    canvas.restoreToCount(c1);
}
 
开发者ID:sathishmscict,项目名称:android-Ultra-Pull-To-Refresh,代码行数:57,代码来源:StoreHouseHeader.java


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