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

  • Home
  • SEARCH
  • 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 8492979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:52:48+00:00 2026-06-10T22:52:48+00:00

I have firstly convert the image to raw pixels and again convert the pixels

  • 0

I have firstly convert the image to raw pixels and again convert the pixels back to UIImage, after converting the image it changes it color and also become some transparent, I have tried a lot but not able to get the problem. Here is my code:

-(UIImage*)markPixels:(NSMutableArray*)pixels OnImage:(UIImage*)image{
CGImageRef inImage = image.CGImage;
// Create off screen bitmap context to draw the image into. Format ARGB is 4 bytes for each pixel: Alpa, Red, Green, Blue
CGContextRef cgctx = [self createARGBBitmapContextFromImage:inImage];
if (cgctx == NULL) { return nil; /* error */ }
    size_t w = CGImageGetWidth(inImage);
size_t h = CGImageGetHeight(inImage);
CGRect rect = {{0,0},{w,h}};
// Draw the image to the bitmap context. Once we draw, the memory
// allocated for the context for rendering will then contain the
// raw image data in the specified color space.
CGContextDrawImage(cgctx, rect, inImage);
// Now we can get a pointer to the image data associated with the bitmap
// context.
int r = 3;
int p = 2*r+1;
unsigned char* data = CGBitmapContextGetData (cgctx);
int i = 0;
while (data[i]&&data[i+1]) {
    //        NSLog(@"%d",pixels[i]);
    i++;
}
NSLog(@"%d %zd %zd",i,w,h);
NSLog(@"%ld",sizeof(CGBitmapContextGetData (cgctx)));
for(int i = 0; i< pixels.count-1 ; i++){
    NSValue*touch1  = [pixels objectAtIndex:i];
    NSValue*touch2  = [pixels objectAtIndex:i+1];
    NSArray *linePoints = [self returnLinePointsBetweenPointA:[touch1 CGPointValue] pointB:[touch2 CGPointValue]];
    for(NSValue *touch in linePoints){
        NSLog(@"point = %@",NSStringFromCGPoint([touch CGPointValue]));
        CGPoint location = [touch CGPointValue];
        for(int i = -r ; i<p ;i++)
            for(int j= -r; j<p;j++)
            {
                if(i<=0 && j<=0 && i>image.size.height && j>image.size.width)
                    continue;
                NSInteger index = (location.y+i) * w*4 + (location.x+j)* 4;
                index = 0;
                data[index +3] = 125;
            }
    }
}
// When finished, release the context
CGContextRelease(cgctx);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGDataProviderRef dp = CGDataProviderCreateWithData(NULL, data, w*h*4, NULL);
CGImageRef img = CGImageCreate(w, h, 8, 32, 4*w, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big, dp, NULL, NO, kCGRenderingIntentDefault);
UIImage* ret_image = [UIImage imageWithCGImage:img];
CGImageRelease(img);
CGColorSpaceRelease(colorSpace);
// Free image data memory for the context
if (data) { free(data); }
return ret_image;
}

enter image description hereenter image description here

First one is original image and second image is after applying this code.

  • 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-06-10T22:52:50+00:00Added an answer on June 10, 2026 at 10:52 pm

    You have to ask the CGImageRef if it uses alpha or not, and the format of the components per pixel – look at all the CGImageGet… functions. Most likely the image is not ARGB but BGRA.

    I often create and render pure green images then print out the first pixel to insure I got it right (BGRA -> 0 255 0 255) etc. It really gets confusing with host order etc and alpha first or last (does that mean before host order is applied before or after?)

    EDIT: You told the CGDataProviderCreateWithData to use ‘kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big’, but I don’t see you asking the original image for how its configured. My guess is that changing ‘kCGBitmapByteOrder32Big’ to ‘kCGBitmapByteOrder32Little’ will fix your problem but the alpha may be wrong too.

    Images can have different values for alpha and byte order so you really need to ask the original image how its configured then adapt to that (or remap the bytes in memory to whatever format you want.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created firstly ASP.NET MVC 2 . and write more functionality. After I
Two things: Firstly - I have version 2 of a website located in a
firstly i have searched a lot and all topics seems to be C# :
Firstly a short description of what I have Images of the same size and
Firstly, I do not have any malicious intent out of this question. I would
ok so i have code that fundementally has this structure: firstly a main div
I have a modeling question related to profiles. Firstly, I have looked into using
see fiddle Firstly i am new to jquery. i have to make one cell
Firstly: I am totally a newbie for this kind of work. I have a
Firstly, Modifying may be the wrong term, I see a few people have posted

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.