• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CGBitmapContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: ResizeImageIOS

		public byte[] ResizeImageIOS(byte[] imageData, float size)
		{
			UIImage originalImage = ImageFromByteArray(imageData);
			System.Diagnostics.Debug.Write("originalImage.Size.Height"+ originalImage.Size.Height + ", " + originalImage.Size.Width);
			UIImageOrientation orientation = originalImage.Orientation;

			float width = size;
			float height = ((float)originalImage.Size.Height / (float)originalImage.Size.Width) * size;
			System.Diagnostics.Debug.Write("new size" + width + ", " + height);
			//create a 24bit RGB image
			using (CGBitmapContext context = new CGBitmapContext(IntPtr.Zero,
												 (int)width, (int)height, 8,
												 (int)(4 * width), CGColorSpace.CreateDeviceRGB(),
												 CGImageAlphaInfo.PremultipliedFirst))
			{

				RectangleF imageRect = new RectangleF(0, 0, width, height);

				// draw the image
				context.DrawImage(imageRect, originalImage.CGImage);

				UIKit.UIImage resizedImage = UIKit.UIImage.FromImage(context.ToImage(), 0, orientation);

				// save the image as a jpeg
				return resizedImage.AsJPEG().ToArray();
			}
		}
开发者ID:todibbang,项目名称:HowlOutApp,代码行数:27,代码来源:ImageResizeRenderer.cs


示例2: Bitmap

        public Bitmap(NSImage sourceImage)
        {
            Width = (int)sourceImage.CGImage.Width;
            Height = (int)sourceImage.CGImage.Height;
            _colors = new Color[Width * Height];

            var rawData = new byte[Width * Height * 4];
            var bytesPerPixel = 4;
            var bytesPerRow = bytesPerPixel * Width;
            var bitsPerComponent = 8;

            using (var colorSpace = CGColorSpace.CreateDeviceRGB())
            {
                using (var context = new CGBitmapContext(rawData, Width, Height, bitsPerComponent, bytesPerRow, colorSpace, CGBitmapFlags.ByteOrder32Big | CGBitmapFlags.PremultipliedLast))
                {
                    context.DrawImage(new CGRect(0, 0, Width, Height), sourceImage.CGImage);

                    for (int y = 0; y < Height; y++)
                    {
                        for (int x = 0; x < Width; x++)
                        {
                            var i = bytesPerRow * y + bytesPerPixel * x;   
                            byte red = rawData[i + 0];
                            byte green = rawData[i + 1];
                            byte blue = rawData[i + 2];
                            byte alpha = rawData[i + 3];
                            SetPixel(x, y, Color.FromArgb(alpha, red, green, blue));
                        }
                    }
                }
            }
        }
开发者ID:SubtitleEdit,项目名称:subtitleedit-mac,代码行数:32,代码来源:Bitmap.cs


示例3: init

        protected override void init(Stream stream, bool flip, Loader.LoadedCallbackMethod loadedCallback)
        {
            try
            {
                using (var imageData = NSData.FromStream(stream))
                using (var image = UIImage.LoadFromData(imageData))
                {
                    int width = (int)image.Size.Width;
                    int height = (int)image.Size.Height;
                    Mipmaps = new Mipmap[1];
                    Size = new Size2(width, height);

                    var data = new byte[width * height * 4];
                    using (CGContext imageContext = new CGBitmapContext(data, width, height, 8, width*4, CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedLast))
                    {
                        imageContext.DrawImage(new RectangleF(0, 0, width, height), image.CGImage);

                        Mipmaps[0] = new Mipmap(data, width, height, 1, 4);
                        if (flip) Mipmaps[0].FlipVertical();
                    }
                }
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                if (loadedCallback != null) loadedCallback(this, false);
                return;
            }

            Loaded = true;
            if (loadedCallback != null) loadedCallback(this, true);
        }
开发者ID:reignstudios,项目名称:ReignSDK,代码行数:33,代码来源:ImageIOS.cs


示例4: iOSSurfaceSource

        /// <summary>
        /// Initializes a new instance of the <see cref="iOSSurfaceSource"/> class.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> that contains the surface data.</param>
        public iOSSurfaceSource(Stream stream)
        {
            Contract.Require(stream, nameof(stream));

            using (var data = NSData.FromStream(stream))
            {
                using (var img = UIImage.LoadFromData(data))
                {
                    this.width = (Int32)img.Size.Width;
                    this.height = (Int32)img.Size.Height;
                    this.stride = (Int32)img.CGImage.BytesPerRow;

                    this.bmpData = Marshal.AllocHGlobal(stride * height);

                    using (var colorSpace = CGColorSpace.CreateDeviceRGB())
                    {
                        using (var bmp = new CGBitmapContext(bmpData, width, height, 8, stride, colorSpace, CGImageAlphaInfo.PremultipliedLast))
                        {
                            bmp.ClearRect(new CGRect(0, 0, width, height));
                            bmp.DrawImage(new CGRect(0, 0, width, height), img.CGImage);
                        }
                    }
                }
            }

            ReversePremultiplication();
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:31,代码来源:iOSSurfaceSource.cs


示例5: ViewDidLoad

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			// set the background color of the view to white
			View.BackgroundColor = UIColor.White;
			
			// instantiate a new image view that takes up the whole screen and add it to 
			// the view hierarchy
			RectangleF imageViewFrame = new RectangleF (0, -NavigationController.NavigationBar.Frame.Height, View.Frame.Width, View.Frame.Height);
			imageView = new UIImageView (imageViewFrame);
			View.AddSubview (imageView);
			
			// create our offscreen bitmap context
			// size
			SizeF bitmapSize = new SizeF (View.Frame.Size);
			using (CGBitmapContext context = new CGBitmapContext (IntPtr.Zero
					, (int)bitmapSize.Width, (int)bitmapSize.Height, 8
					, (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB ()
					, CGImageAlphaInfo.PremultipliedFirst)) {
				
				// declare vars
				UIImage apressImage = UIImage.FromFile ("Images/Icons/512_icon.png");
				PointF imageOrigin = new PointF ((imageView.Frame.Width / 2) - (apressImage.CGImage.Width / 2), (imageView.Frame.Height / 2) - (apressImage.CGImage.Height / 2)); 
				RectangleF imageRect = new RectangleF (imageOrigin.X, imageOrigin.Y, apressImage.CGImage.Width, apressImage.CGImage.Height);
				
				// draw the image
				context.DrawImage (imageRect, apressImage.CGImage);
				
				
				// output the drawing to the view
				imageView.Image = UIImage.FromImage (context.ToImage ());
			}
		}
开发者ID:rojepp,项目名称:monotouch-samples,代码行数:34,代码来源:Controller.cs


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


示例7: ResizeImage

        public byte[] ResizeImage(byte[] imageData, float width, float height)
        {
            UIImage originalImage = ImageFromByteArray (imageData);
            float oldWidth = (float)originalImage.Size.Width;
            float oldHeight = (float)originalImage.Size.Height;
            float scaleFactor = 0f;

            if (oldWidth > oldHeight) {
                scaleFactor = width / oldWidth;
            } else {
                scaleFactor = height / oldHeight;
            }
            float newHeight = oldHeight * scaleFactor;
            float newWidth = oldWidth * scaleFactor;

            //create a 24bit RGB image
            using (CGBitmapContext context = new CGBitmapContext (null,
                                                 (int)newWidth, (int)newHeight, 8,
                                                 0, CGColorSpace.CreateDeviceRGB (), CGImageAlphaInfo.PremultipliedFirst)) {

                RectangleF imageRect = new RectangleF (0, 0, newWidth, newHeight);

                // draw the image
                context.DrawImage (imageRect, originalImage.CGImage);

                UIKit.UIImage resizedImage = UIKit.UIImage.FromImage (context.ToImage ());

                // save the image as a jpeg
                return resizedImage.AsJPEG ().ToArray ();
            }
        }
开发者ID:BorisFR,项目名称:astromech,代码行数:31,代码来源:ImageResizer.cs


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


示例9: CreateImage

 public IImage CreateImage(Color[] colors, int width, double scale = 1.0)
 {
     var pixelWidth = width;
     var pixelHeight = colors.Length / width;
     var bitmapInfo = CGImageAlphaInfo.PremultipliedFirst;
     var bitsPerComp = 8;
     var bytesPerRow = width * 4;// ((4 * pixelWidth + 3)/4) * 4;
     var colorSpace = CGColorSpace.CreateDeviceRGB ();
     var bitmap = new CGBitmapContext (IntPtr.Zero, pixelWidth, pixelHeight, bitsPerComp, bytesPerRow, colorSpace, bitmapInfo);
     var data = bitmap.Data;
     unsafe {
         fixed (Color *c = colors) {
             for (var y = 0; y < pixelHeight; y++) {
                 var s = (byte*)c + 4*pixelWidth*y;
                 var d = (byte*)data + bytesPerRow*y;
                 for (var x = 0; x < pixelWidth; x++) {
                     var b = *s++;
                     var g = *s++;
                     var r = *s++;
                     var a = *s++;
                     *d++ = a;
                     *d++ = (byte)((r * a) >> 8);
                     *d++ = (byte)((g * a) >> 8);
                     *d++ = (byte)((b * a) >> 8);
                 }
             }
         }
     }
     var image = bitmap.ToImage ();
     return new CGImageImage (image, scale);
 }
开发者ID:nakijun,项目名称:NGraphics,代码行数:31,代码来源:ApplePlatform.cs


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


示例11: GrayscaleImage

        /// <summary>
        ///    Creates grayscaled image from existing image.
        /// </summary>
        /// <param name="oldImage">Image to convert.</param>
        /// <returns>Returns grayscaled image.</returns>
        public static UIImage GrayscaleImage( UIImage oldImage )
        {
            var imageRect = new RectangleF(PointF.Empty, (SizeF) oldImage.Size);

            CGImage grayImage;

            // Create gray image.
            using (CGColorSpace colorSpace = CGColorSpace.CreateDeviceGray()) {
                using (var context = new CGBitmapContext(IntPtr.Zero, (int) imageRect.Width, (int) imageRect.Height, 8, 0, colorSpace, CGImageAlphaInfo.None)) {
                    context.DrawImage(imageRect, oldImage.CGImage);
                    grayImage = context.ToImage();
                }
            }

            // Create mask for transparent areas.
            using (var context = new CGBitmapContext(IntPtr.Zero, (int) imageRect.Width, (int) imageRect.Height, 8, 0, CGColorSpace.Null, CGBitmapFlags.Only)) {
                context.DrawImage(imageRect, oldImage.CGImage);
                CGImage alphaMask = context.ToImage();
                var newImage = new UIImage(grayImage.WithMask(alphaMask));

                grayImage.Dispose();
                alphaMask.Dispose();

                return newImage;
            }
        }
开发者ID:strongloop,项目名称:loopback-example-xamarin,代码行数:31,代码来源:ImageHelper.cs


示例12: GetImageFromSampleBuffer

		/// <summary>
		/// Gets a single image frame from sample buffer.
		/// </summary>
		/// <returns>The image from sample buffer.</returns>
		/// <param name="sampleBuffer">Sample buffer.</param>
		private UIImage GetImageFromSampleBuffer(CMSampleBuffer sampleBuffer) {

			// Get a pixel buffer from the sample buffer
			using (var pixelBuffer = sampleBuffer.GetImageBuffer () as CVPixelBuffer) {
				// Lock the base address
				pixelBuffer.Lock ((CVPixelBufferLock)0);

				// Prepare to decode buffer
				var flags = CGBitmapFlags.PremultipliedFirst | CGBitmapFlags.ByteOrder32Little;

				// Decode buffer - Create a new colorspace
				using (var cs = CGColorSpace.CreateDeviceRGB ()) {

					// Create new context from buffer
					using (var context = new CGBitmapContext (pixelBuffer.BaseAddress,
						                     pixelBuffer.Width,
						                     pixelBuffer.Height,
						                     8,
						                     pixelBuffer.BytesPerRow,
						                     cs,
						                     (CGImageAlphaInfo)flags)) {

						// Get the image from the context
						using (var cgImage = context.ToImage ()) {

							// Unlock and return image
							pixelBuffer.Unlock ((CVPixelBufferLock)0);
							return UIImage.FromImage (cgImage);
						}
					}
				}
			}
		}
开发者ID:sergiimaindev,项目名称:monotouch-samples,代码行数:38,代码来源:OutputRecorder.cs


示例13: DrawPathAsBackground

		// Draws our animation path on the background image, just to show it
		protected void DrawPathAsBackground ()
		{
			// create our offscreen bitmap context
			var bitmapSize = new SizeF (View.Frame.Size);
			using (var context = new CGBitmapContext (
				       IntPtr.Zero,
				       (int)bitmapSize.Width, (int)bitmapSize.Height, 8,
				       (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB (),
				       CGImageAlphaInfo.PremultipliedFirst)) {
				
				// convert to View space
				var affineTransform = CGAffineTransform.MakeIdentity ();
				// invert the y axis
				affineTransform.Scale (1f, -1f);
				// move the y axis up
				affineTransform.Translate (0, View.Frame.Height);
				context.ConcatCTM (affineTransform);

				// actually draw the path
				context.AddPath (animationPath);
				context.SetStrokeColor (UIColor.LightGray.CGColor);
				context.SetLineWidth (3f);
				context.StrokePath ();
				
				// set what we've drawn as the backgound image
				backgroundImage.Image = UIImage.FromImage (context.ToImage());
			}
		}
开发者ID:BoogieMAN2K,项目名称:monotouch-samples,代码行数:29,代码来源:LayerAnimationScreen.xib.cs


示例14: CalculateLuminance

      private void CalculateLuminance(UIImage d)
      {
         var imageRef = d.CGImage;
         var width = imageRef.Width;
         var height = imageRef.Height;
         var colorSpace = CGColorSpace.CreateDeviceRGB();

         var rawData = Marshal.AllocHGlobal(height * width * 4);

         try
         {
			var flags = CGBitmapFlags.PremultipliedFirst | CGBitmapFlags.ByteOrder32Little; 
            var context = new CGBitmapContext(rawData, width, height, 8, 4 * width,
            colorSpace, (CGImageAlphaInfo)flags);

            context.DrawImage(new RectangleF(0.0f, 0.0f, (float)width, (float)height), imageRef);
            var pixelData = new byte[height * width * 4];
            Marshal.Copy(rawData, pixelData, 0, pixelData.Length);

            CalculateLuminance(pixelData, BitmapFormat.BGRA32);
         }
         finally
         {
            Marshal.FreeHGlobal(rawData);
         }
      }
开发者ID:Woo-Long,项目名称:ZXing.Net.Mobile,代码行数:26,代码来源:RGBLuminanceSource.monotouch.cs


示例15: GetPixelColor

        private UIColor GetPixelColor(CGPoint point, UIImage image)
        {
            var rawData = new byte[4];
            var handle = GCHandle.Alloc(rawData);
            UIColor resultColor = null;

            try
            {
                using (var colorSpace = CGColorSpace.CreateDeviceRGB())
                {
                    using (var context = new CGBitmapContext(rawData, 1, 1, 8, 4, colorSpace, CGImageAlphaInfo.PremultipliedLast))
                    {
                        context.DrawImage(new CGRect(-point.X, point.Y - image.Size.Height, image.Size.Width, image.Size.Height), image.CGImage);

                        float red   = (rawData[0]) / 255.0f;
                        float green = (rawData[1]) / 255.0f;
                        float blue  = (rawData[2]) / 255.0f;
                        float alpha = (rawData[3]) / 255.0f;

                        resultColor = UIColor.FromRGBA(red, green, blue, alpha);
                    }
                }
            }
            finally
            {
                handle.Free();
            }

            return resultColor;
        }
开发者ID:Manne990,项目名称:XamTest,代码行数:30,代码来源:HexagonButtonViewRenderer.cs


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


示例17: ProcessImageNamed

		static UIImage ProcessImageNamed (string imageName)
		{
			var image = UIImage.FromBundle (imageName);

			if (image == null)
				return null;

			if (imageName.Contains (".jpg"))
				return image;

			UIImage resultingImage;

			using (var colorSpace = CGColorSpace.CreateDeviceRGB ()) {
				// Create a bitmap context of the same size as the image.
				var imageWidth = (int)image.Size.Width;
				var imageHeight = (int)image.Size.Height;

				using (var bitmapContext = new CGBitmapContext (null, imageWidth, imageHeight, 8, imageHeight * 4,
										colorSpace, CGBitmapFlags.PremultipliedLast | CGBitmapFlags.ByteOrder32Little)) {

					// Draw the image into the graphics context.
					if (image.CGImage == null)
						throw new Exception ("Unable to get a CGImage from a UIImage.");

					bitmapContext.DrawImage (new CGRect (CGPoint.Empty, image.Size), image.CGImage);
					using (var newImageRef = bitmapContext.ToImage ()) {
						resultingImage = new UIImage (newImageRef);
					}
				}
			}

			return resultingImage;
		}
开发者ID:BytesGuy,项目名称:monotouch-samples,代码行数:33,代码来源:DataItemCellComposer.cs


示例18: ViewDidLoad

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			// set the background color of the view to white
			View.BackgroundColor = UIColor.White;
			
			// instantiate a new image view that takes up the whole screen and add it to 
			// the view hierarchy
			RectangleF imageViewFrame = new RectangleF (0, -NavigationController.NavigationBar.Frame.Height, View.Frame.Width, View.Frame.Height);
			imageView = new UIImageView (imageViewFrame);
			View.AddSubview (imageView);
			
			// create our offscreen bitmap context
			// size
			SizeF bitmapSize = new SizeF (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)) {
				
				// draw our coordinates for reference
				DrawCoordinateSpace (context);
				
				// draw our flag
				DrawFlag (context);
				
				// add a label
				DrawCenteredTextAtPoint (context, 384, 700, "Stars and Stripes", 60);
								
				// output the drawing to the view
				imageView.Image = UIImage.FromImage (context.ToImage ());
			}
		}
开发者ID:BoogieMAN2K,项目名称:monotouch-samples,代码行数:34,代码来源:Controller.cs


示例19: Draw

        public override void Draw(CGRect rect)
        {
            base.Draw (rect);

            var screenScale = UIScreen.MainScreen.Scale;
            var width = (int)(Bounds.Width * screenScale);
            var height = (int)(Bounds.Height * screenScale);

            IntPtr buff = System.Runtime.InteropServices.Marshal.AllocCoTaskMem (width * height * 4);
            try {
                using (var surface = SKSurface.Create (width, height, SKColorType.N_32, SKAlphaType.Premul, buff, width * 4)) {
                    var skcanvas = surface.Canvas;
                    skcanvas.Scale ((float)screenScale, (float)screenScale);
                    using (new SKAutoCanvasRestore (skcanvas, true)) {
                        skiaView.SendDraw (skcanvas);
                    }
                }

                using (var colorSpace = CGColorSpace.CreateDeviceRGB ())
                using (var bContext = new CGBitmapContext (buff, width, height, 8, width * 4, colorSpace, (CGImageAlphaInfo)bitmapInfo))
                using (var image = bContext.ToImage ())
                using (var context = UIGraphics.GetCurrentContext ()) {
                    // flip the image for CGContext.DrawImage
                    context.TranslateCTM (0, Frame.Height);
                    context.ScaleCTM (1, -1);
                    context.DrawImage (Bounds, image);
                }
            } finally {
                if (buff != IntPtr.Zero)
                    System.Runtime.InteropServices.Marshal.FreeCoTaskMem (buff);
            }
        }
开发者ID:mattleibow,项目名称:skiasharp-samples,代码行数:32,代码来源:NativeSkiaView.cs


示例20: ViewDidLoad

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			// no data
			IntPtr data = IntPtr.Zero;
			// size
			SizeF bitmapSize = new SizeF (200, 300);
			//View.Frame.Size;
			// 32bit RGB (8bits * 4components (aRGB) = 32bit)
			int bitsPerComponent = 8;
			// 4bytes for each pixel (32 bits = 4bytes)
			int bytesPerRow = (int)(4 * bitmapSize.Width);
			// no special color space
			CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB ();
			// aRGB
			CGImageAlphaInfo alphaType = CGImageAlphaInfo.PremultipliedFirst;
			
			
			using (CGBitmapContext context = new CGBitmapContext (data
				, (int)bitmapSize.Width, (int)bitmapSize.Height, bitsPerComponent
				, bytesPerRow, colorSpace, alphaType)) {
				
				// draw whatever here.
			}
			
			
			
		}
开发者ID:GSerjo,项目名称:monotouch-samples,代码行数:29,代码来源:Controller.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CGContext类代码示例发布时间:2022-05-24
下一篇:
C# CFNumberType类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap