Doubt in color the image

Discussion in 'iPhone/iPad Programming' started by iphonejudy, Apr 2, 2009.

  1. macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #1
    hi,


    I need to write code for coloring an image.how can i find the orgin of the images.

    For example, if i want to color a duck.means , i want to color eyes.so i need to know the orgin of the eyes.

    Can anyone give me some idea?
     
  2. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #2
    If I understand you correctly (a big if) then what you're asking is IMO extremely hard - recognising an eye. There are code snippets on the web for doing red-eye correction (such as this one) but what you're asking is much harder. An easier option would be color replacement where the user selects a color to replace and what to replace it with. All you need then are appropriate tolerances on the colors so very similar tones get changed but not dissimilar ones.
     
  3. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #3
    I want to color an image.

    For example if it is a man image means,The user wants to give different colors for hair,lips,eyes,shirts and pants know?

    So,if the user having his fingers in the shirt means.I need to find the orgin of the shirt and to color the shirt with the color picked by the user.

    and if the user placed his fingers in the hair of the image.i need to fill the hair of the image with the color picked by the user.

    1)How can i find the orgin of the image(like shirt and pant)

    2)Is any useful documents available related to the paint?
     
  4. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    Google Edge Detection.
     
  5. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #5
    Paint application

    Hi,


    I need to develop a paint application in iphone.


    I want to paint an image by clicking a color and,if i click in a part of an image ,that part would be filled with the particular color.

    Can anyone suggest me the solution?
     
  6. macrumors 604

    jmann

    #6
  7. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #7
    Any documents or sample code related to this,please let me know?
     
  8. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #8
    I'm going to throw you a bone here. I don't know why: I agree with the other posters: you come on here, ask for code without providing any yourself and seem to want everything handed to you on a plate. I'd guess you are about 15, have never had to work a day in your life, have well off parents and are used to getting everything you want, right now. Your sense of entitlement has grown worse and worse since you started posting.

    And I disagree that you "just want to get ideas from the senior developeres". You didn't ask for ideas you asked for "the solution" in your first post.

    Anyway what you are talking about is performing a flood fill. You can read about many possible algorithms on Wikipedia. You will then need to read the Quartz/Core Graphics documentation and decide how to implement this yourself.
     
  9. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #9
    I started my application and i finished the app 25% .

    Thanks for all
     
  10. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #10
    Coloring an image

    Hi i need to color an image.I refered with documents and wrote the below code,


    My problem is,i ask 2 fill with red color,but the code fill my image with green color .and if i touch again the image.then the color is change to light green.if again i touch it wil become blank.

    Whats the problem in my code?

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
    UIColor *greenColor, *blueColor,*redColor;

    if(button == @"green" || button ==@"red")
    {



    NSLog(@"I am Touch");

    UITouch *touch = [[event allTouches] anyObject];
    if([touch view] == baseImage1)
    {
    NSLog(@"touch");
    //CGPoint location = [touch locationInView:self];
    //baseImage.center = location;
    image1=baseImage1;
    }

    if([touch view] == baseImage)
    {
    NSLog(@"baseImage");
    //CGPoint location = [touch locationInView:self];
    //baseImage.center = location;
    image1=baseImage;
    }



    if([touch view] == buton1)
    {
    NSLog(@"buton1");
    //CGPoint location = [touch locationInView:self];
    //baseImage.center = location;
    theColor=greenColor;
    }

    if([touch view] == buton2)
    {
    NSLog(@"buton2");
    //CGPoint location = [touch locationInView:self];
    //baseImage.center = location;
    theColor=redColor;
    }




    NSLog(@"image=%@",image1);


    CGImageRef imageRef = self.image1.image.CGImage;
    size_t bitsPerComponent = CGImageGetBitsPerComponent(imageRef);
    size_t bytesPerRow = CGImageGetBytesPerRow(imageRef);
    size_t imageWidth = CGImageGetWidth(imageRef);
    size_t imageHeight = CGImageGetHeight(imageRef);
    CGColorSpaceRef colorSpace = CGImageGetColorSpace(imageRef);



    //CGColorSpaceRef colorSpace ;
    CFDataRef dr = CGDataProviderCopyData(CGImageGetDataProvider(imageRef));
    UInt8* dataPtr = (UInt8*)CFDataGetBytePtr(dr);
    int max = bytesPerRow * imageHeight;

    for (int i = 0; i < max; i++)
    {

    if (0 != dataPtr[i + 3])
    {


    dataPtr[i++]=(UInt8*)redColor;

    }
    else
    i += 3;



    }

    CGContextRef ref = CGBitmapContextCreate(dataPtr, imageWidth, imageHeight, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);//To set the new image

    if (nil == ref)
    NSLog(@"Error creating context!");
    CGImageRef imageRefNew = CGBitmapContextCreateImage(ref);

    UIImage *img = [UIImage imageWithCGImage:imageRefNew];
    self.image1.image = img;


    CFRelease(imageRefNew);
    CFRelease(ref);
    CFRelease(colorSpace);
    CFRelease(dr);
    return self;
    }

    }

    judy
     
  11. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #11
    Well, for starters you haven't assigned a value to redColor, blueColor or greenColor.
     
  12. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #12

    oh!

    then how can i do it in another way? any other solution?
     
  13. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #13
    FFS It's pretty simple really. You need to do -

    Code:
    redColor=[UIColor redColor];
    
    etc.

    Looking at the code it's pretty clear to see what you've written and what you've cut and pasted. It isn't going to do what you expect it to do.
     
  14. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #14
    Thanks.its working now
     
  15. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #15
    CGContextRef imageRef = self.image1.image.CGImage;//image1 is a png image
    size_t bitsPerComponent = CGImageGetBitsPerComponent(imageRef);
    size_t bytesPerRow = CGImageGetBytesPerRow(imageRef);
    size_t imageWidth = CGImageGetWidth(imageRef);
    size_t imageHeight = CGImageGetHeight(imageRef);
    CGColorSpaceRef colorSpace = colorSpace = CGColorSpaceCreateDeviceRGB();
    CFDataRef dr = CGDataProviderCopyData(CGImageGetDataProvider(imageRef));
    UInt8* dataPtr = (UInt8*)CFDataGetBytePtr(dr);
    int max = bytesPerRow * imageHeight;


    CGContextRef ref = CGBitmapContextCreate(dataPtr, imageWidth, imageHeight, bitsPerComponent, bytesPerRow, colorSpace,kCGImageAlphaNoneSkipLast);


    CGContextSetRGBFillColor(ref, 1.0, 0.0, 0.0, 0.0);//to set red color

    //I need to fill color of the image

    .............


    }


    I refered the document that i saw CGContextFillRect() is available for fill rectangle,

    Is there any function available for fill color for png image?
     
  16. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #16
    There is no built-in flood fill function. You have to write it yourself. I have already provided you with a link to a number of potential algorithms for this. If you are unable to turn an algorithm into working code it's time to pay for a professional programmer to do it properly.
     
  17. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #17

    oh.Thanks
     
  18. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #18
    Can we color a particular pixel ?
     
  19. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #19
    There is this clearly linked document in the documentation that tells you how to get the pixel level data from a CGImage. You should then manipulate that data and set your CGImage to that data once complete. Note the warnings regarding data format etc in the note.
     
  20. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #20

    ya ,I saw this document earlier.here they mention how to get pixel,I am asking is there any function available to color a pixel?
     
  21. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #21
    Once you have the pixel data you simply need to set the values in the data to represent the colour you want respecting the bits per component, colour ordering and so on. There is no function that I am aware of that will set a single pixel value for you.
     
  22. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #22
    How can we convert grayscale image to color image?(So that i can color red,blue...)
     
  23. macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #23
    Do you actually have an imagination? How do you expect us all to know the answer to every question you have when the majority of us have never tried to do what you are doing?

    All the solutions that have been suggested to you are either plain common sense or products of peoples imagination and ideas they have come up with based on your questions. It wouldn't kill you to sit and have a think about how to solve something before flooding this forum with question after question, one answer never seems to be enough for you. I hope when you release this app on the AppStore you quote the members of MacRumours as the lead developer!
     
  24. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #24
    The document in my previous post actually has the answer to this in it if you read and understand it.
     
  25. thread starter macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #25
    I used the code in the documentation,i got the below error in the line


    CGContextRef CreateARGBBitmapContext (CGImageRef inImage)

    //error: conflicting types for 'CreateARGBBitmapContext'
     

Share This Page