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


C# CGBitmapContext.TranslateCTM方法代码示例

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


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

示例1: 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

示例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: 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

示例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: MakeCalendarBadgeSmall

		public static UIImage MakeCalendarBadgeSmall (UIImage template, string smallText, string bigText)
		{
			int imageWidth=30, imageHeight=29;
			int smallTextY=5, bigTextY=12;
			float smallTextSize=7f, bigTextSize=16f;

			using (var cs = CGColorSpace.CreateDeviceRGB ()) {
				using (var context = new CGBitmapContext (IntPtr.Zero
								, imageWidth, imageHeight, 8, imageWidth*4, cs
								, CGImageAlphaInfo.PremultipliedLast)) {
					
					//context.ScaleCTM (0.5f, -1);
					context.TranslateCTM (0, 0);
					context.DrawImage (new RectangleF (0, 0, imageWidth, imageHeight), template.CGImage);
					context.SetFillColor (0, 0, 0, 1);
					
					// The _small_ string
					context.SelectFont ("Helvetica-Bold", smallTextSize, CGTextEncoding.MacRoman);
					
					// Pretty lame way of measuring strings, as documented:
					var start = context.TextPosition.X;					
					context.SetTextDrawingMode (CGTextDrawingMode.Invisible);
					context.ShowText (smallText);
					var width = context.TextPosition.X - start;
					
					context.SetTextDrawingMode (CGTextDrawingMode.Fill);
					context.ShowTextAtPoint ((imageWidth-width)/2, smallTextY, smallText);
					
					// The BIG string
					context.SelectFont ("Helvetica-Bold", bigTextSize, CGTextEncoding.MacRoman);					
					start = context.TextPosition.X;
					context.SetTextDrawingMode (CGTextDrawingMode.Invisible);
					context.ShowText (bigText);
					width = context.TextPosition.X - start;
					
					context.SetFillColor (0, 0, 0, 1);
					context.SetTextDrawingMode (CGTextDrawingMode.Fill);
					context.ShowTextAtPoint ((imageWidth-width)/2, bigTextY, bigText);
					
					context.StrokePath ();
				
					return UIImage.FromImage (context.ToImage ());
				}
			}
		}
开发者ID:slodge,项目名称:mobile-samples,代码行数:45,代码来源:CustomBadgeImage.cs

示例6: AdjustImage

        public static UIImage AdjustImage(CGRect rect,UIImage template, CGBlendMode mode,nfloat red,nfloat green,nfloat blue,nfloat alpha )
        {
            using (var cs = CGColorSpace.CreateDeviceRGB ()){
                using (var context = new CGBitmapContext (IntPtr.Zero, (int)rect.Width, (int)rect.Height, 8, (int)rect.Height*8, cs, CGImageAlphaInfo.PremultipliedLast)){

                    context.SetShadow(new CGSize(0.0f, 1.0f), 0.7f, UIColor.Black.CGColor);
                    context.TranslateCTM(0.0f,0f);
                    //context.ScaleCTM(1.0f,-1.0f);
                    context.DrawImage(rect,template.CGImage);
                    context.SetBlendMode(mode);
                    context.ClipToMask(rect,template.CGImage);
                    context.SetFillColor(red,green,blue,alpha);
                    context.FillRect(rect);

                    return UIImage.FromImage (context.ToImage ());
                }
            }
        }
开发者ID:Clancey,项目名称:UICalendar,代码行数:18,代码来源:Graphics.cs

示例7: MakeCalendarBadge

		public static UIImage MakeCalendarBadge (UIImage template, string smallText, string bigText)
		{
			using (var cs = CGColorSpace.CreateDeviceRGB ()){
				using (var context = new CGBitmapContext (IntPtr.Zero, 59, 58, 8, 59*4, cs, CGImageAlphaInfo.PremultipliedLast)){
					//context.ScaleCTM (0.5f, -1);
					context.TranslateCTM (0, 0);
					context.DrawImage (new RectangleF (0, 0, 59, 58), template.CGImage);
					context.SetFillColor (0, 0, 0, 1);
					
					// The _small_ string
					context.SelectFont ("Helvetica-Bold", 14f, CGTextEncoding.MacRoman);
					
					// Pretty lame way of measuring strings, as documented:
					var start = context.TextPosition.X;					
					context.SetTextDrawingMode (CGTextDrawingMode.Invisible);
					context.ShowText (smallText);
					var width = context.TextPosition.X - start;
					
					context.SetTextDrawingMode (CGTextDrawingMode.Fill);
					context.ShowTextAtPoint ((59-width)/2, 10, smallText); // was 46
					
					// The BIG string
					context.SelectFont ("Helvetica-Bold", 32, CGTextEncoding.MacRoman);					
					start = context.TextPosition.X;
					context.SetTextDrawingMode (CGTextDrawingMode.Invisible);
					context.ShowText (bigText);
					width = context.TextPosition.X - start;
					
					context.SetFillColor (0, 0, 0, 1);
					context.SetTextDrawingMode (CGTextDrawingMode.Fill);
					context.ShowTextAtPoint ((59-width)/2, 25, bigText);	// was 9
					
					context.StrokePath ();
				
					return UIImage.FromImage (context.ToImage ());
				}
			}
		}
开发者ID:slodge,项目名称:mobile-samples,代码行数:38,代码来源:CustomBadgeImage.cs

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: CreateCalendarImage

            static UIImage CreateCalendarImage(DateTime date)
            {
                string month = date.ToString ("MMMM");
                string day = date.Day.ToString ();

                using (var cs = CGColorSpace.CreateDeviceRGB ()) {
                    using (var context = new CGBitmapContext (IntPtr.Zero, 57, 57, 8, 57 * 4, cs, CGImageAlphaInfo.PremultipliedLast)) {
                        //context.ScaleCTM (0.5f, -1);
                        context.TranslateCTM (0, 0);
                        context.DrawImage (new RectangleF (0, 0, 57, 57), Calendar.CGImage);
                        context.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f);

                        context.SelectFont ("Helvetica", 10f, CGTextEncoding.MacRoman);

                        // Pretty lame way of measuring strings, as documented:
                        var start = context.TextPosition.X;
                        context.SetTextDrawingMode (CGTextDrawingMode.Invisible);
                        context.ShowText (month);
                        var width = context.TextPosition.X - start;

                        context.SetTextDrawingMode (CGTextDrawingMode.Fill);
                        context.ShowTextAtPoint ((57 - width) / 2, 46, month);

                        // The big string
                        context.SelectFont ("Helvetica-Bold", 32, CGTextEncoding.MacRoman);
                        start = context.TextPosition.X;
                        context.SetTextDrawingMode (CGTextDrawingMode.Invisible);
                        context.ShowText (day);
                        width = context.TextPosition.X - start;

                        context.SetFillColor (0.0f, 0.0f, 0.0f, 1.0f);
                        context.SetTextDrawingMode (CGTextDrawingMode.Fill);
                        context.ShowTextAtPoint ((57 - width) / 2, 9, day);

                        context.StrokePath ();

                        return UIImage.FromImage (context.ToImage ());
                    }
                }
            }
开发者ID:Clancey,项目名称:FlightLog,代码行数:40,代码来源:FlightElement.cs

示例14: SetOriginalImage

        public void SetOriginalImage(UIImage originalImage, CGRect cropFrame)
        {
            LoadIndicator.StartAnimating();
            InvokeOnMainThread(() =>
                {
                    CGImage imageRef = originalImage.CGImage;
                    UIImageOrientation imageOrientation = originalImage.Orientation;

                    if (imageRef == null)
                        return;

                    var bytesPerRow = 0;
                    var width = imageRef.Width;
                    var height = imageRef.Height;
                    var bitsPerComponent = imageRef.BitsPerComponent;
                    CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
                    CGBitmapFlags bitmapInfo = imageRef.BitmapInfo;

                    switch (imageOrientation)
                    {
                        case UIImageOrientation.RightMirrored:
                        case UIImageOrientation.LeftMirrored:
                        case UIImageOrientation.Right:
                        case UIImageOrientation.Left:
                            width = imageRef.Height;
                            height = imageRef.Width;
                            break;
                        default:
                            break;
                    }

                    CGSize imageSize = new CGSize(width, height);
                    CGBitmapContext context = new CGBitmapContext(null,
                                                  width,
                                                  height,
                                                  bitsPerComponent,
                                                  bytesPerRow,
                                                  colorSpace,
                                                  bitmapInfo);

                    colorSpace.Dispose();

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

                    switch (imageOrientation)
                    {
                        case UIImageOrientation.RightMirrored:
                        case UIImageOrientation.Right:
                            context.TranslateCTM(imageSize.Width / 2, imageSize.Height / 2);
                            context.RotateCTM(-((nfloat)Math.PI / 2));
                            context.TranslateCTM(-imageSize.Height / 2, -imageSize.Width / 2);
                            break;
                        case UIImageOrientation.LeftMirrored:
                        case UIImageOrientation.Left:
                            context.TranslateCTM(imageSize.Width / 2, imageSize.Height / 2);
                            context.RotateCTM((nfloat)(Math.PI / 2));
                            context.TranslateCTM(-imageSize.Height / 2, -imageSize.Width / 2);
                            break;
                        case UIImageOrientation.Down:
                        case UIImageOrientation.DownMirrored:
                            context.TranslateCTM(imageSize.Width / 2, imageSize.Height / 2);
                            context.RotateCTM((nfloat)Math.PI);
                            context.TranslateCTM(-imageSize.Width / 2, -imageSize.Height / 2);
                            break;
                        default:
                            break;
                    }

                    context.InterpolationQuality = CGInterpolationQuality.High;
                    context.SetBlendMode(CGBlendMode.Copy);
                    context.DrawImage(new CGRect(0, 0, imageRef.Width, imageRef.Height), imageRef);

                    CGImage contextImage = context.ToImage();

                    context.Dispose();

                    if (contextImage != null)
                    {
                        _originalImage = UIImage.FromImage(contextImage, originalImage.CurrentScale, UIImageOrientation.Up);

                        contextImage.Dispose();
                    }

                    imageRef.Dispose();

                    BeginInvokeOnMainThread(() =>
                        {
                            CGSize convertedImageSize = new CGSize(_originalImage.Size.Width / _cropSizeRatio,
                                                            _originalImage.Size.Height / _cropSizeRatio);

                            ImageView.Alpha = 0;
                            ImageView.Image = _originalImage;

                            CGSize sampleImageSize = new CGSize(Math.Max(convertedImageSize.Width, ScrollView.Frame.Size.Width),
                                                         Math.Max(convertedImageSize.Height, ScrollView.Frame.Size.Height));

//.........这里部分代码省略.........
开发者ID:ProstoKorol,项目名称:HIPImageCropperXamarin,代码行数:101,代码来源:HIPImageCropperView.cs

示例15: FromUIImage

        static Texture2D FromUIImage(UIImage uiImage, string name)
        {
            All filter = All.Linear;

            CGImage image = uiImage.CGImage;
            if(uiImage == null)
                throw new ArgumentNullException("uiImage");

            // TODO: could use this to implement lower-bandwidth textures
            //bool hasAlpha = (image.AlphaInfo == CGImageAlphaInfo.First || image.AlphaInfo == CGImageAlphaInfo.Last
            //		|| image.AlphaInfo == CGImageAlphaInfo.PremultipliedFirst || image.AlphaInfo == CGImageAlphaInfo.PremultipliedLast);

            // Image dimentions:
            Point logicalSize = new Point((int)uiImage.Size.Width, (int)uiImage.Size.Height);

            int pixelWidth = uiImage.CGImage.Width;
            int pixelHeight = uiImage.CGImage.Height;

            // Round up the target texture width and height to powers of two:
            int potWidth = pixelWidth;
            int potHeight = pixelHeight;
            if(( potWidth & ( potWidth-1)) != 0) { int w = 1; while(w <  potWidth) { w *= 2; }  potWidth = w; }
            if((potHeight & (potHeight-1)) != 0) { int h = 1; while(h < potHeight) { h *= 2; } potHeight = h; }

            // Scale down textures that are too large...
            CGAffineTransform transform = CGAffineTransform.MakeIdentity();
            while((potWidth > 1024) || (potHeight > 1024))
            {
                potWidth /= 2;    // Note: no precision loss - it's a power of two
                potHeight /= 2;
                pixelWidth /= 2;  // Note: precision loss - assume possibility of dropping a pixel at each step is ok
                pixelHeight /= 2;
                transform.Multiply(CGAffineTransform.MakeScale(0.5f, 0.5f));
            }

            lock(textureLoadBufferLockObject)
            {
                CreateTextureLoadBuffer();

                unsafe
                {
                    fixed(byte* data = textureLoadBuffer)
                    {
                        using(var colorSpace = CGColorSpace.CreateDeviceRGB())
                        using(var context = new CGBitmapContext(new IntPtr(data), potWidth, potHeight,
                                8, 4 * potWidth, colorSpace, CGImageAlphaInfo.PremultipliedLast))
                        {
                            context.ClearRect(new RectangleF(0, 0, potWidth, potHeight));
                            context.TranslateCTM(0, potHeight - pixelHeight); // TODO: this does not play nice with the precision-loss above (keeping half-pixel to the edge)

                            if(!transform.IsIdentity)
                                context.ConcatCTM(transform);

                            context.DrawImage(new RectangleF(0, 0, image.Width, image.Height), image);

                            uint textureId = 0;
                            /*textureId = new uint[1];
                            textureId[0]= 0;
                            GL.GenTextures(1,textureId);*/
                            GL.GenTextures(1, ref textureId);
                            GL.BindTexture(All.Texture2D, textureId);
                            GL.TexParameter(All.Texture2D, All.TextureMinFilter, (int)filter);
                            GL.TexParameter(All.Texture2D, All.TextureMagFilter, (int)filter);
                            GL.TexImage2D(All.Texture2D, 0, (int)All.Rgba, (int)potWidth, (int)potHeight, 0, All.Rgba, All.UnsignedByte, new IntPtr(data));

                            return new Texture2D(logicalSize.X, logicalSize.Y,
                                    pixelWidth, pixelHeight, potWidth, potHeight,
                                    textureId, name);
                        }
                    }
                }
            }
        }
开发者ID:eickegao,项目名称:tiny2d,代码行数:73,代码来源:Texture2D.cs


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