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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:06:10+00:00 2026-05-19T12:06:10+00:00

I have looked through replacing colors in an image but cannot get it to

  • 0

I have looked through replacing colors in an image but cannot get it to work how i need because I am trying to do it with every color but one, as well as transparency.

what I am looking for is a way to take in an image and split out a color (say all the pure black) from that image. Then take that split out portion and make a new image with a transparent background and the split out portion.

(here is just an example of the idea, say i want to take a screenshot of this page. make every other color but pure black be transparent, and save that new image to the library, or put it into a UIImageView)

i have looked in to CGImageCreateWithMaskingColors but cant seem to do what I need with the transparent portion, and I dont really understand the colorMasking input other than you can provide it with a {Rmin,Rmax,Gmin,Gmax,Bmin,Bmax} color mask but when I do, it colors everything. any ideas or input would be great.

  • 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-05-19T12:06:10+00:00Added an answer on May 19, 2026 at 12:06 pm

    Sounds like you’re going to have to get access to the underlying bytes and write code to process them directly. You can use CGImageGetDataProvider() to get access to the data of an image, but there’s no guarantee that the format will be something you know how to handle. Alternately you can create a new CGContextRef using a specific format you know how to handle, then draw the original image into your new context, then process the underlying data. Here’s a quick attempt at doing what you want (uncompiled):

    - (UIImage *)imageWithBlackPixels:(UIImage *)image {
        CGImageRef cgImage = image.CGImage;
        // create a premultiplied ARGB context with 32bpp
        CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
        size_t width = CGImageGetWidth(cgImage);
        size_t height = CGImageGetHeight(cgImage);
        size_t bpc = 8; // bits per component
        size_t bpp = bpc * 4 / 8; // bytes per pixel
        size_t bytesPerRow = bpp * width;
        void *data = malloc(bytesPerRow * height);
        CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
        CGContextRef ctx = CGBitmapContextCreate(data, width, height, bpc, bytesPerRow, colorspace, bitmapInfo);
        CGColorSpaceRelease(colorspace);
        if (ctx == NULL) {
            // couldn't create the context - double-check the parameters?
            free(data);
            return nil;
        }
        // draw the image into the context
        CGContextDrawImage(ctx, CGRectMake(0, 0, width, height), cgImage);
        // replace all non-black pixels with transparent
        // preserve existing transparency on black pixels
        for (size_t y = 0; y < height; y++) {
            size_t rowStart = bytesPerRow * y;
            for (size_t x = 0; x < width; x++) {
                size_t pixelOffset = rowStart + x*bpp;
                // check the RGB components of the pixel
                if (data[pixelOffset+1] != 0 || data[pixelOffset+2] != 0 || data[pixelOffset+3] != 0) {
                    // this pixel contains non-black. zero it out
                    memset(&data[pixelOffset], 0, 4);
                }
            }
        }
        // create our new image and release the context data
        CGImageRef newCGImage = CGBitmapContextCreateImage(ctx);
        CGContextRelease(ctx);
        free(data);
        UIImage *newImage = [UIImage imageWithCGImage:newCGImage scale:image.scale orientation:image.imageOrientation];
        CGImageRelease(newCGImage);
        return newImage;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked through GDB documentation, but haven't found anything that works or shows
I have looked through the Ruby on Rails guides and I can't seem to
I have looked through the documentation and the only reference I can find is
I have looked through several answers for loading CSS pages. http://docs.djangoproject.com/en/dev/howto/static-files/ Basically, I believe
I have looked through the whole set of Oracle Database 11g Release 2 (11.2)
I have a simple web page that displays some text and images and trying
I have a program written in Ruby that uses multiple levels of inheritance. All
I currently have a NSView in a NSScrollView. The NSView is large and I
I have group of jQuery Tabs that are created dynamically. Each tab has an

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.