Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7557209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:04:21+00:00 2026-05-30T12:04:21+00:00

I am really strugggling with Quartz2D for more then 10 days please help me

  • 0

I am really strugggling with Quartz2D for more then 10 days please help me understand few concepts I will be really grateful, please look at this code and screenshot url.

This code draw image with border and write text to it and the image become whole new image with border and text.

//part 1 
CGSize cgs = CGSizeMake(250.0, 400.0);
UIGraphicsBeginImageContext(cgs);

CGRect rectangle = CGRectMake(0,0,cgs.width,cgs.height);
CGRect imageRect = CGRectInset(rectangle, 5.4, 5.4);
imageRect.size.height -= 100;

UIImage *myImage = [UIImage imageNamed:@"BMW.jpg"]; 
[myImage drawInRect:imageRect];    

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 10.0);
    CGContextSetRGBStrokeColor(context, 0.0, 0.0, 1.0, 1.0);
CGContextStrokeRect(context, rectangle);
//



//part 2

 1. CGRect contextRect = rectangle;
 2. CGContextTranslateCTM(context, 0, contextRect.size.height);
 3. CGContextScaleCTM(context, 1, -1);
 4. float w, h;
 5. w = contextRect.size.width;
 6. h = contextRect.size.height;
 7. CGContextSelectFont (context, "Helvetica-Bold", 25,
    kCGEncodingMacRoman);
 8. CGContextSetCharacterSpacing (context, 5);
 9. CGContextSetRGBFillColor(context, 0.0, 1.0, 1.0, 1.0);
 10. CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
 11. CGContextShowTextAtPoint(context, 45, 50, "Quartz 2D", 9);

//



//part 3
UIImage *testImg =  UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

[testImg drawAtPoint:CGPointMake(35, 10)];
// 

http://i40.tinypic.com/140aptv.png

part 1 and part 3 of the code is very clear to me

problem is regarding part 2

on line 2 and 3 coordinates are transformed so the text do not display
upside down, but uiimage already take care of this internally, why it
didn’t transformed to upside down? why it is still displaying in
correct position after transform is applied for text using same
context? I am asking this because when uiimage coordinates are already
modified then this coordinate transform will not make uiimage again
upside down?

on line 9 and 10 fillcolor and strokecolor methods are called and
fillcolor changes the text color, but strokecolor not doing any thing
to text why? And why without CGContextSaveGState it modified the
color of text not the border color?

regarding these both points I mentioned above the common confusion is
why its working perfectly why this code didn’t need
CGContextSaveGState and CGContextRestoreGState. How it is possible
that context is modified and it didn’t effect the perviously drawing
item like blue border in this case and coordinates transformation for
text.

Please correct me if I am lacking in any way to make you understand my points.

Thanks in advance,
Regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:04:22+00:00Added an answer on May 30, 2026 at 12:04 pm

    Quartz 2D uses the “painter’s model.” That means, you draw one thing, and it’s done. Then you draw another thing, and it goes on top of what you drew before. Then you draw another thing and that goes on top, etc. If I pick up a stamp, dip it in paint and press it to paper, then turn it over and do it again to another part of the paper, the first stamped image doesn’t flip over just because I flipped the stamp.

    Every time you see “stroke” or “draw,” you’re modifying the final image. Later changes to the context don’t effect that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Really struggling to understand this problem, any ideas are welcome I have a carousel
I'm really struggling to understand why I'm getting this error. I'm getting it referring
Really struggling to figure this out. Just trying to take in data from php
I am really struggling to understand why, when I change my code to use
OK i am really struggling with this! I know had to add an image
I'm really struggling with this now, been on it for ages and asked two
For some reason I'm really struggling with this. I'm new to wpf and I
I am really struggling to understand tail recursion in Erlang. I have the following
I'm sure this is a piece of cake but I'm really struggling with something
Here is probably an easy question.. but I am really struggling so help is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.