Java Code Examples for android.graphics.Matrix#setPolyToPoly()

The following examples show how to use android.graphics.Matrix#setPolyToPoly() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidCamera2AgentImpl.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
@Override
public Matrix getPreviewTransform(int currentDisplayOrientation,
                                  RectF surfaceDimensions,
                                  RectF desiredBounds) {
    if (!orientationIsValid(currentDisplayOrientation)) {
        return new Matrix();
    }

    // The system transparently transforms the image to fill the surface
    // when the device is in its natural orientation. We rotate the
    // coordinates of the rectangle's corners to be relative to the
    // original image, instead of to the current screen orientation.
    float[] surfacePolygon = rotate(convertRectToPoly(surfaceDimensions),
            2 * currentDisplayOrientation / 90);
    float[] desiredPolygon = convertRectToPoly(desiredBounds);

    Matrix transform = new Matrix();
    // Use polygons instead of rectangles so that rotation will be
    // calculated, since that is not done by the new camera API.
    transform.setPolyToPoly(surfacePolygon, 0, desiredPolygon, 0, 4);
    return transform;
}
 
Example 2
Source File: MatrixMethod.java    From zone-sdk with MIT License 6 votes vote down vote up
private void ployTWO(Canvas canvas) {
    canvas.save();
    float[] src = {0, 0,                                    // 左上
            bt.getWidth(), 0,                          // 右上
            bt.getWidth(), bt.getHeight(),        // 右下
            0, bt.getHeight()};                        // 左下

    float[] dst = {0, 0,                                    // 左上
            bt.getWidth(),50,                        // 右上
            bt.getWidth(), bt.getHeight() -50,  // 右下
            0, bt.getHeight()};                        // 左下

    Matrix ploy=new Matrix();
    ploy.setPolyToPoly(src,0,dst,0,2);
    canvas.drawBitmap(bt,ploy, paint);
    canvas.restore();
}
 
Example 3
Source File: MatrixMethod.java    From zone-sdk with MIT License 6 votes vote down vote up
private void ployOne(Canvas canvas) {
    canvas.save();
    float[] src = {0, 0,                                    // 左上
            bt.getWidth(), 0,                          // 右上
            bt.getWidth(), bt.getHeight(),        // 右下
            0, bt.getHeight()};                        // 左下

    float[] dst = {0+100, 0,                                    // 左上
            bt.getWidth(),50,                        // 右上
            bt.getWidth(), bt.getHeight() -50,  // 右下
            0, bt.getHeight()};                        // 左下

    Matrix ploy=new Matrix();
    ploy.setPolyToPoly(src,0,dst,0,1);
    canvas.drawBitmap(bt,ploy, paint);
    canvas.restore();
}
 
Example 4
Source File: TextureViewPreview.java    From TikTok with Apache License 2.0 5 votes vote down vote up
/**
 * Configures the transform matrix for TextureView based on {@link #mDisplayOrientation} and
 * the surface size.
 */
void configureTransform() {
    Matrix matrix = new Matrix();
    if (mDisplayOrientation % 180 == 90) {
        final int width = getWidth();
        final int height = getHeight();
        // Rotate the camera preview when the screen is landscape.
        matrix.setPolyToPoly(
                new float[]{
                        0.f, 0.f, // top left
                        width, 0.f, // top right
                        0.f, height, // bottom left
                        width, height, // bottom right
                }, 0,
                mDisplayOrientation == 90 ?
                        // Clockwise
                        new float[]{
                                0.f, height, // top left
                                0.f, 0.f, // top right
                                width, height, // bottom left
                                width, 0.f, // bottom right
                        } : // mDisplayOrientation == 270
                        // Counter-clockwise
                        new float[]{
                                width, 0.f, // top left
                                width, height, // top right
                                0.f, 0.f, // bottom left
                                0.f, height, // bottom right
                        }, 0,
                4);
    } else if (mDisplayOrientation == 180) {
        matrix.postRotate(180, getWidth() / 2, getHeight() / 2);
    }
    mTextureView.setTransform(matrix);
}
 
Example 5
Source File: TextureViewPreview.java    From LockDemo with Apache License 2.0 5 votes vote down vote up
/**
 * Configures the transform matrix for TextureView based on {@link #mDisplayOrientation} and
 * the surface size.
 */
void configureTransform() {
    Matrix matrix = new Matrix();
    if (mDisplayOrientation % 180 == 90) {
        final int width = getWidth();
        final int height = getHeight();
        // Rotate the camera preview when the screen is landscape.
        matrix.setPolyToPoly(
                new float[]{
                        0.f, 0.f, // top left
                        width, 0.f, // top right
                        0.f, height, // bottom left
                        width, height, // bottom right
                }, 0,
                mDisplayOrientation == 90 ?
                        // Clockwise
                        new float[]{
                                0.f, height, // top left
                                0.f, 0.f, // top right
                                width, height, // bottom left
                                width, 0.f, // bottom right
                        } : // mDisplayOrientation == 270
                        // Counter-clockwise
                        new float[]{
                                width, 0.f, // top left
                                width, height, // top right
                                0.f, 0.f, // bottom left
                                0.f, height, // bottom right
                        }, 0,
                4);
    } else if (mDisplayOrientation == 180) {
        matrix.postRotate(180, getWidth() / 2, getHeight() / 2);
    }
    mTextureView.setTransform(matrix);
}
 
Example 6
Source File: TextureViewPreview.java    From SimpleVideoEditor with Apache License 2.0 5 votes vote down vote up
/**
 * Configures the transform matrix for TextureView based on {@link #mDisplayOrientation} and
 * the surface size.
 */
void configureTransform() {
    Matrix matrix = new Matrix();
    if (mDisplayOrientation % 180 == 90) {
        final int width = getWidth();
        final int height = getHeight();
        // Rotate the camera preview when the screen is landscape.
        matrix.setPolyToPoly(
                new float[]{
                        0.f, 0.f, // top left
                        width, 0.f, // top right
                        0.f, height, // bottom left
                        width, height, // bottom right
                }, 0,
                mDisplayOrientation == 90 ?
                        // Clockwise
                        new float[]{
                                0.f, height, // top left
                                0.f, 0.f, // top right
                                width, height, // bottom left
                                width, 0.f, // bottom right
                        } : // mDisplayOrientation == 270
                        // Counter-clockwise
                        new float[]{
                                width, 0.f, // top left
                                width, height, // top right
                                0.f, 0.f, // bottom left
                                0.f, height, // bottom right
                        }, 0,
                4);
    } else if (mDisplayOrientation == 180) {
        matrix.postRotate(180, getWidth() / 2, getHeight() / 2);
    }
    mTextureView.setTransform(matrix);
}
 
Example 7
Source File: TextureViewPreview.java    From MediaPickerInstagram with Apache License 2.0 5 votes vote down vote up
/**
 * Configures the transform matrix for TextureView based on {@link #mDisplayOrientation} and
 * the surface size.
 */
public void configureTransform() {
    Matrix matrix = new Matrix();
    if (mDisplayOrientation % 180 == 90) {
        final int width = getWidth();
        final int height = getHeight();
        // Rotate the camera preview when the screen is landscape.
        matrix.setPolyToPoly(
                new float[]{
                        0.f, 0.f, // top left
                        width, 0.f, // top right
                        0.f, height, // bottom left
                        width, height, // bottom right
                }, 0,
                mDisplayOrientation == 90 ?
                        // Clockwise
                        new float[]{
                                0.f, height, // top left
                                0.f, 0.f, // top right
                                width, height, // bottom left
                                width, 0.f, // bottom right
                        }
                        : // mDisplayOrientation == 270
                        // Counter-clockwise
                        new float[]{
                                width, 0.f, // top left
                                width, height, // top right
                                0.f, 0.f, // bottom left
                                0.f, height, // bottom right
                        }, 0,
                4);
    }
    mTextureView.setTransform(matrix);
}
 
Example 8
Source File: FaceCapturer.java    From rubik-robot with MIT License 5 votes vote down vote up
public Bitmap getTransformedBitmap(byte[] data) {
    Log.d(TAG, "Picture taken!!");

    Bitmap b = rotateBitmap(BitmapFactory.decodeByteArray(data, 0, data.length), mCameraRotation);
    int w = b.getWidth();
    int h = b.getHeight();

    int sw = mCameraPreview.getWidth();
    int sh = mCameraPreview.getHeight();

    /**
     * Map screen coordinates to image coordinates
     * Assumes aspect ratios of preview and image are the same
     */
    Point[] coords = mHLView.getCoords();
    float[] src = new float[coords.length * 2];
    for (int i = 0; i < coords.length; i++) {
        Point coord = coords[i];
        src[i * 2 + 0] = (coord.x / (float) sw) * w;
        src[i * 2 + 1] = (coord.y / (float) sh) * h;
    }

    Bitmap target = Bitmap.createBitmap(b.getWidth(), b.getHeight(), b.getConfig());
    int tw = target.getWidth();
    int th = target.getHeight();

    Canvas canvas = new Canvas(target);
    Matrix m = new Matrix();
    m.setPolyToPoly(src, 0, new float[]{0, 0, tw, 0, tw, th, 0, th}, 0, 4);
    canvas.drawBitmap(b, m, null);

    return target;
}
 
Example 9
Source File: TextureViewPreview.java    From cameraview with Apache License 2.0 5 votes vote down vote up
/**
 * Configures the transform matrix for TextureView based on {@link #mDisplayOrientation} and
 * the surface size.
 */
void configureTransform() {
    Matrix matrix = new Matrix();
    if (mDisplayOrientation % 180 == 90) {
        final int width = getWidth();
        final int height = getHeight();
        // Rotate the camera preview when the screen is landscape.
        matrix.setPolyToPoly(
                new float[]{
                        0.f, 0.f, // top left
                        width, 0.f, // top right
                        0.f, height, // bottom left
                        width, height, // bottom right
                }, 0,
                mDisplayOrientation == 90 ?
                        // Clockwise
                        new float[]{
                                0.f, height, // top left
                                0.f, 0.f, // top right
                                width, height, // bottom left
                                width, 0.f, // bottom right
                        } : // mDisplayOrientation == 270
                        // Counter-clockwise
                        new float[]{
                                width, 0.f, // top left
                                width, height, // top right
                                0.f, 0.f, // bottom left
                                0.f, height, // bottom right
                        }, 0,
                4);
    } else if (mDisplayOrientation == 180) {
        matrix.postRotate(180, getWidth() / 2, getHeight() / 2);
    }
    mTextureView.setTransform(matrix);
}