コード例 #1
0
ファイル: Texture.cs プロジェクト: Anomalous-Software/monomac
 void GetImagaDataFromPath (string path)
 {
         int width, height;
         NSImage src;
         CGImage image;
         CGContext context = null;
         RectangleF rect = RectangleF.Empty;
         
         data = new byte[TEXTURE_WIDTH * TEXTURE_HEIGHT * 4];
         
         src = new NSImage (path);
         
         image = src.AsCGImage (ref rect, null, null);
         width = image.Width;
         height = image.Height;
         
         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);
 }
コード例 #2
0
		void GetImagaDataFromPath (string path)
		{
			NSImage src;
			CGImage image;
			CGContext context = null;

			src = new NSImage (path);

			image = src.AsCGImage (RectangleF.Empty, null, null);
			width = image.Width;
			height = image.Height;

			int bytesPerRow = image.BytesPerRow;
			int bitsPerPixel = image.BitsPerPixel;
			int bitsPerComponent = image.BitsPerComponent;

			data = new byte[bytesPerRow * height * 4];
			
			CGImageAlphaInfo ai = CGImageAlphaInfo.PremultipliedLast;
			CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
			
			context = new CGBitmapContext (data, width, height, 8, 4 * width, 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);
		}