<div dir="ltr"><div class="gmail_extra">Okay, I looked at my Darwin sources which use minimal wrappers around the inbuilt Quartz classes to handle image loading, saving, and pixel data access.</div><div class="gmail_extra"><br></div><div class="gmail_extra">To load any image (png, jpg, bmp, gif, ect) you use a CGImageSourceRef object.</div><div class="gmail_extra"><br></div><div class="gmail_extra">From file:</div><div class="gmail_extra"><br></div><div class="gmail_extra">ImageSource := CGImageSourceCreateWithURL(UrlRefCreateFromFileSystem(FileName).Handle, nil);<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">From a stream:</div><div class="gmail_extra"><br></div><div class="gmail_extra">ImageSource := CGImageSourceCreateWithData(DataRefCreate(Stream).Handle, nil);<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Then to access image data you need to create a bitmap context and tell the image source to populate the bitmap. My bitmap context create looks like this, which should give you a head start:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">constructor TBitmapContextRef.Create(Image: IImageRef; ColorSpace: TColorSpace = colorBGRA);</div><div class="gmail_extra">var</div><div class="gmail_extra">  R: CGRect;</div><div class="gmail_extra">begin</div><div class="gmail_extra">  Create(Image.Width, Image.Height);</div><div class="gmail_extra">  R.origin.x := 0;</div><div class="gmail_extra">  R.origin.y := 0;</div><div class="gmail_extra">  R.size.width := Image.Width;</div><div class="gmail_extra">  R.size.height := Image.Height;</div><div class="gmail_extra">  CGContextDrawImage(Handle, R, Image.Handle);</div><div class="gmail_extra">end;</div><div class="gmail_extra"><br></div><div class="gmail_extra">constructor TBitmapContextRef.Create(Width, Height: Integer; ColorSpace: TColorSpace = colorBGRA);</div><div class="gmail_extra">var</div><div class="gmail_extra">  PixelBytes: UIntPtr;</div><div class="gmail_extra">  C: CGColorSpaceRef;</div><div class="gmail_extra">  A: CGImageAlphaInfo;</div><div class="gmail_extra">  R: CGContextRef;</div><div class="gmail_extra">begin</div><div class="gmail_extra">  inherited Create(nil);</div><div class="gmail_extra">  PixelBytes := Width * Height * 4;</div><div class="gmail_extra">  FPixels := GetMem(PixelBytes);</div><div class="gmail_extra">  FillZero(FPixels^, PixelBytes);</div><div class="gmail_extra">  C := CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);</div><div class="gmail_extra">  A := ColorSpaceToAlpha(ColorSpace);</div><div class="gmail_extra">  R := CGBitmapContextCreate(FPixels, Width, Height, 8, Width * 4, C, A);</div><div class="gmail_extra">  CGColorSpaceRelease(C);</div><div class="gmail_extra">  HandleOwn(R);</div><div class="gmail_extra">end;</div><div class="gmail_extra"><br></div><div class="gmail_extra"><a href="https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGImageSource/">https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGImageSource/</a><br></div><div class="gmail_extra"><a href="https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGBitmapContext/">https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGBitmapContext/</a><br></div><div><br></div></div><div class="gmail_extra">You might be able to figure the rest out from there by yourself. If instead of figuring things out for yourself, you might to use want the Darwin graphics part of my library. For this you'll need two of my unit files:</div><div class="gmail_extra"><br></div><div class="gmail_extra">The first unit wraps the ref object management pattern used by Darwin and includes plus a few extra helper routines.</div><div class="gmail_extra">The second unit wraps the Quartz 2D objects and also includes a few simple helper routines.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Let me know if you want to contribute and I can upload some code to a repository on github. But please I would ask that if you have any improvements to my code (such as wrapping more classes), that you share those changes with everyone using the same github repository. I'll need you github account names add you guys as contributors.</div></div>