• 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
Re: help with NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help with NSImage


  • Subject: Re: help with NSImage
  • From: "M. Uli Kusterer" <email@hidden>
  • Date: Sat, 12 Feb 2005 14:14:30 +0100

At 12:11 Uhr +0000 12.02.2005, Daniel O'Sullivan wrote:
I'm a new to cocoa so this will probably sound rather basic, but i'm looking to display .ppm images using NSImage. Do i use NSQuickDrawView? if anyone could help me, it would be really appreciated especailly if theres any example code out there that i could view.

I don't think Cocoa or QuickTime support loading pbm and ppm images yet. IIRC, PPM is this text-based file format that uses numeric strings to encode each pixel, right? <http://netpbm.sourceforge.net/doc/ppm.html>


In that case, your best bet is to use NSString -stringWithContentsOfFile: to load the PPM, and then to parse that string for the actual image data using NSScanner. Create an NSImage once you know the proper size and draw the colored pixels into that.

If you're a seasoned C programmer, you might just want to create a memory buffer using malloc() and hand that to an NSBitmapImageRep created via -initWithBitmapDataPlanes:, after writing the image data directly to that buffer.

If you're new to programming in general, just do a lockFocus on the image and use NSBezierPath to draw a one-pixel "line" for each pixel, using NSColor to set the desired colors. That will be slower, but should be easier to work out than the pointer arithmetics you'd otherwise need.

If you have some portable C source code that parses PPMs and generates, say, an RGBA buffer from that, you can also just use that code and pass the buffer to -initWithBitmapDataPlanes: above.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
References: 
 >help with NSImage (From: "Daniel O'Sullivan" <email@hidden>)

  • Prev by Date: NSImageView only for images?
  • Next by Date: Re: NSImageView only for images?
  • Previous by thread: Re: help with NSImage
  • Next by thread: Re: help with NSImage
  • Index(es):
    • Date
    • Thread