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 9251693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:45:57+00:00 2026-06-18T10:45:57+00:00

I’m working on an iPhone app that can create pictures and post them to

  • 0

I’m working on an iPhone app that can create pictures and post them to Facebook and Instagram.

The correct size for Facebook photos seems to be 350×350, and indeed this code creates a 350×350 image exactly how I want:

-(UIImage *)createImage {
    UIImageView *v = [[UIImageView alloc] initWithFrame:CGRectMake(0, screenHeight/2-349, 349, 349)];
    v.image = [UIImage imageNamed:@"backgroundForFacebook.png"];  //"backgroundForFacebook.png" is 349x349.

    //This code adds some text to the image.

    CGSize dimensions = CGSizeMake(screenWidth, screenHeight);
    CGSize imageSize = [self.ghhaiku.text sizeWithFont:[UIFont fontWithName:@"Georgia"
                                                                       size:mediumFontSize]
                                     constrainedToSize:dimensions lineBreakMode:0];
    int textHeight = imageSize.height+16;
    UITextView *tv = [self createTextViewForDisplay:self.ghhaiku.text];
    tv.frame = CGRectMake((screenWidth/2)-(self.textWidth/2),s creenHeight/3.5,
                          self.textWidth/2 + screenWidth/2, textHeight*2);
    [v addSubview:tv];

    //End of text-adding code

    CGRect newRect = CGRectMake(0, screenHeight/2-349, 349, 349);
    UIGraphicsBeginImageContext(newRect.size);
    [[v layer] renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *myImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [v removeFromSuperview];
    return myImage;
}

But when I use the same code to create an Instagram image, which needs to be 612×612, I get the text only, no background image:

-(UIImage *)createImageForInstagram {
    UIImageView *v = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 612, 612)];
    v.image = [UIImage imageNamed:@"backgroundForInstagram.png"];  //"backgroundForInstagram.png" is 612x612.

    //...text-adding code...

    CGRect newRect = CGRectMake(0, 0, 612, 612);
    UIGraphicsBeginImageContext(newRect.size);
    [[v layer] renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *myImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [v removeFromSuperview];
    return myImage;
}

What am I doing wrong, and how do I fix it?

(While I’m at it, I’ll also say that I’m very new to using graphic contexts, so if there’s any awkwardness in the code I’d appreciate your pointing it out.)

EDIT: Now I’ve reduced the two methods to one, and this time I don’t even get the text. Argh!

-(UIImage *)addTextToImage:(UIImage *)myImage withFontSize:(int)sz {
    NSString *string=self.displayHaikuTextView.text;
    NSString *myWatermarkText = [string stringByAppendingString:@"\n\n\t--haiku.com"];
    NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Georgia" 
                                                                                     size:sz],
                                                                     NSFontAttributeName, 
                                                                     nil];
    NSAttributedString *attString = [[NSAttributedString alloc] initWithString:myWatermarkText attributes:attrs];
    UIGraphicsBeginImageContextWithOptions(myImage.size,NO,1.0);
    [myImage drawAtPoint: CGPointZero];
    NSString *longestLine = ghv.listOfLines[1];
    CGSize sizeOfLongestLine = [longestLine sizeWithFont:[UIFont fontWithName:@"Georgia" size:sz]];
    CGSize siz = CGSizeMake(sizeOfLongestLine.width, sizeOfLongestLine.height*5);
    [attString drawAtPoint: CGPointMake(myImage.size.width/2 - siz.width/2, myImage.size.height/2-siz.height/2)];
    myImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return myImage;
}

When I pass the arguments [UIImage imageNamed:"backgroundForFacebook.png"] (an image 349×349) and 12, everything is fine. I get the picture. When I pass the arguments [UIImage imageNamed:"backgroundForInstagram.png"] (an image 612×612) and 24, nothing doing.

Right now I’m just putting the text on the smaller image (@”backgroundForFacebook.png”) and then resizing it, but that makes the text blurry, which I don’t like.

EDIT: Just to cover the basics, here are images of 1) the method in which I call this method (to check the spelling) and 2) the Supporting Files and the Build Phases (to show the image is actually there). I also tried assigning longestLine a non-variable NSString. No luck. 🙁

enter image description here

build phases

enter image description here

FURTHER EDIT: Okay, logging the size and scale of the images as I go during addTextToImage: above, here’s what I get for the smaller image, the one that’s working:

2013-02-04 22:24:09.588 GayHaikuTabbed[38144:c07] 349.000000, 349.000000, 1.000000

And here’s what I get for the larger image–it’s a doozy.

Feb  4 22:20:36 Joels-MacBook-Air.local GayHaikuTabbed[38007] <Error>: CGContextGetFontRenderingStyle: invalid context 0x0
Feb  4 22:20:36 Joels-MacBook-Air.local GayHaikuTabbed[38007] <Error>: CGContextSetFillColorWithColor: invalid context 0x0

//About thirty more of these.

Feb  4 22:20:36 Joels-MacBook-Air.local GayHaikuTabbed[38007] <Error>: CGBitmapContextCreate: unsupported parameter combination: 0 integer bits/component; 0 bits/pixel; 0-component color space; kCGImageAlphaNoneSkipLast; 2448 bytes/row.
Feb  4 22:20:36 Joels-MacBook-Air.local GayHaikuTabbed[38007] <Error>: CGContextDrawImage: invalid context 0x0
Feb  4 22:20:36 Joels-MacBook-Air.local GayHaikuTabbed[38007] <Error>: CGBitmapContextCreateImage: invalid context 0x0
  • 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-06-18T10:45:58+00:00Added an answer on June 18, 2026 at 10:45 am

    i always back up to the obvious questions:

    • is your image actually properly called/spelled backgroundForInstagram.png?
    • have you properly added it to your project?
    • when added, did it copied to the device in the copy steps of the build phases?
    • what’s in the ghv at the time of the call in the edited code?
    • what’s in item[1] of ghv.lines at the time of that rendering?

    these are the things i would look at in terms of debugging this code.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.