EarlGrey
EarlGrey

Reputation: 2543

CGRectApplyAffineTransform not doing anything?

I'm new to the CGAffine world. Anyone know why my transformation doesn't work/take ?

  1. I have a valid PDFContext created with UIGraphicsBeginPDFContextToData and the following current matrix:

    CGAffineTransform curMat = CGContextGetCTM(context);
    NSLog (@"current context matrix: %f %f %f %f %f %f", curMat.a, curMat.b, curMat.c, curMat.d, curMat.tx, curMat.ty);
    
  2. NSLog values:

    current matrix: 1.000000 0.000000 -0.000000 -1.000000 0.000000 792.000000

  3. I create the transformation matrix with:

    CGAffineTransform xform = CGAffineTransformMake(a, b, c, d, tx, ty);
    
  4. NSLog values:

    transform matrix: 0.062500 0.000000 0.000000 0.062500 0.000000 0.000000

  5. I get the my rect from:

    CGRect pdfBounds = UIGraphicsGetPDFContextBounds();
    
  6. NSLog values:

    pdfBounds: 0.000000 0.000000 612.000000 792.000000

  7. I apply the transformation matrix with:

     CGRectApplyAffineTransform (pdfBounds, xform);
    
  8. Then I re-check the current matrix value with:

    CGAffineTransform curMat2 = CGContextGetCTM(context);
    NSLog (@"current context matrix after transformation: %f %f %f %f %f %f", curMat2.a, curMat2.b, curMat2.c, curMat2.d, curMat2.tx, curMat2.ty)
    
  9. and the NSLog values are the same as at the beginning.

    current context matrix after transformation: 1.000000 0.000000 -0.000000 -1.000000 0.000000 792.000000

What am I missing ? Why is the transformation not happening/taking ? Thank you.

Upvotes: 2

Views: 1022

Answers (1)

Joe
Joe

Reputation: 57179

You are ignoring the result of the applied transformation and you are also not applying any transformation to the context.

Step 7 should be:

CGContextConcatCTM(context, xform);

Upvotes: 1

Related Questions