Exemple #1
0
        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);
                    }
                }
            }
        }
Exemple #2
0
        public BitmapSource RenderImageSource(ILUT lut)
        {
            var img = new MonoTouch.CoreGraphics.CGBitmapContext(IntPtr.Zero, OriginalWidth, OriginalHeight, 8, 4 * OriginalWidth,
                                                                 MonoTouch.CoreGraphics.CGColorSpace.CreateDeviceRGB(),
                                                                 MonoTouch.CoreGraphics.CGImageAlphaInfo.PremultipliedFirst);

            for (var i = 0; i < _layers.Count; ++i)
            {
                var g     = _layers[i];
                var layer = _layers[i].RenderImageSource(i == 0 ? lut : null);

                if (layer != null)
                {
                    var rect = new System.Drawing.RectangleF(g.ScaledOffsetX, g.ScaledOffsetY, g.ScaledWidth, g.ScaledHeight);
                    img.DrawImage(rect, layer);
                }
            }
            return(img.ToImage());
        }
Exemple #3
0
        void LoadTextureFromPng()
        {
            using (UIImage img = UIImage.FromFile ("Crate.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);

                            GL.BindTexture (All.Texture2D, texture[0]);
                            GL.TexParameter (All.Texture2D, All.TextureMagFilter, (int)All.Nearest);
                            GL.TexParameter (All.Texture2D, All.TextureMinFilter, (int)All.Nearest);

                            GL1.TexImage2D (All1.Texture2D, 0, (int)All1.Rgba, width, height, 0, All1.Rgba, All1.UnsignedByte, imageData);

                            GL.BindTexture (All.Texture2D, texture[1]);
                            GL.TexParameter (All.Texture2D, All.TextureMagFilter, (int)All.Linear);
                            GL.TexParameter (All.Texture2D, All.TextureMinFilter, (int)All.Linear);

                            GL1.TexImage2D (All1.Texture2D, 0, (int)All1.Rgba, width, height, 0, All1.Rgba, All1.UnsignedByte, imageData);

                            GL.BindTexture (All.Texture2D, texture[2]);
                            GL1.TexParameter (All1.Texture2D, All1.GenerateMipmap, 1);
                            GL.TexParameter (All.Texture2D, All.TextureMagFilter, (int)All.Linear);
                            GL.TexParameter (All.Texture2D, All.TextureMinFilter, (int)All.LinearMipmapNearest);

                            GL1.TexImage2D (All1.Texture2D, 0, (int)All1.Rgba, width, height, 0, All1.Rgba, All1.UnsignedByte, imageData);
                        }
                    }
                    finally
                    {
                        System.Runtime.InteropServices.Marshal.FreeCoTaskMem (imageData);
                    }
                }
            }
        }
		public BitmapSource RenderImageSource(ILUT lut)
		{
			var img = new MonoTouch.CoreGraphics.CGBitmapContext(IntPtr.Zero, OriginalWidth, OriginalHeight, 8, 4 * OriginalWidth,
			                                                     MonoTouch.CoreGraphics.CGColorSpace.CreateDeviceRGB(),
			                                                     MonoTouch.CoreGraphics.CGImageAlphaInfo.PremultipliedFirst);
			for (var i = 0; i < _layers.Count; ++i)
			{
				var g = _layers[i];
				var layer = _layers[i].RenderImageSource(i == 0 ? lut : null);

				if (layer != null)
				{
					var rect = new System.Drawing.RectangleF(g.ScaledOffsetX, g.ScaledOffsetY, g.ScaledWidth, g.ScaledHeight);
					img.DrawImage(rect, layer);
				}
			}
			return img.ToImage();
		}