0

I have a very large image that I would like to show a 200x200px thumbnail of (showing a portion of the image, not a strethed version of the entire image). To achieve this I am looking into using CIImage.ImageByCroppingToRect or CICrop - but I am not able to get anything useful. Either the result is just black (I assume what I see is the black portion of the cropped image) or I get a SIGABRT ("Cannot handle a (6000 x 3000) sized texture with the given GLES context!")

There is a ObjC sample in this thread: Cropping CIImage with CICrop isn't working properly

But I haven't managed to translate it in to C# and get it working properly.

Community
  • 1
  • 1
Johan
  • 780
  • 7
  • 22

1 Answers1

3

Here's a MonoTouch port of the answer from the post you mentioned:

var croppedImaged = CIImage.FromCGImage (inputCGImage).ImageByCroppingToRect (new RectangleF (150, 150, 300, 300));              
var transformFilter = new CIAffineTransform();
var affineTransform = CGAffineTransform.MakeTranslation (-150, 150);
transformFilter.Transform = affineTransform;
transformFilter.Image = croppedImaged;           
CIImage transformedImage = transformFilter.OutputImage;
Mike Bluestein
  • 706
  • 3
  • 7
  • Thank you! That code indeed works - unless the image you want cropped is larger than 4096x4096 because than the SIGABRT will come. Not sure wether that is a limitation in iOS, MonoTouch, iPhone Simulator or just my computer... – Johan Apr 29 '12 at 21:01
  • 2
    This is a limitation of the GPU on the device. You can avoid using the GPU by requesting the software renderer in your CIContext construction: CIContext.FromOptions (new CIContextOptions () { UseSoftwareRenderer = true }) – miguel.de.icaza Apr 30 '12 at 01:09
  • Thank you Miguel, but that actually returns null instead of a valid CIContext (at least on the Simulator - I haven't tried with an actual device yet). – Johan May 01 '12 at 08:32