• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
saving data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

saving data


  • Subject: saving data
  • From: daniel oberhoff <email@hidden>
  • Date: Sun, 16 Mar 2003 00:40:08 +0100

anyone have an idea why some NSData could refuse writing itself to a
file? i had this problem before, but i was under pressure then so i
just dropped it and tried something else that worked. this time i would
have to go over to quicktime and i'd like to check if this can be
repaired first. what i do is i grab pixels from an NSOpenGLContext
using glReadPixels into the bitmap data of a prepared NSBitmapImageRep,
get the tiff representation and tell that, since its just NSData, to
save itself to a file. i do this in a timer, but i cant think how this
would make it fail and before i had the problem without a timer. heres
the relevant code snippets:

obtaining the NSBitmapImageRep:

-(void) reshape {
[[self openGLContext] makeCurrentContext];
NSRect bounds = [self bounds];
glViewport((GLint) bounds.origin.x, (GLint) bounds.origin.y,
(GLint) bounds.size.width, (GLint) bounds.size.height);
[...projection bussiness...]
if (m_grabbuffer) delete[] m_grabbuffer;
m_grabbuffer = new int[(int) bounds.size.width * (int)
bounds.size.height];
m_bitmapimage = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:(unsigned char **)(&m_grabbuffer)
pixelsWide:(int) bounds.size.width pixelsHigh:(int) bounds.size.height
bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:(int)
bounds.size.width * 4 bitsPerPixel:32];
[self setNeedsDisplay:YES];
}

grabing the image:

-(void) grab {
if (m_bitmapimage = nil) return;
[[self openGLContext] makeCurrentContext];
NSRect bounds = [self bounds];
glReadPixels((GLint) bounds.origin.x, (GLint) bounds.origin.y,
(GLint) bounds.size.width, (GLint) bounds.size.height,
GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV,
m_grabbuffer);
if (![[m_bitmapimage TIFFRepresentation] writeToFile:[NSString
stringWithFormat:@"grabbed%d.tif", m_grabcount++] atomically:NO])
NSLog(@"failed to write grabbed");
}


the latter method gets called by a timer and that works (i get lotsa
"failed to write grabbed" messages!).

since ideally this way of saving data is kinda cool and easy id like to
figure it out. thanx for help!!

daniel
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Some really simple release/autoRlease questions
  • Next by Date: Trouble with a save panel
  • Previous by thread: NSBrowser selections lag a click behind
  • Next by thread: Trouble with a save panel
  • Index(es):
    • Date
    • Thread