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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:21:55+00:00 2026-05-21T17:21:55+00:00

I have a structure which includes a pointer to a data set, which in

  • 0

I have a structure which includes a pointer to a data set, which in this case is a 16-bit grayscale image. I want to convert this data to an NSImage so that I can display it, and then save it as a .TIF file. The route from the manuals appears to be something like:

(Create *myNSImData from frame->image, which is a pointer)
NSImage *TestImage = [[NSImage alloc] initWithData : myNSImData];
(display TestImage, save it, whatever else)
[TestImage release];

I am lost as to how to create the NSData object and assure it contains the array of 16-bit data. Attempts to recast the pointer give warnings and no data. I could simply increment the pointers, transferring one byte at a time from frame->image to the data object, but I don’t understand how to communicate the array structure to the data object. Any ideas?
Thanks

MORE ATTEMPTS USING YOUR SUGGESTION
I can convert this data to a .TIF file in the following manner:

for (uint32 row = 0 ; row < MaxHeight ; row++)  
{
    for (uint32 column = 0;column< MaxWidth;column++)
    {
        tempData = (uint8_t)*frame->image;  //first byte
        *frame->image++;
        buf[2 * column + 1] = (unsigned char) tempData;
        tempData = (uint8_t)*frame->image;  //second byte
        *frame->image++;
        buf[2 * column] = (unsigned char) tempData;
    }
    TIFFWriteScanline(tiffile,buf,row,0);
}

With the .TIF file thus generated, I can create an NSImage and display it:

NSImage *TestImage = [[[NSImage alloc] initWithContentsOfFile:inFilePath] autorelease];
[viewWindow setImage: TestImage];

My question now becomes – can I create an NSData object that I can display in the same way? I have tried the following (product is the height*width of the image):

NSData *ReadImage = [[[NSData alloc] initWithBytes: frame->image length:2*product]  autorelease] ;
NSImage *NewImage = [[[NSImage alloc] initWithData:ReadImage] autorelease];
NSSize newSize;
newSize.height = MaxHeight; //height of the image
newSize.width = MaxWidth; //width of the image
[NewImage setSize:newSize];
[viewWindow setImage: NewImage];

When I try this, nothing displays. I have also tried creating an array of uint16_t which has the data, and serving up the pointer to that – again, nothing displays. Any ideas? E.g. do I have to tell the NSData that I am using 2 bytes per pixel, or something like that? Thanks Monty Wood

  • 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-21T17:21:56+00:00Added an answer on May 21, 2026 at 5:21 pm

    To create an NSData object containing a block to which you have a pointer, you should use one of the three methods that start with initWithBytes:, or, to create an autoreleased NSData object, use one of the class methods that start with dataWithBytes:

    UPDATE: I think that if you want to create an NSImage directly from an NSData, the data needs to include the appropriate headers/magic numbers so that NSImage can figure out what the representation is. You should look at NSBitmapImageRep and the Images chapter of the Cocoa Drawing Guide for raw image data.

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

Sidebar

Related Questions

I have a structure which I need to populate and write to disk (several
I have a structure which I create a custom constructor to initialize the members
We have redesigned the structure to a website which has several business units. Now
I have a database structure that has a Person table which contains fields such
I have a table in my database which stores a tree structure. Here are
I have a java class which fires custom java events. The structure of the
I have a structure like this: <ul> <li>text1</li> <li>text2</li> <li>text3</li> </ul> How do I
I have a recursive call which includes an asyn operation (file copy) .. I
I have a structure in C#: public struct UserInfo { public string str1 {
I have a structure: struct pkt_ { double x; double y; double alfa; double

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.