当前位置: 首页>>代码示例>>C#>>正文


C# CGBitmapContext.ScaleCTM方法代码示例

本文整理汇总了C#中CGBitmapContext.ScaleCTM方法的典型用法代码示例。如果您正苦于以下问题:C# CGBitmapContext.ScaleCTM方法的具体用法?C# CGBitmapContext.ScaleCTM怎么用?C# CGBitmapContext.ScaleCTM使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CGBitmapContext的用法示例。


在下文中一共展示了CGBitmapContext.ScaleCTM方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadBitmapData

		void LoadBitmapData (int texId)
		{
			NSData texData = NSData.FromFile (NSBundle.MainBundle.PathForResource ("texture1", "png"));

			UIImage image = UIImage.LoadFromData (texData);
			if (image == null)
				return;

			int width = image.CGImage.Width;
			int height = image.CGImage.Height;

			CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB ();
			byte[] imageData = new byte[height * width * 4];
			CGContext context = new CGBitmapContext (imageData, width, height, 8, 4 * width, colorSpace,
				                    CGBitmapFlags.PremultipliedLast | CGBitmapFlags.ByteOrder32Big);

			context.TranslateCTM (0, height);
			context.ScaleCTM (1, -1);
			colorSpace.Dispose ();
			context.ClearRect (new RectangleF (0, 0, width, height));
			context.DrawImage (new RectangleF (0, 0, width, height), image.CGImage);

			GL.TexImage2D (TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, imageData);
			context.Dispose ();
		}
开发者ID:Juliansanu,项目名称:mobile-samples,代码行数:25,代码来源:EAGLView.cs

示例2: DrawScreen

		protected void DrawScreen ()
		{

			// create our offscreen bitmap context
			// size
			CGSize bitmapSize = new CGSize (imageView.Frame.Size);
			using (CGBitmapContext context = new CGBitmapContext (IntPtr.Zero, (int)bitmapSize.Width, (int)bitmapSize.Height, 8, (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB (), CGImageAlphaInfo.PremultipliedFirst)) {

				// save the state of the context while we change the CTM
				context.SaveState ();

				// draw our circle
				context.SetFillColor (1, 0, 0, 1);
				context.TranslateCTM (currentLocation.X, currentLocation.Y);
				context.RotateCTM (currentRotation);
				context.ScaleCTM (currentScale, currentScale);
				context.FillRect (new CGRect (-10, -10, 20, 20));

				// restore our transformations
				context.RestoreState ();

				// draw our coordinates for reference
				DrawCoordinateSpace (context);

				// output the drawing to the view
				imageView.Image = UIImage.FromImage (context.ToImage ());
			}
		}
开发者ID:Rajneesh360Logica,项目名称:monotouch-samples,代码行数:28,代码来源:Controller.cs

示例3: GetImagaDataFromPath

		void GetImagaDataFromPath (string path)
		{
			NSImage src;
			CGImage image;
			CGContext context = null;

			src = new NSImage (path);

			var rect = CGRect.Empty;
			image = src.AsCGImage (ref rect, null, null);
			width =(int)image.Width;
			height = (int) 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 CGRect (0, 0, width, height), image);
		}
开发者ID:RangoLee,项目名称:mac-samples,代码行数:31,代码来源:Texture.cs

示例4: GLTexture

		public GLTexture (string inFilename)
		{
			GL.Enable (EnableCap.Texture2D);
			GL.Enable (EnableCap.Blend);

			filename = inFilename;

			GL.Hint (HintTarget.GenerateMipmapHint, HintMode.Nicest);
			GL.GenTextures (1, out texture);
			GL.BindTexture (TextureTarget.Texture2D, texture);
			GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int) All.Repeat);
			GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int) All.Repeat);
			GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) All.Linear);
			GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) All.Linear);
			GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) All.Nearest);
			GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) All.Nearest);

			//TODO Remove the Substring method if you don't support iOS versions prior to iOS 6.
			string extension = Path.GetExtension (filename).Substring(1);
			string baseFilename = Path.GetFileNameWithoutExtension (filename);

			string path = NSBundle.MainBundle.PathForResource (baseFilename, extension);
			NSData texData = NSData.FromFile (path);

			UIImage image = UIImage.LoadFromData (texData);
			if (image == null)
				return;

			nint width = image.CGImage.Width;
			nint height = image.CGImage.Height;

			CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB ();
			byte [] imageData = new byte[height * width * 4];
			CGContext context = new CGBitmapContext  (imageData, width, height, 8, 4 * width, colorSpace,
			                                          CGBitmapFlags.PremultipliedLast | CGBitmapFlags.ByteOrder32Big);

			context.TranslateCTM (0, height);
			context.ScaleCTM (1, -1);
			colorSpace.Dispose ();
			context.ClearRect (new CGRect (0, 0, width, height));
			context.DrawImage (new CGRect (0, 0, width, height), image.CGImage);

			GL.TexImage2D (TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)width, (int)height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, imageData);
			context.Dispose ();
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:45,代码来源:GLTexture.cs

示例5: LoadImage

        public static void LoadImage(string filePathName, bool flipVertical)
        {
            var imageClass = UIImage.FromFile(filePathName);

            var cgImage = imageClass.CGImage;

            var Width = cgImage.Width;
            var Height = cgImage.Height;
            var RowByteSize = Width * 4;
            var Data =  new byte[cgImage.Height * cgImage.Width];
            var Format = PixelInternalFormat.Rgba;
            var Type = PixelType.UnsignedByte;

            IntPtr dataPtr = Marshal.AllocHGlobal (cgImage.Height * cgImage.Width);

            using(var context = new CGBitmapContext(dataPtr, Width, Height, 8, RowByteSize, cgImage.ColorSpace, CGImageAlphaInfo.NoneSkipLast))
            {
                context.SetBlendMode(CGBlendMode.Copy);

                if(flipVertical)
                {
                    context.TranslateCTM(0.0f, (float)Height);
                    context.ScaleCTM(1.0f, -1.0f);
                }

                context.DrawImage(new RectangleF(0f, 0f, Width, Height), cgImage);
            }

            if(dataPtr == IntPtr.Zero)
            {
                return;
            }
            else
            {
                Marshal.PtrToStructure(dataPtr, Data);
            }
        }
开发者ID:ebeisecker,项目名称:Playpen,代码行数:37,代码来源:AppDelegate.cs

示例6: GetViewContext

		public CGBitmapContext GetViewContext ()
		{
			// our network takes in only grayscale images as input
			var colorSpace = CGColorSpace.CreateDeviceGray ();
			// we have 3 channels no alpha value put in the network
			var bitmapInfo = CGImageAlphaInfo.None;

			// this is where our view pixel data will go in once we make the render call
			var context = new CGBitmapContext (null, 28, 28, 8, 28, colorSpace, bitmapInfo);

			// scale and translate so we have the full digit and in MNIST standard size 28x28
			context.TranslateCTM (0, 28);
			context.ScaleCTM (28 / Frame.Size.Width, -28 / Frame.Size.Height);

			// put view pixel data in context
			Layer.RenderInContext (context);

			return context;
		}
开发者ID:xamarin,项目名称:monotouch-samples,代码行数:19,代码来源:DrawView.cs

示例7: LoadImage

        public static unsafe DemoImage LoadImage(string filePathName, bool flipVertical)
        {
            var imageClass = UIImage.FromFile(filePathName);

            var cgImage = imageClass.CGImage;

            if(cgImage == null)
            {
                return null;
            }

            var image = new DemoImage();
            image.Width = cgImage.Width;
            image.Height = cgImage.Height;
            image.RowByteSize = image.Width * 4;
            image.Data =  new byte[cgImage.Height * image.RowByteSize];
            image.Format = PixelInternalFormat.Rgba;
            image.Type = PixelType.UnsignedByte;

            fixed (byte *ptr = &image.Data [0]){
                using(var context = new CGBitmapContext((IntPtr) ptr, image.Width, image.Height, 8, image.RowByteSize, cgImage.ColorSpace, CGImageAlphaInfo.NoneSkipLast))
                {
                    context.SetBlendMode(CGBlendMode.Copy);

                    if(flipVertical)
                    {
                        context.TranslateCTM(0.0f, (float)image.Height);
                        context.ScaleCTM(1.0f, -1.0f);
                    }

                    context.DrawImage(new RectangleF(0f, 0f, image.Width, image.Height), cgImage);
                }
            }
            return image;
        }
开发者ID:ebeisecker,项目名称:Playpen,代码行数:35,代码来源:DemoImage.cs

示例8: CreateMaskForImage

 private CGImage CreateMaskForImage(UIImage image)
 {
     int pixelsWide = (int)(image.Size.Width * image.CurrentScale);
     int pixelsHigh = (int)(image.Size.Height * image.CurrentScale);
     int bitmapBytesPerRow = (pixelsWide * 1);
     CGBitmapContext context = new CGBitmapContext(null,pixelsWide,pixelsHigh,image.CGImage.BitsPerComponent,bitmapBytesPerRow,null,CGImageAlphaInfo.Only);
     context.TranslateCTM(0.0f, pixelsHigh);
     context.ScaleCTM(1.0f, -1.0f);
     context.DrawImage(new CGRect(0, 0, pixelsWide, pixelsHigh),image.CGImage);
     CGImage maskImage = context.ToImage ();
     //CGImage maskImage = CGBitmapContextCreateImage(context);
     //CGContextRelease(context);
     return maskImage;
 }
开发者ID:skela,项目名称:SMPageControl,代码行数:14,代码来源:SMPageControl.cs

示例9: Texture2D

        public Texture2D(string text, SizeF dim, UITextAlignment alignment, string fontName, float fontSize)
        {
            UIFont font = UIFont.FromName(fontName, fontSize);

            int width = (int)dim.Width;
            if (width != 1 && (width & (width - 1)) != 0) {
                int i = 1;
                while (i < width) {
                    i *= 2;
                }

                width = i;
            }

            int height = (int)dim.Height;
            if (height != 1 && (height & (height - 1)) != 0) {
                int i = 1;
                while (i < height) {
                    i *= 2;
                }
                height = i;
            }

            CGColorSpace colorSpace = CGColorSpace.CreateDeviceGray();

            byte[] data = new byte[width * height];

            unsafe {
                fixed (byte* dataPb = data) {
                    using (CGContext context = new CGBitmapContext((IntPtr)dataPb, width, height, 8, width, colorSpace, CGImageAlphaInfo.None)) {
                        context.SetFillColor(1f, 1f);
                        context.TranslateCTM(0f, height);
                        context.ScaleCTM(1f, -1f);
                        UIGraphics.PushContext(context);
                        text.DrawInRect(new RectangleF(0, 0, dim.Width, dim.Height), font, UILineBreakMode.WordWrap, alignment);
                        UIGraphics.PopContext();
                    }
                }
            }
            colorSpace.Dispose();

            InitWithData(data, Texture2DPixelFormat.A8, width, height, dim);
        }
开发者ID:ishinao,项目名称:CocosNet,代码行数:43,代码来源:Texture2D.cs

示例10: CreateTexture

        private uint CreateTexture(string imageName)
        {
            string imagePath = NSBundle.PathForResourceAbsolute(imageName, ".png", "Content");
            CGImage image = UIImage.FromFile(imagePath).CGImage;

            if (image == null)
                throw new InvalidOperationException("Failed to load image");

            int width = image.Width;
            int height = image.Height;
            byte[] data = new byte[width * height * 4];

            // See http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx for an explanation of pre-multiplied alpha

            using (CGBitmapContext context = new CGBitmapContext(data, width, height, 8, width * 4, image.ColorSpace, CGImageAlphaInfo.PremultipliedLast))
            {
                // CoreGraphics flipped the image when it loaded it, so set up a transform to flip it back
                context.ScaleCTM(1f, -1f);
                context.TranslateCTM(0f, -height);
                context.DrawImage(new RectangleF(0, 0, (float)width, (float)height), image);
            }

            uint texture = 0;

            GL.GenTextures(1, ref texture);
            GL.BindTexture(All.Texture2D, texture);

            GL.TexParameter(All.Texture2D, All.TextureMinFilter, (int)All.Nearest);
            GL.TexImage2D(All.Texture2D, 0, (int)All.Rgba, width, height, 0, All.Rgba, All.UnsignedByte, data);

            return texture;
        }
开发者ID:jlyonsmith,项目名称:GLES2Tutorial,代码行数:32,代码来源:OpenGLView.cs

示例11: Finalize

		public bool Finalize (IMTLDevice device)
		{
			if (MetalTexture != null)
				return true;

			UIImage image = UIImage.FromFile (path);

			if (image == null)
				return false;

			using (CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB ()) {

				if (colorSpace == null)
					return false;

				Width = image.CGImage.Width;
				Height = image.CGImage.Height;

				nuint width = (nuint)Width;
				nuint height = (nuint)Height;
				nuint rowBytes = width * 4;

				var context = new CGBitmapContext (IntPtr.Zero,
					              (int)width,
					              (int)height,
					              8,
					              (int)rowBytes,
					              colorSpace,
					              CGImageAlphaInfo.PremultipliedLast);

				if (context == null)
					return false;

				var bounds = new CGRect (0f, 0f, width, height);
				context.ClearRect (bounds);

				// Vertical Reflect
				if (flip) {
					context.TranslateCTM (width, height);
					context.ScaleCTM (-1f, -1f);
				}

				context.DrawImage (bounds, image.CGImage);
				MTLTextureDescriptor texDesc = MTLTextureDescriptor.CreateTexture2DDescriptor (MTLPixelFormat.RGBA8Unorm, width, height, false);

				if (texDesc == null)
					return false;

				MetalTexture = device.CreateTexture (texDesc);

				if (MetalTexture == null) {
					context.Dispose ();
					return false;
				}

				IntPtr pixels = context.Data;

				if (pixels != IntPtr.Zero) {
					var region = new MTLRegion ();
					region.Origin.X = 0;
					region.Origin.Y = 0;
					region.Size.Width = (nint)width;
					region.Size.Height = (nint)height;

					MetalTexture.ReplaceRegion (region, 0, pixels, rowBytes);
				}

				context.Dispose ();
			}

			return true;
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:72,代码来源:Texture.cs


注:本文中的CGBitmapContext.ScaleCTM方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。