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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:30:51+00:00 2026-05-25T06:30:51+00:00

I am trying to create a new Image from raw data in unsigned char

  • 0

I am trying to create a new Image from raw data in unsigned char *. I have the bits per pixel from the data stored.
I tried converting raw data into NSData, But result image was nil,

unsigned char *bitmap = myData;

NSUInteger myImageDataLength = strlen( (const char*)bitmap);

NSData *d = [NSData dataWithBytes:bitmap length:myImageDataLength];

imgView.image = [UIImage imageWithData:d];

Then I tried using context to create an image as follows:

CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
int width = mWidth;
int height = mHeight;
size_t bpp = mBpp;
size_t bpc = 8;
size_t bpr = (width * 4);
CGContextRef context = CGBitmapContextCreate(bitmap, width, height, 8, bpr, colorspace, kCGImageAlphaNone);
CGImageRef cgImage = nil;
if (context != nil) {
    cgImage = CGBitmapContextCreateImage (context);
    CGContextRelease(context);
}
CGColorSpaceRelease(colorspace);
UIImage *newImage = [UIImage imageWithCGImage:cgImage];

I am getting an error message like
<Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 24 bits/pixel; 3-component color space; kCGImageAlphaNone; 64 bytes/row.

I tried solving it by setting many values but cant find any result. I googled on internet to find this solution but all others are creating an image from existing images so they get the values of bits per components and all that… How can I create image from this data???

Original Image:

enter image description here

Resulting image:

enter image description here

Resulting image should be warped. (Warped same as fatBooth and other application)

  • 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-25T06:30:52+00:00Added an answer on May 25, 2026 at 6:30 am

    The following code creates a UIImage instance from raw pixel data assuming you have:

    • pixelData: the raw pixel data
    • imageWidth, imageHeight: the image dimensions
    • scanWidth: the number of bytes per scanline
    • bytesPerPixel: the number of bytes used per pixel, usually 4

    The resulting UIImage is assigned to the variable uiImage.

    CGDataProviderRef provider = CGDataProviderCreateWithData(
        NULL, 
        pixelData, 
        imageHeight * scanWidth, 
        NULL);
    
    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
    CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
    
    CGImageRef imageRef = CGImageCreate(imageWidth,
        imageHeight,
        8,
        bytesPerPixel * 8,
        scanWidth,
        colorSpaceRef,
        bitmapInfo,
        provider,
        NULL,
        NO,
        renderingIntent);
    
    UIImage *uiImage = [UIImage imageWithCGImage:imageRef];
    CGDataProviderRelease(provider);
    CGColorSpaceRelease(colorSpaceRef);
    CGImageRelease(imageRef);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a clustered image from data being returned from the
I'm trying to create a new project in NetBeans PHP from existing sources. When
I am trying to create a new branch using the API, and have used
New demo code: I am trying to get the captcha image from a AOL,
I am trying to copy a 5mb database file to data folder from raw
I'm trying to create image from SQLite database in Java Swing application. But it
I am trying to create an image from a byte array. The byte array
So I have a tile image tile.png and I'm trying to create a tiled
I am trying to create a new BST from the intersection of 2 known
Trying to create a transparent gif with PIL. So far I have this: from

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.