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


C# NSImage.LockFocus方法代码示例

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


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

示例1: Tint

		public static NSImage Tint(this NSImage image, NSColor tint)
		{
			var colorGenerator = new CIConstantColorGenerator
			{ 
				Color = CIColor.FromCGColor(tint.CGColor)
			};

			var colorFilter = new CIColorControls
			{
				Image = (CIImage)colorGenerator.ValueForKey(CIFilterOutputKey.Image),
				Saturation = 3f,
				Brightness = 0.35f,
				Contrast = 1f
			};

			var monochromeFilter = new CIColorMonochrome
			{
				Image = CIImage.FromCGImage(image.CGImage),
				Color = CIColor.FromRgb(0.75f, 0.75f, 0.75f),
				Intensity = 1f
			};

			var compositingFilter = new CIMultiplyCompositing
			{
				Image = (CIImage)colorFilter.ValueForKey(CIFilterOutputKey.Image),
				BackgroundImage = (CIImage)monochromeFilter.ValueForKey(CIFilterOutputKey.Image)
			};

			var outputImage = (CIImage)compositingFilter.ValueForKey(CIFilterOutputKey.Image);
			var extent = outputImage.Extent;

			var newsize = sd.Size.Truncate(extent.Size);
			if (newsize.IsEmpty)
				return image;

			var tintedImage = new NSImage(newsize);
			tintedImage.LockFocus();
			try
			{
				var graphics = NSGraphicsContext.CurrentContext.GraphicsPort;
				var ciContext = CIContext.FromContext(graphics, new CIContextOptions { UseSoftwareRenderer = true });
				ciContext.DrawImage(outputImage, extent, extent);
			}
			finally
			{
				tintedImage.UnlockFocus();
			}

			var newrep = tintedImage.Representations()[0];
			newrep.Size = image.Size;
			return tintedImage;
		}
开发者ID:Exe0,项目名称:Eto,代码行数:52,代码来源:NSImageExtensions.cs

示例2: GenerateImage

        /// <summary>
        /// Generates the image.
        /// </summary>
        /// <returns>The image.</returns>
        /// <param name="view">View.</param>
        public static NSImage GenerateImage(this NSView view)
        {
            RectangleF bounds = view.Bounds;

            NSBitmapImageRep bir = view.BitmapImageRepForCachingDisplayInRect (bounds);
            bir.Size = bounds.Size;
            view.CacheDisplay (bounds, bir);

            NSImage targetImage = new NSImage(bounds.Size);
            targetImage.LockFocus();
            bir.DrawInRect(bounds);
            targetImage.UnlockFocus();

            return targetImage;
        }
开发者ID:trinnguyen,项目名称:oxyplot-xammac,代码行数:20,代码来源:ExportExtensions.cs

示例3: ScaleImageSquare

 public static NSImage ScaleImageSquare(NSImage sourceImage, int size)
 {
     var newSize = new SizeF(size, size);
     var newImage = new NSImage(newSize);
     newImage.LockFocus();
     sourceImage.Size = newSize;
     NSGraphicsContext.CurrentContext.ImageInterpolation = NSImageInterpolation.High;
     sourceImage.DrawInRect(new RectangleF(0, 0, size, size), new RectangleF(), NSCompositingOperation.Copy, 1);
     //sourceImage.Draw(new PointF(), new RectangleF(0, 0, newSize.Width, newSize.Height), NSCompositingOperation.Copy, 1); 
     newImage.UnlockFocus();
     return newImage;
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:12,代码来源:CoreGraphicsHelper.cs

示例4: MakeGLDisplayListFirst

		// Create the set of display lists for the bitmaps
		bool MakeGLDisplayListFirst (char first, int count, int baseDL)
		{

			int curListIndex;
			NSColor blackColor;
			NSMutableDictionary attribDict;
			int dListNum;
			NSString currentChar;
			char currentUnichar;
			SizeF charSize;
			RectangleF charRect;
			NSImage theImage;
			bool retval;

			// Make sure the list isn't already under construction
			GL.GetInteger (GetPName.ListIndex, out curListIndex);
			if (curListIndex != 0) {
				Console.WriteLine ("Display list already under construction");
				return false;
			}

			// Save pixel unpacking state
			GL.PushClientAttrib (ClientAttribMask.ClientPixelStoreBit);

			GL.PixelStore (PixelStoreParameter.UnpackSwapBytes, 0);
			GL.PixelStore (PixelStoreParameter.UnpackLsbFirst, 0);
			GL.PixelStore (PixelStoreParameter.UnpackSkipPixels, 0);
			GL.PixelStore (PixelStoreParameter.UnpackSkipRows, 0);
			GL.PixelStore (PixelStoreParameter.UnpackRowLength, 0);
			GL.PixelStore (PixelStoreParameter.UnpackAlignment, 0);

			blackColor = NSColor.Black;

			attribDict = new NSMutableDictionary ();
			attribDict.SetValueForKey (font, NSAttributedString.FontAttributeName);
			attribDict.SetValueForKey (NSColor.White, NSAttributedString.ForegroundColorAttributeName);
			attribDict.SetValueForKey (blackColor, NSAttributedString.BackgroundColorAttributeName);

			charRect.Location.X = charRect.Location.Y = 0;

			theImage = new NSImage (new SizeF (0,0));
			retval = true;

			for (dListNum = baseDL, currentUnichar = first; currentUnichar < first + count; 
				dListNum++, currentUnichar++) {

				currentChar = new NSString (Char.ToString (currentUnichar));
				charSize = currentChar.StringSize (attribDict);
				charRect.Size = charSize;
				charRect = charRect.Integral ();
				if (charRect.Size.Width > 0 && charRect.Size.Height > 0) {

					theImage.Size = charRect.Size;
					theImage.LockFocus ();
					NSGraphicsContext.CurrentContext.ShouldAntialias = false;
					blackColor.Set ();
					NSBezierPath.FillRect (charRect);
					currentChar.DrawString (charRect, attribDict);
					theImage.UnlockFocus ();

					if (!MakeDisplayList(dListNum, theImage)) {
						retval = false;
						break;
					}
				}
			}
			return retval;
		}
开发者ID:Anomalous-Software,项目名称:monomac,代码行数:69,代码来源:BitmapFont.cs

示例5: MakeRotatedCopy

		NSImage MakeRotatedCopy (NSImage original, float degrees)
		{
			var copy = new NSImage (original.Size);
			copy.LockFocus ();
			try {
				var rot = new NSAffineTransform ();
				rot.Translate (original.Size.Width / 2, original.Size.Height / 2);
				rot.RotateByDegrees (degrees);
				rot.Translate (-original.Size.Width / 2, -original.Size.Height / 2);
				rot.Concat ();
				original.Draw (PointF.Empty, RectangleF.Empty, NSCompositingOperation.Copy, 1);
			} finally {
				copy.UnlockFocus ();
			}
			return copy;
		}
开发者ID:Tak,项目名称:monodevelop-novell,代码行数:16,代码来源:SelectEncodingPanel.cs

示例6: CreateTextSprite


//.........这里部分代码省略.........
                {
                    dimensions.Width = boundingRect.Width;

                    // Restore our alignment before drawing - see notes above.
                    nsparagraphStyle.Alignment = textAlign;
                    stringWithAttributes.Dispose();
                    stringWithAttributes = null;
                    stringWithAttributes = new NSAttributedString(text, nsAttributes);
                }
                if (dimensions.Height == 8388608)
                {
                    dimensions.Height = boundingRect.Height;
                }
            }

            imageWidth = (int)dimensions.Width;
            imageHeight = (int)dimensions.Height;

            // Alignment
            var xOffset = 0.0f;
            switch (textAlign) {
            case NSTextAlignment.Left:
                xOffset = 0; 
                break;
            case NSTextAlignment.Center: 
                xOffset = (dimensions.Width-boundingRect.Width)/2.0f; 
                break;
            case NSTextAlignment.Right: xOffset = dimensions.Width-boundingRect.Width; break;
            default: break;
            }

            // Line alignment
            var yOffset = (CCVerticalTextAlignment.Top == verticleAlignement 
                || boundingRect.Height >= dimensions.Height) ? (dimensions.Height - boundingRect.Height)  // align to top
                : (CCVerticalTextAlignment.Bottom == verticleAlignement) ? 0                    // align to bottom
                : (imageHeight - boundingRect.Height) / 2.0f;                                   // align to center

            //Find the rect that the string will draw into inside the dimensions 
            var drawRect = new RectangleF(xOffset
                , yOffset
                , boundingRect.Width 
                , boundingRect.Height);


            NSImage image = null;
            try
            {
                //Set antialias or not
                NSGraphicsContext.CurrentContext.ShouldAntialias = textDef.isShouldAntialias;

                image = new NSImage(new SizeF(imageWidth, imageHeight));

                image.LockFocus();

                // set a default transform
                var transform = new NSAffineTransform();
                transform.Set();

                stringWithAttributes.DrawInRect(drawRect);

                image.UnlockFocus();

                // We will use Texture2D from stream here instead of CCTexture2D stream.
                var tex = Texture2D.FromStream(CCDrawManager.SharedDrawManager.XnaGraphicsDevice, image);

                // Debugging purposes
//            var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
//            var fileName = Path.Combine(path, "Label3.png");
//            using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
//            {
//                tex.SaveAsPng(stream, imageWidth, imageHeight);
//            }

                // Create our texture of the label string.
                var texture = new CCTexture2D(tex);

                return texture;
            }
            catch (Exception exc)
            {
                CCLog.Log ("CCLabel: Error creating native label:{0}\n{1}", exc.Message, exc.StackTrace);
            }
            finally
            {
                // clean up the resources
                if (image != null) 
                {
                    image.Dispose ();
                    image = null;
                }
                if (stringWithAttributes != null) 
                {
                    stringWithAttributes.Dispose ();
                    stringWithAttributes = null;
                }
            }
            return new CCTexture2D ();


        }
开发者ID:haithemaraissia,项目名称:CocosSharp,代码行数:101,代码来源:CCLabel-CoreGraphics.cs


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