Fill a part of an image

Hi everybody,
I'm a new french iPhone developer
I'm searching since few days how to fill a part of an image for my iPhone application.
I think that I must use the CGContext functions but I found not anything... I understood how make few operations on my UiImageView. But I draw an eclipse, a rect... but not a "zone"?
I've an example for explain my idea :
http://uploads.bodin-hullin.net/41be0528efcdf5170b0acd18ebe210f6.png
The square is the UIImage.
When I touch the #1 circle, this circle is filled with my color.
When I touch the #2 circle, the same, with another color why not.
Can you help me ?
Thanks for all
Message was edited by: jacquesbh

Hi Jacques-
again, this isn't the only approach, but here's something that could work.
#1) Separate the individual shapes into individual images, white with black background. To make things easier, save in a format that does not have an alpha channel. (keeping each shape in its relative position within your bounds). I'd suggest trying a 50% gray for the lines and adjust later if needed. Just do this to a few images to try out the code.
#2) In the code fragment I posted before, set "image" to one of those saved files. This should give you a colorized image, keeping the black background.
#3) If you wish to remove the background, it's much more complex, but try the following:
add a method like so:
- (UIImage *)maskImg: (NSString *) filename
CGColorRef fillColor = [UIColor yellowColor].CGColor; // Yellow for test
CGImageRef baseImage = [[UIImage imageNamed:filename] CGImage];
CGImageRef maskImage;
CGContextRef context;
CGColorSpaceRef colorSpace;
colorSpace = CGColorSpaceCreateDeviceRGB();
// create a bitmap graphics context the size of the image
context = CGBitmapContextCreate (NULL, self.bounds.size.width, self.bounds.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);
// free the rgb colorspace
CGColorSpaceRelease(colorSpace);
if (context==NULL)
return NULL; // avoid errors
CGContextDrawImage(context, self.bounds, baseImage);
CGContextSetBlendMode (context, kCGBlendModeMultiply);
CGContextSetFillColorWithColor(context, fillColor);
CGContextFillRect(context, self.bounds);
CGContextSetBlendMode (context, kCGBlendModeNormal);
baseImage = CGBitmapContextCreateImage(context);
//baseImage = [self remAlpha:baseImage]; //should work without this line and method if images don't have an alpha channel
const float myMaskingColors[6] = { 0, 0, 0, 0, 0, 0 }; // can be a range, in this case we only want to mask out black
maskImage = CGImageCreateWithMaskingColors (baseImage, myMaskingColors);
CGContextRelease(context);
UIImage *img = [UIImage imageWithCGImage:maskImage];
//CGImageRelease(bitmap);
CGImageRelease(maskImage);
CGImageRelease(baseImage);
// return the image
return img;
and then in the drawRect, you'd just do something like:
UIImage *img = [self maskImg:@"test.jpg"]; //for testing
[img drawInRect:rect];
for your end purposes, you may want to add the color as another parameter of the maskImg method.... this stuff can be very tricky sometimes to setup... I know I experimented for hours getting no image, or a solid color block, etc... before perfecting this code.... hope this works for you..
I don't think you need to call this method if your images don't have an alpha channel, but I'm including it just in case:
-(CGImageRef)remAlpha:(CGImageRef)ref
//CGImageRef ref=img.CGImage;
int mWidth=CGImageGetWidth(ref);
int mHeight=CGImageGetHeight(ref);
int count=mWidthmHeight4;
void *bufferdata=malloc(count);
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
CGContextRef cgctx = CGBitmapContextCreate (bufferdata,mWidth,mHeight, 8,mWidth*4, colorSpaceRef, kCGImageAlphaPremultipliedLast);
CGRect rect = {0,0,mWidth,mHeight};
CGContextDrawImage(cgctx, rect, ref);
bufferdata = CGBitmapContextGetData (cgctx);
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, bufferdata, mWidthmHeight4, NULL);
CGImageRef savedimageref = CGImageCreate(mWidth,mHeight, 8, 32, mWidth*4, colorSpaceRef, bitmapInfo,provider , NULL, NO, renderingIntent);
CFRelease(colorSpaceRef);
return savedimageref;

Similar Messages

  • Help with Live Paint - filling in part of an image

    I have imported a dfw image into illustrator. It's a black and white image of an object similar to the one below:
    I want to paint the areas around the perimeter of the image black so that it looks like it has a large black outline (the areas that contain the X's). I've been able to do it on a few but some of the images, when I open them, the live paint selects only inner areas that I don't want painted. I can't figure out how to change the paths to the ones I want.
    I import the image, select all, Object>Live Paiint>Make. Then I set the fill to black. In this example, there are 3 stripes on each pants leg and the only thing Live Paint will select is the outermost stripe. I've tried Object>LivePaint>Expand then reselect the Live Paint Buckeet and click the image when it says, "Click to make Live Paint Group" but nothing changesso that I can paint the desired areas.
    I've checked the image closely to ensure there are no breaks in the paths and I've just spent the last 4 hours reading instructions and watching videos but no help. I'm braind new ti Illustrator and must be missing something bassic but don't know what. Any help would be appreciated. I'm stumped.

    I should have posted this hours ago. As soon as I did I found the answer. For anyone else with this problem, Select the image then, before using the Live Paint Bucket, select Object>Flatten Transparacy. Then, when you select the live paint bucket, it will ask for you to set the paths and after you do, it'll work just fine.

  • Using applet to select a part of an image and then save it

    Hi ,
    I want to use applet to select a part of an image and then save that particular selected part to a server. can anyone provide me a code for this. I have found codes on the sun site which help in uploading an image but I am having trouble in trying to select a part of the image.

    Sorry to get back to you so late, but I was away from my computer this afternoon.
    I'm not sure just what you are after. I do see that you have positioned the tree on the labels. I went to the web site for the label company, and their instructions are not too helplful.
    http://www.pixentral.com/show.php?picture=15sBkl9OZE9xSkHoLMxgwjTFv2VCg1
    I changed the white portion of 1 label to black - - this can be any color. To do this use the magic wand tool, tolerance=10 worked for me, then go to Edit>fill selection.

  • Display part of an image in a box

    I have a script that places several images in boxes using script labels.  I use the command, "fit myrect3 given content to frame" and that works great for all images but one.  One image is larger than the box and I only want to show a portion of the image.  Currently I move the image manually until I can only see the part of the image I want.  The image is always formatted the same so I wanted to know if there is a command to insert an image in a box with an offset so only part of the image shows?

    Are you targeting the image object within the rectangle for the move command? Here are two examples one using the 'move' method the other by getting the 'bounds' and repositioning by changing those. If you get the bounds of the containing rectangle too then you should be able to use some math on how to fill & position within the rectangle.
    set This_Image to choose file
    tell application "Adobe InDesign CS2"
    tell active document
    tell page 1
    tell rectangle 1
    place This_Image
    move image 1 by {-10, -10}
    end tell
    end tell
    end tell
    end tell
    set This_Image to choose file
    tell application "Adobe InDesign CS2"
    tell active document
    tell page 1
    tell rectangle 1
    place This_Image
    set {Rect_T, Rect_L, Rect_B, Rect_R} to geometric bounds
    set {Pict_T, Pict_L, Pict_B, Pict_R} to geometric bounds of image 1
    set geometric bounds of image 1 to ¬
    {Pict_T - 10, Pict_L - 10, Pict_B - 10, Pict_R - 10}
    end tell
    end tell
    end tell
    end tell

  • Illustrator is chopping off a part of my image when exporting

    Okay so I have an image I created on a canvas that is larger than the image. When I export the image as a png, I get the image without any of the white space there was surrounding in illustrator and a very small part of the image is actually chopped off ... Is there anyway I can get illustrator to export the entire canvas or at least not chop off a part of the image if it is going to auto-crop?
    Thanks

    Add a rectangle the size of your artboard, or at least larger than the rest of the artwork, fill it with white but no stroke and send it behind the rest of the artwork. Save and export. The result should be the size of the white background.
    Not a good solution if you want the background transparent. In that case, put a stroke around the rectangle but no fill. Then, upon export, open it in Photoshop and crop out the stroke around the outside. If you are using some other program to manipulate it, you should be able to crop out the stroke there as well.

  • Best Way to get part of a image

    Hi , i´m trying to achieve a behaviour with bitmaps but a little bit confused.
    Objective:
    (As shown in image attached)
    I have a Movieclip with a static Shape on Stage ( Let´s say ... a star)
    I would like to load a image(img1) , then i would be able to, rotate, zoom , and pan the image(img1).
    Then i would have only the star but filled with the part of the image that fitted that star.
    I was trying to  get bitmapData from the image, then draw the star on the image.... And at end, compare color pixels and only getting the ones i want to.... but i get a big mess with the rotations, scale and position of star to be exactly on the place it should be draw...
    Something tell´s me that i´m missing a point and it should be easier...
    Can anyone give me directions ?
    It´s a kind of masking, but i want to save that image only then...
    Thanks in advance!

    I would:
    1) Move and translate your image clip
    2) Set the star as the mask
    3) Once the mask is applied, use BitmapData.draw to draw the masked image to a new bitmap data
    4) TADA!
    As far as I am aware, 'draw' should respect masks? If it doesn't then you may need to put clip+mask inside another DisplayObject and draw that.  Some psuedo code (not tested, and simplified):
    // Parent object
    var canvas : Sprite = new Sprite();
    canvas.addChild( clip );
    canvas.addChild( star );
    // Manipulate your image
    clip.rotation = 35;
    clip.scaleX = clip.scaleY = 1.2;
    // Set mask and position it
    clip.mask = star;
    star.x = 40;
    star.y = 20;
    // Create a bitmap data and draw to it
    bitmapData = new BitmapData( Math.ceil(canvas.width), Math.ceil(canvas.height), true, 0x00000000 );
    bitmapData.draw( canvas, ...... );
    // You may need to use canvas.getBounds and create a matrix to get 'canvas' positioned correctly on the bitmapData
    Hope it helps,
    Peter

  • I need to replace a color on my image with a specific color from another part of the image.  How?!

    I have spent over 2 hours trying to figure out how to replace a color on one part of my image with a specific color shown on another part of the image.  So far I have been able to go to "Replace Color" on my Adobe Photoshop version, but it seems that I can only change the hue and brightness of the color that it currently is.  I need to use a specific color so this does not help me.  Does anyone know how to complete the task I am referring to?
    Also, please keep in mind that I am using Adobe Photoshop 6.0, not a fancy cs version or anything.  So it's pretty old school...
    Any help/feedback is greatly appreciated!  Thank you.

    Hi brookehelene,
    You might consider making a selection the object and using a color fill layer set to the color blend mode instead of replace color.
    I used the same picture as kendallplant did and changed the color on the same flower by sampling the pink color from the flower to the right)
    (click on the screenshots below for larger views)
    1. Select>Color Range
       (i used color range because the dialog is somewhat similar to the replace color dialog, except one is making a selection instead of replacing a color)
       (there are many other ways to make the selection such as the magic wand, so if your more familar with the other selection tools you can use those instead to make your selection)
    2. Use the eyedroppers and fuzziness slider in the color range dialog to make the selection of the object.
       (in the screenshot below the white areas are selected and black areas are not)
       (your selection probably won't be perfect, but you can paint on the layer mask to refine the selection)
    3. After you press the okay in the color range dialog you'll see the selection (marching ants)
       At the bottom of the layers palette press the Create New Fill or Adjustment Layer icon
       to reveal a list and choose Solid Color.
       Then use the eyedropper to sample a color from your image and press ok.
       Change the Blend mode for the color fill layer to Color (top of the layers palette)
    4. As you can see a lot has been selected besides the flower.
        To refine the areas of color, paint on the layer mask with the paintbrush tool.
        Use white to add the color or black to subtract the color
        You can press the D key on the keyboard to get the default colors (black and white) in the toolbox
        and press the X key to switch between the two when painting on the layer mask.
    Even though the above takes longer you can easily change the color or modify the areas that you want to change the color on.
    To change the color you can double click on the color fill icon in the layers panel.
    You can also use other layer blend modes besides color such as hue, so you might try some of the others and see what they do.

  • How to display different parts of an image

    hi,
    I need to display different parts of an image at specific situations.
    for example, a dice. there is only one image which includes different sides of the dice. and I wanna add
    to my panel one side if one comes, two side if two comes... I mean if one comes then we will display
    from 10 px to 80 px width and from 10 px to 80 px height of the dice image.
    is there any way to obtain this in java?
    thanks...

    import java.awt.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.util.Random;
    import javax.swing.*;
    public class ImageClipping extends JPanel {
        BufferedImage image;
        Rectangle clip;
        final int ROWS = 3;
        final int COLS = 3;
        public ImageClipping() {
            // Make an image we can clip.
            Dimension d = getPreferredSize();
            int type = BufferedImage.TYPE_INT_RGB;
            image = new BufferedImage(d.width, d.height, type);
            Graphics2D g2 = image.createGraphics();
            g2.setBackground(getBackground());
            g2.clearRect(0, 0, d.width, d.height);
            Font font = g2.getFont().deriveFont(36f);
            g2.setFont(font);
            FontRenderContext frc = g2.getFontRenderContext();
            LineMetrics lm = font.getLineMetrics("0", frc);
            float sh = lm.getAscent() + lm.getDescent();
            int xInc = d.width/COLS;
            int yInc = d.height/ROWS;
            for(int j = 0; j < ROWS; j++) {
                for(int k = 0; k < COLS; k++) {
                    String s = String.valueOf(j*COLS + k+1);
                    float sw = (float)font.getStringBounds(s, frc).getWidth();
                    float sx = k*xInc + (xInc - sw)/2;
                    float sy = j*yInc + (yInc + sh)/2 - lm.getDescent();
                    g2.setPaint(Color.red);
                    g2.drawString(s, sx, sy);
                    g2.setPaint(Color.blue);
                    g2.drawRect(k*xInc, j*yInc, xInc-1, yInc-1);
            g2.dispose();
            clip = new Rectangle(xInc, yInc);
            // Inspect image.
            ImageIcon icon = new ImageIcon(image);
            JOptionPane.showMessageDialog(null, icon, "", -1);
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            Shape origClip = g2.getClip();
            //g2.setPaint(Color.red);
            //g2.draw(clip);
            // Draw clipped image at:
            int x = 100;
            int y = 100;
            // Mark location.
            g2.setPaint(Color.red);
            g2.fill(new Ellipse2D.Double(x-2,y-2,4,4));
            // Position the image.
            g2.translate(x-clip.x, y-clip.y);
            // Clip it and draw.
            g2.setClip(clip);
            g2.drawImage(image,0,0,this);
            // Reverse the changes to the graphics context.
            g2.setClip(origClip);
            g2.translate(clip.x-x, clip.y-y);
        public Dimension getPreferredSize() {
            return new Dimension(400,400);
        public static void main(String[] args) {
            ImageClipping test = new ImageClipping();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(test);
            f.pack();
            f.setLocation(50,50);
            f.setVisible(true);
            test.start();
        private void start() {
            Thread thread = new Thread(runner);
            thread.setPriority(Thread.NORM_PRIORITY);
            thread.start();
        private Runnable runner = new Runnable() {
            Random seed = new Random();
            Dimension d = getPreferredSize();
            int xInc = d.width/COLS;
            int yInc = d.height/ROWS;
            public void run() {
                do {
                    try {
                        Thread.sleep(3000);
                    } catch(InterruptedException e) {
                        break;
                    int row = seed.nextInt(ROWS);
                    int col = seed.nextInt(COLS);
                    int x = col*xInc;
                    int y = row*yInc;
                    int n = row*COLS + col+1;
                    System.out.printf("row = %d  col = %d  n = %d%n",
                                       row, col, n);
                    clip.setLocation(x,y);
                    repaint();
                } while(isVisible());
    }

  • How can I select only a small part of the image to clone or edit etc?

    I want to select part of the image to clone is, and just edit the selected part. I know i can do this on photoshop but how do i do it on Aperture?

    You use the "Retouche" brush in Aperture and set it to "clone".
    Option-Click on the location you want to clone from to select a source, and then brush over the location where you want to clone to. The cloned region will follow the shape of the brushed area. You do not lasso the shape to to copy and paste it like in Photoshop.
    For example: Duplicating a penguin: The sourcepoint has been set to the beak of the second penguin, and then I brushed along the path where I want to penguin clone to appear.
    If I brush the whole area eventually the penguin will be copied completely. You'll have to experiment a bit with the brush size and softnees to ensure that the cloned object will blend in.
    Regards
    Léonie

  • I have Office 2011 which includes Word.  Ever since downloading Mavericks, when I try to send a two-page word document, some recipients get only one page.  Also sometimes when I burn an image from iPhoto on to a disc, only part of the image appears.  Why?

    I have Office 2011 which includes Word.  Ever since downloading Mavericks, when I try to send a two-page Word document by email, some recipients get only one page.  Also when burning an image from iPhoto (usually no larger than 1mb) on to a disc, only part of it appears.  It appears to have been magnified so that only a part of the image appears.  Can anyone enlighten me as to what is happening?  And how to fix it??

    I have Office 2011 which includes Word.  Ever since downloading Mavericks, when I try to send a two-page Word document by email, some recipients get only one page.  Also when burning an image from iPhoto (usually no larger than 1mb) on to a disc, only part of it appears.  It appears to have been magnified so that only a part of the image appears.  Can anyone enlighten me as to what is happening?  And how to fix it??

  • My Photoshop CS 5 has some strange actions when I copy a portion of a photo using the clone stamp  to transfer to another part of the image. It carries the entire layer (not just the stamps selection) across the screen and I cannot place it where I need t

    My Photoshop CS 5 has some strange actions when I copy a portion of a photo using the clone stamp  to transfer to another part of the image. It carries the entire layer (not just the stamps selection) across the screen and I cannot place it where I need to. It appears as if I selected the entire layer on purpose (which I did not)
    The below items appeared when I opened Photoshop CS 5:
    “Photoshop has encountered a problem with the display driver and has temporarily disabled G & U enhancements. Check the video card malfunctions website for latest software. GPU enhancements can be enabled in the performance panel of preferences.”
    (I believe this started after the automatically updated Windows was applied. It was coincident with the before mentioned problem . . . but I don’t really know if it had anything to do with it. )

    For the Clone Stamp problem, check the Clone Source panel and Clipped is probably unchecked.
    If so, check Clipped and see if that makes a difference.
    (Window>Clone Source)
    As to the video card problem:
    Which version of windows are you using?
    What is the make and model of your graphics card?
    Do you know which update windows installed?

  • How do you cut out the part of an image in a photo?

    How do you cut out a part of an image on a photo that you have added to Pages. For example, if I have added a picture of a giraffe to Pages how would I cut out the giraffe from the image and get rid of the rest of the image

    You can use the instant alpha tool to make the background transparent.
    FYI: Pages is part of iWork, not iLife.

  • Is it possible to work only on a small part of the image in FCP ?

    Hello,
    I"m working on a DV film that I have made this winter, but on the original film, the image (video) is a lot darker on both top corners (I have some problems with my camera when I use it outside during the winter).
    Is there any way to work only on a part of the image with a filter, instead of working on the whole image. I would like to work on thoses 2 darker spot without touching the rest of the image.
    Thanks

    What you need to do is color correct just those two portions of the image. In a DaVinci and Final Touch this is called using "power windows." Now, you can do this one of two ways.
    1) Layer the same clip on the timeline 3 times. V1, V2 and V3. Same start and end time on all clips. Now, use the 4-point garbage matte on the clips on the upper layers to isolate those sections and then apply the 3-way color corrector to brighten the images.
    2) Colorista by Red Giant Software (www.redgiantsoftware.com) is a $200 color correction filter that allows you to layer color correction and isolate specific areas...using POWER WINDOWS in effect.
    Shane

  • In iPhoto, how can I export images with the metadata - including the title and caption information - intact as part of the image?

    In iPhoto, how can I export images with the metadata — including the title and caption information — intact as part of the image?

    Check those boxes in the export dialogue - Exporting From iPhoto
    LN

  • Parts of PDF image missing

    I am very puzzled. I downloaded an owners manual from the manufacturer's website in PDF format. I downloaded to my MacBook Pro, and on my Macbook Pro, the manual is perfect. However, when I move the manual to the Books section of iTunes and upload it to iBooks, parts of the exploded diagrams are missing. In fact, in some cases, some of the entire image is missing. Instead of going that way, I uploaded it to Dropbox. Once again, on my MacBook Pro, the manual is perfect. When I look at my Dropbox folder on the web (via Safari), it's parfect. But when I access Dropbox through my iPad, parts of the images are missing. When I went to the manufacturer's website via Safari on my iPad and looked at the manual online via my iPad, the same parts of the images are missing. The text is all perfect. I have never had this happen to me before, and I keep a LOT of manuals, articles and magazines on my iPad. Does anyone know why this could be happening and what, if anything, I can do about it?

    Not enough info. What version of ID? What version of AI?
    How are you saving the AI files? What are you PDF export settings?
    Have you checked everything with overprint preview on?
    Bob

Maybe you are looking for

  • How do I change the email account for icloud on my iphone only

    How do I change the email account for icloud on my iphone6 only.  I don't want to change my ipad or my husband's iphone6.  Currently all 3 devices have the same gmail account associated with them.  I have created a new & separate apple id and I want

  • C-stored procedure in Oracle

    Dear Friends, I have a lot of c-stored procedures for DB2, now,I want to use these c-stored procedures in Oracle directly without any changes. I'm not sure whether this method is right. Please help me. Guang

  • Import Server - Multiple Qualified Table - Map Crash

    Hello, Requirement: I need to update multiple qualified table using single source file. Preparation: I have created a map where mapping to multiple qualified table fields maually.                    Have created a Inbound Port using the above map. Pr

  • Difference between SAP SLD and SAP Management console

    Hello, It seems that both System landscape directory and SAP management console have some overlapping features. The services can be started or stopped in both. Is it true? Does anyone know the difference between these 2 and where does Solution manage

  • Apply XSLT  while importing the xml to the selected node in structure view

    Hi All, I would like to apply XSLT while importing the xml file to the selected node in the structure view. How to go about it? Thanks Sakthi