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


C# CGBitmapContext.SetBlendMode方法代码示例

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


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

示例1: GetImagaDataFromPath

                void GetImagaDataFromPath (string path)
                {
                        int width, height;
                        NSImage src;
                        CGImage image;
                        CGContext context = null;
                        
                        data = new byte[TEXTURE_WIDTH * TEXTURE_HEIGHT * 4];
                        
                        src = new NSImage (path);
						var rect = CGRect.Empty;

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

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

示例3: AdjustImage

		public static UIImage AdjustImage (RectangleF rect, UIImage template, CGBlendMode mode, 
		                                   float red, float green, float blue, float alpha)
		{
			using (var cs = CGColorSpace.CreateDeviceRGB ()) {
				using (var context = new CGBitmapContext (IntPtr.Zero, (int)rect.Width, (int)rect.Height, 8, 
				                                          (int)rect.Height * 4, cs, CGImageAlphaInfo.PremultipliedLast)) {
					
					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:21Off,项目名称:21Off,代码行数:19,代码来源:GraphicsII.cs

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

示例5: TestRendering

        /// <summary>
        /// Executes rendering tests.
        /// </summary>
        /// <param name="embeddedResource">Embedded resource.</param>
        private void TestRendering(string embeddedResource)
        {
            Log.TraceEvent("Test", TraceEventType.Information,
                           "Testing rendering.");

            OsmSharp.Test.Performance.UI.Rendering.RenderingSerializedSceneTests<CGContextWrapper>.Test(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    embeddedResource),
                (width, height) =>
                {
                    CGColorSpace space = CGColorSpace.CreateDeviceRGB ();
                    int bytesPerPixel = 4;
                    int bytesPerRow = bytesPerPixel * width;
                    int bitsPerComponent = 8;
                    CGBitmapContext target = new CGBitmapContext (null, width, height,
                        bitsPerComponent, bytesPerRow,
                        space, // kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast
                        CGBitmapFlags.PremultipliedFirst | CGBitmapFlags.ByteOrder32Big);
                    target.InterpolationQuality = CGInterpolationQuality.None;
                    target.SetShouldAntialias (false);
                    target.SetBlendMode (CGBlendMode.Copy);
                    target.SetAlpha (1);
                    return new CGContextWrapper(target, new CGRect(
                        0, 0, width, height));
                },
                () => {
                    return new CGContextRenderer (1);
                });
        }
开发者ID:OpenMaps,项目名称:OsmSharp,代码行数:33,代码来源:OsmSharp_iOS_UI_SampleViewController.cs

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

示例7: ProcessedImage

        public UIImage ProcessedImage()
        {
            nfloat scale = UIScreen.MainScreen.Scale;
            CGImage imageRef = _originalImage.CGImage;

            if (imageRef == null)
                return null;

            var bytesPerRow = 0;
            var bitsPerComponent = imageRef.BitsPerComponent;
            CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
            var bitmapInfo = imageRef.BitmapInfo;
            CGBitmapContext context = new CGBitmapContext(null,
                                          (nint)(_targetSize.Width * scale),
                                          (nint)(_targetSize.Height * scale),
                                          bitsPerComponent,
                                          bytesPerRow,
                                          colorSpace,
                                          bitmapInfo);

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

            CGRect targetFrame = LocalCropFrame();

            context.InterpolationQuality = CGInterpolationQuality.High;
            context.SetBlendMode(CGBlendMode.Copy);
            context.DrawImage(targetFrame, imageRef);

            var contextImage = context.ToImage();
            UIImage finalImage = null;

            context.Dispose();

            if (contextImage != null)
            {
                finalImage = UIImage.FromImage(contextImage, scale, UIImageOrientation.Up);
                contextImage.Dispose();
            }

            imageRef.Dispose();
            return finalImage;
        }
开发者ID:ProstoKorol,项目名称:HIPImageCropperXamarin,代码行数:47,代码来源:HIPImageCropperView.cs


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