3

Can anyone help me with a graphics issue I am having. This code does not apply the setPolyToPoly at all.. it does the Camera rotation, but not the polyToPoly transformation .. I dont understand why..

final Camera camera = mCamera;
final Matrix matrix = t.getMatrix();

camera.save();
camera.translate(x, y, z);
camera.getMatrix(matrix);
camera.restore();

matrix.setPolyToPoly(sourceArr, 0, destArr, 0, sourceArr.length >> 1);
matrix.preTranslate(-0, -height);
matrix.postTranslate(0, height);
user584513
  • 630
  • 11
  • 20

1 Answers1

6

This sample does not fit your question entirely but might put you in the right direction. In this sample a matrix is applied to a bitmap that puts in a perspective. If I compare to your snippet, you do set the polytopoly but it is not applied to the camera.

    Bitmap  bitmap2 = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
    Canvas canvas2 = new Canvas(bitmap2);       
    canvas2.drawColor(Color.WHITE);
    Paint rectPaint2 = new Paint();
    rectPaint2.setColor(Color.GREEN);
    canvas2.drawRect(20, 20, 180, 180, rectPaint2);
    Matrix matrix2 = new Matrix();
    float deform2 = 20f;
    float[] src2 = new float[] { 0, 0, bitmap2.getWidth(), 0, bitmap2.getWidth(), bitmap2.getHeight(), 0, bitmap2.getHeight() };
    float[] dst2 = new float[] { 0, 0, bitmap2.getWidth() - deform2, deform2, bitmap2.getWidth() - deform2, bitmap2.getHeight() - deform2, 0, bitmap2.getHeight() };
    matrix2.setPolyToPoly(src2, 0, dst2, 0, src2.length >> 1);
    Bitmap bMatrix2= Bitmap.createBitmap(bitmap2, 0, 0, bitmap2.getWidth(), bitmap2.getHeight(), matrix2, true);

    ImageView ivSecond = (ImageView) findViewById(R.id.ivSecond);
    ivSecond.setImageBitmap(bMatrix2);
Alex
  • 624
  • 1
  • 9
  • 12
  • Why do you have "src2.length >> 1" ? isn't it supposed to match the length of the array exactly ? – android developer Aug 25 '15 at 07:30
  • pointCount The number of pairs/points to be used. Must be [0..4] It's the number of pairs, not the number of entries. – Tatarize Aug 31 '15 at 01:14
  • FYI ">> 1" drops the least significant bit, effectively dividing by 2. Just as dropping the least significant digit in a base-10 number divides by 10. For example 120, dropping the zero is 12. – Systemsplanet Jan 09 '20 at 02:19