Adding a movable/resizble image to another UIImage?

Discussion in 'iOS Programming' started by dazcox5181, Apr 24, 2010.

  1. dazcox5181 macrumors 6502

    Joined:
    Jun 12, 2005
    #1
    Hi, I could do with some help...

    In an app I'm creating I need to be able to add an image onto another image, at a place/size the user specifies.

    On my view there is an UIImageView called imageView - this is then setup with buttons to capture a camera image/use one from library, and I even have emailing/twitpic upload for the image working.

    What i need to do is allow the user to add something to the image (small logo etc) which is in the app in png format called logo.png before sending it.

    I can't find how to do this though!

    I could do with the option to drag/drop the logo and also resize would be nice, but not essential for v1...

    Could anyone point me in the right direction?

    Thanks
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    So what you are saying, in a round about way, is that you want to composite two images together and get the result as an image you can email? If so it's pretty easy:

    1) Use UIGraphicsBeginImageContext to create a graphics context to render into
    2) Draw the first image
    3) Draw the second image
    4) Get the resulting composte with UIGraphicsGetImageFromCurrentImageContext.
    5) End the context with UIGraphicsEndImageContext

    There are a few ways that you could draw the images. If they are already in views the the renderInContext: method of CALayer is pretty handy.

    In short all of this is in the documentation.
     
  3. dazcox5181 thread starter macrumors 6502

    Joined:
    Jun 12, 2005
    #3
    Thanks, where do I handle the drag/drop part?

    It may be in the docs but is there a code sample somewhere that would demonstrate?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    I've no idea if there is "sample code" for you to copy and paste. Go and read the documentation and work out how you would detect a drag on a view and then use that to reposition it.
     
  5. dazcox5181 thread starter macrumors 6502

    Joined:
    Jun 12, 2005
    #5
    Well thanks anyway. Luckily found answer on another more beginner friendly site than this.
     

Share This Page