void LoadTextureFromPng() { using (UIImage img = UIImage.FromFile("NeHe.png")) { int width = img.CGImage.Width; int height = img.CGImage.Height; using (MonoTouch.CoreGraphics.CGColorSpace colorSpaceRef = MonoTouch.CoreGraphics.CGColorSpace.CreateDeviceRGB()) { IntPtr imageData = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(height * width * 4); try { using (MonoTouch.CoreGraphics.CGBitmapContext context = new MonoTouch.CoreGraphics.CGBitmapContext( imageData, width, height, 8, 4 * width, colorSpaceRef, MonoTouch.CoreGraphics.CGBitmapFlags.ByteOrder32Big | MonoTouch.CoreGraphics.CGBitmapFlags.PremultipliedLast)) { colorSpaceRef.Dispose(); context.ClearRect(new System.Drawing.RectangleF(0.0f, 0.0f, (float)width, (float)height)); context.TranslateCTM(0, 0); context.DrawImage(new System.Drawing.RectangleF(0.0f, 0.0f, (float)width, (float)height), img.CGImage); GL1.TexImage2D(All1.Texture2D, 0, (int)All1.Rgba, width, height, 0, All1.Rgba, All1.UnsignedByte, imageData); } } finally { System.Runtime.InteropServices.Marshal.FreeCoTaskMem(imageData); } } } }
public override void Draw(System.Drawing.RectangleF rect) { base.Draw(rect); using (MonoTouch.CoreGraphics.CGContext gfx = UIGraphics.GetCurrentContext()) { using (MonoTouch.CoreGraphics.CGColorSpace rgb = MonoTouch.CoreGraphics.CGColorSpace.CreateDeviceRGB()) { MonoTouch.CoreGraphics.CGGradient gradient = new MonoTouch.CoreGraphics.CGGradient(rgb, new MonoTouch.CoreGraphics.CGColor[] { startColor.CGColor, endColor.CGColor }); gfx.DrawLinearGradient(gradient, new System.Drawing.PointF(rect.Left, rect.Top), new System.Drawing.PointF(rect.Right, rect.Top), MonoTouch.CoreGraphics.CGGradientDrawingOptions.DrawsBeforeStartLocation); } } }