本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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 ();
}