void GetImagaDataFromPath (string path) { NSImage src; CGImage image; CGContext context = null; src = new NSImage (path); var rect = RectangleF.Empty; image = src.AsCGImage (ref rect, null, null); width = image.Width; height = image.Height; data = new byte[width * height * 4]; CGImageAlphaInfo ai = CGImageAlphaInfo.PremultipliedLast; context = new CGBitmapContext (data, width, height, 8, 4 * width, image.ColorSpace, ai); // Core Graphics referential is upside-down compared to OpenGL referential // Flip the Core Graphics context here // An alternative is to use flipped OpenGL texture coordinates when drawing textures context.TranslateCTM (0, height); context.ScaleCTM (1, -1); // Set the blend mode to copy before drawing since the previous contents of memory aren't used. // This avoids unnecessary blending. context.SetBlendMode (CGBlendMode.Copy); context.DrawImage (new RectangleF (0, 0, width, height), image); }
public static Gdk.Pixbuf GetPixbufFromNSImage (NSImage icon, int width, int height) { var rect = new RectangleF (0, 0, width, height); var rep = icon.BestRepresentation (rect, null, null); var bitmap = rep as NSBitmapImageRep; try { if (bitmap == null) { if (rep != null) rep.Dispose (); using (var cgi = icon.AsCGImage (ref rect, null, null)) { if (cgi == null) return null; bitmap = new NSBitmapImageRep (cgi); } } return GetPixbufFromNSBitmapImageRep (bitmap, width, height); } finally { if (bitmap != null) bitmap.Dispose (); } }
public Task Save(CompressedBitmapFormat format, float quality, Stream target) { return(Task.Run(() => { #if UIKIT var data = format == CompressedBitmapFormat.Jpeg ? inner.AsJPEG((float)quality) : inner.AsPNG(); data.AsStream().CopyTo(target); #else var rect = new RectangleF(); var cgImage = inner.AsCGImage(ref rect, null, null); var imageRep = new NSBitmapImageRep(cgImage); var props = format == CompressedBitmapFormat.Png ? new NSDictionary() : new NSDictionary(new NSNumber(quality), new NSString("NSImageCompressionFactor")); var type = format == CompressedBitmapFormat.Png ? NSBitmapImageFileType.Png : NSBitmapImageFileType.Jpeg; var outData = imageRep.RepresentationUsingTypeProperties(type, props); outData.AsStream().CopyTo(target); #endif })); }
public ESTexture2D(NSImage nsImage, All filter) { // TODO InitWithCGImage(nsImage,filter); CGImage image = nsImage.AsCGImage (RectangleF.Empty, null, null); InitWithCGImage (image, filter); }
public IImage ImageFromFile(string filename) { #if MONOMAC var img = new NSImage ("Images/" + filename); return new UIKitImage (img.AsCGImage (new RectangleF (PointF.Empty, img.Size), NSGraphicsContext.CurrentContext, new MonoMac.Foundation.NSDictionary ())); #else return new UIKitImage (UIImage.FromFile ("Images/" + filename).CGImage); #endif }
public void LoadCurrentEntry() { var nsImage = new NSImage (NSData.FromArray (comic.CurrentPage.Bytes)); var image = nsImage.AsCGImage (RectangleF.Empty, null, null); imageView.SetImageimageProperties (image, new NSDictionary ()); imageView.ZoomImageToFit (this); CalculateAndSet(); imageView.ZoomImageToFit (this); }