1

I am new programming IOS app , and I got into this problem : I have two images in the app that I want to post in twitter , but Twitter just accept one picture to be uploaded , so I came out with the idea to make Image A + Image B just One Image. I already have the posting and resizing the images process done. However, I need help to make Image A + Image B just one Image. Anyone can HELP? Thank you.

enter image description here

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
Luis
  • 23
  • 2
  • 4
    Luis. Congrats on wanting to be a iOS programmer, and Welcome to Stack Overflow... however INSERT CODE HERE is not the way we roll. You need to attempt to figure it out and if you have a specific question we can try to help you out... best of luck to you! What have you tried so far? – logixologist Aug 21 '13 at 23:50
  • 3
    Hi Luis, welcome to StackOverflow. Sharing your research helps everyone. Show us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! Also see [how to ask](http://stackoverflow.com/questions/how-to-ask) – Dhaust Aug 21 '13 at 23:51
  • Because ur new I would think the easiest way to do this is to make 2 uiimageview and set their position like in the picture and then add a button that screenscots. You can google it all up ;) – Arbitur Aug 22 '13 at 00:02
  • 2
    @Arbitur - Are you serious? This is a terrible idea. – Abizern Aug 22 '13 at 00:16
  • @Abizem its a start :S because hes new. I dont think its a that bad of an idea. – Arbitur Aug 22 '13 at 00:17
  • Possible duplicate of http://stackoverflow.com/questions/9257992/how-to-combine-merge-2-images-into-1 and this http://stackoverflow.com/questions/9208951/ios-merging-two-images-of-different-size and possibly this http://stackoverflow.com/questions/7137411/iphonesdk-merge-three-imoages-two-single-image – Adrian P Aug 22 '13 at 02:17

1 Answers1

8

Here is some code you can use...

Assumptions:

  • You have your two images already initialized
  • The two images have the same dimension. If your images have different sizes you'll have to play around with the dimensions yourself.

    UIImage *girl1 = INITIALIZE_HERE;
    UIImage *girl2 = INITIALIZE_HERE;
    
    // Get the size of your images (assumed to be the same)
    CGSize size = [girl1 size];
    
    // Create a graphic context that you can draw to. You can change the size of the 
    // graphics context (your 'canvas') by modifying the parameters inside the
    // CGSizeMake function. 
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(size.width*2, size.height), NO, 0);
    
    // Draw the first image to your newly created graphic context
    [girl1 drawAtPoint:CGPointMake(0,0)];
    
    // Draw your second image to your graphic context
    [girl2 drawAtPoint:CGPointMake(size.width,0)];
    
    // Get the new image from the graphic context
    UIImage *theOneImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // Get rid of the graphic context
    UIGraphicsEndImageContext();
    

Hope this helps!

LuisCien
  • 6,362
  • 4
  • 34
  • 42
  • +1 beat me to it. I'd add that you don't need to base the size on the actual sizes of the images, you can draw into whatever size rect you want using `drawInRect:`. @Arbitur - see, this is the way to do it. – Abizern Aug 22 '13 at 00:19
  • @Luis were you able to try this solution? Did you have any problems? – LuisCien Aug 22 '13 at 00:32
  • Thanks LuisCien, That was very kind from you . I found the solution and it was something very similar to the one you wrote. Any way, Thanks again buddy. – Luis Aug 27 '13 at 19:25