本文整理汇总了C#中MonoMac.AppKit.NSImage.AddRepresentation方法的典型用法代码示例。如果您正苦于以下问题:C# NSImage.AddRepresentation方法的具体用法?C# NSImage.AddRepresentation怎么用?C# NSImage.AddRepresentation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MonoMac.AppKit.NSImage
的用法示例。
在下文中一共展示了NSImage.AddRepresentation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToNSImage
public static NSImage ToNSImage(this CIImage image, System.Drawing.SizeF size)
{
var imageRep = NSCIImageRep.FromCIImage(image);
var nsImage = new NSImage(size);
nsImage.AddRepresentation(imageRep);
return nsImage;
}
示例2: CreateImage
public override object CreateImage (object backend)
{
var gc = (CGContextBackend)backend;
var img = new NSImage (((CGBitmapContext)gc.Context).ToImage (), gc.Size);
var imageData = img.AsTiff ();
var imageRep = (NSBitmapImageRep) NSBitmapImageRep.ImageRepFromData (imageData);
var im = new NSImage ();
im.AddRepresentation (imageRep);
return im;
}
示例3: RenderToImageInMemory
public IBasicImage RenderToImageInMemory()
{
NSImage image = null;
InvokeOnMainThread(() => {
//Console.WriteLine("MemoryGraphicsContextWrapper - RenderToImageInMemory");
NSGraphicsContext.GlobalRestoreGraphicsState();
image = new NSImage(new SizeF(BoundsWidth, BoundsHeight));
image.AddRepresentation(_bitmap);
});
var basicImage = new BasicImage(image);
return basicImage;
}
示例4: Resize
public static NSImage Resize(this NSImage image, sd.Size newsize, ImageInterpolation interpolation = ImageInterpolation.Default)
{
var newimage = new NSImage(newsize);
var newrep = new NSBitmapImageRep(IntPtr.Zero, newsize.Width, newsize.Height, 8, 4, true, false, NSColorSpace.DeviceRGB, 4 * newsize.Width, 32);
newimage.AddRepresentation(newrep);
var graphics = NSGraphicsContext.FromBitmap(newrep);
NSGraphicsContext.GlobalSaveGraphicsState();
NSGraphicsContext.CurrentContext = graphics;
graphics.GraphicsPort.InterpolationQuality = interpolation.ToCG();
image.DrawInRect(new sd.RectangleF(sd.PointF.Empty, newimage.Size), new sd.RectangleF(sd.PointF.Empty, image.Size), NSCompositingOperation.SourceOver, 1f);
NSGraphicsContext.GlobalRestoreGraphicsState();
return newimage;
}
示例5: Tint
public static NSImage Tint(this NSImage image, NSColor tint)
{
CIFilter colorGenerator = CIFilter.FromName("CIConstantColorGenerator");
CIColor color = CIColor.FromCGColor(tint.ToCG());
colorGenerator.SetValueForKey(color, CIFilterInputKey.Color);
CIFilter colorFilter = CIFilter.FromName("CIColorControls");
colorFilter.SetValueForKey(colorGenerator.ValueForKey(CIFilterOutputKey.Image), CIFilterInputKey.Image);
colorFilter.SetValueForKey(NSNumber.FromFloat(3f), CIFilterInputKey.Saturation);
colorFilter.SetValueForKey(NSNumber.FromFloat(0.35f), CIFilterInputKey.Brightness);
colorFilter.SetValueForKey(NSNumber.FromFloat(1f), CIFilterInputKey.Contrast);
CIFilter monochromeFilter = CIFilter.FromName("CIColorMonochrome");
CIImage baseImage = CIImage.FromCGImage(image.CGImage);
monochromeFilter.SetValueForKey(baseImage, CIFilterInputKey.Image);
monochromeFilter.SetValueForKey(CIColor.FromRgb(0.75f, 0.75f, 0.75f), CIFilterInputKey.Color);
monochromeFilter.SetValueForKey(NSNumber.FromFloat(1f), CIFilterInputKey.Intensity);
CIFilter compositingFilter = CIFilter.FromName("CIMultiplyCompositing");
compositingFilter.SetValueForKey(colorFilter.ValueForKey(CIFilterOutputKey.Image), CIFilterInputKey.Image);
compositingFilter.SetValueForKey(monochromeFilter.ValueForKey(CIFilterOutputKey.Image), CIFilterInputKey.BackgroundImage);
CIImage outputImage = (CIImage)compositingFilter.ValueForKey(CIFilterOutputKey.Image);
var extent = outputImage.Extent;
var newsize = sd.Size.Truncate(extent.Size);
var tintedImage = new NSImage(newsize);
var newrep = new NSBitmapImageRep(IntPtr.Zero, newsize.Width, newsize.Height, 8, 4, true, false, NSColorSpace.DeviceRGB, 4 * newsize.Width, 32);
tintedImage.AddRepresentation(newrep);
var graphics = NSGraphicsContext.FromBitmap(newrep);
NSGraphicsContext.GlobalSaveGraphicsState();
NSGraphicsContext.CurrentContext = graphics;
var ciContext = CIContext.FromContext(graphics.GraphicsPort, new CIContextOptions { UseSoftwareRenderer = true });
ciContext.DrawImage(outputImage, extent, extent);
NSGraphicsContext.GlobalRestoreGraphicsState();
newrep.Size = image.Size;
return tintedImage;
}
示例6: Colourize
public static void Colourize (NSView control, Color color, Action drawAction)
{
var size = control.Frame.Size;
var image = new NSImage (size);
image.LockFocusFlipped (control.IsFlipped);
drawAction ();
image.UnlockFocus ();
var ciImage = CIImage.FromData (image.AsTiff ());
if (control.IsFlipped) {
var realSize = control.ConvertSizeToBase (size);
var affineTransform = new NSAffineTransform ();
affineTransform.Translate (0, realSize.Height);
affineTransform.Scale (1, -1);
var filter1 = CIFilter.FromName ("CIAffineTransform");
filter1.SetValueForKey (ciImage, CIInputImage);
filter1.SetValueForKey (affineTransform, CIInputTransform);
ciImage = filter1.ValueForKey (CIOutputImage) as CIImage;
}
var filter2 = CIFilter.FromName ("CIColorControls");
filter2.SetDefaults ();
filter2.SetValueForKey (ciImage, CIInputImage);
filter2.SetValueForKey (new NSNumber (0.0f), CIInputSaturation);
ciImage = filter2.ValueForKey (CIOutputImage) as CIImage;
var filter3 = CIFilter.FromName ("CIColorMatrix");
filter3.SetDefaults ();
filter3.SetValueForKey (ciImage, CIInputImage);
filter3.SetValueForKey (new CIVector (0, color.R, 0), CIInputRVector);
filter3.SetValueForKey (new CIVector (color.G, 0, 0), CIInputGVector);
filter3.SetValueForKey (new CIVector (0, 0, color.B), CIInputBVector);
ciImage = filter3.ValueForKey (CIOutputImage) as CIImage;
image = new NSImage (size);
var rep = NSCIImageRep.FromCIImage (ciImage);
image.AddRepresentation (rep);
image.Draw (SD.PointF.Empty, new SD.RectangleF (SD.PointF.Empty, size), NSCompositingOperation.SourceOver, 1);
/* Use this when implemented in maccore:
ciImage.Draw (SD.PointF.Empty, new SD.RectangleF (SD.PointF.Empty, size), NSCompositingOperation.SourceOver, 1);
*/
}
示例7: Badge
public void Badge ()
{
using (NSAutoreleasePool a = new NSAutoreleasePool ()) {
foreach (string path in this.paths) {
string extension = Path.GetExtension (path.ToLower ());
NSImage new_icon = new NSImage ();
if (!this.icons.ContainsKey (extension)) {
foreach (int size in this.sizes) {
NSImage file_icon = NSWorkspace.SharedWorkspace.IconForFileType (extension);
file_icon.Size = new SizeF (size, size);
// TODO: replace this with the sync icon
NSImage overlay_icon = NSWorkspace.SharedWorkspace.IconForFileType ("sln");
overlay_icon.Size = new SizeF (size / 2, size / 2);
file_icon.LockFocus ();
NSGraphicsContext.CurrentContext.ImageInterpolation = NSImageInterpolation.High;
overlay_icon.Draw (
new RectangleF (0, 0, file_icon.Size.Width / 3, file_icon.Size.Width / 3),
new RectangleF (), NSCompositingOperation.SourceOver, 1.0f);
file_icon.UnlockFocus ();
new_icon.AddRepresentation (file_icon.Representations () [0]);
}
this.icons.Add (extension, new_icon);
} else {
new_icon = this.icons [extension];
}
NSWorkspace.SharedWorkspace.SetIconforFile (new_icon, path, 0);
}
}
}
示例8: RenderWidget
public override object RenderWidget (Widget w)
{
var view = ((ViewBackend)w.GetBackend ()).Widget;
view.LockFocus ();
var img = new NSImage (view.DataWithPdfInsideRect (view.Bounds));
var imageData = img.AsTiff ();
var imageRep = (NSBitmapImageRep)NSBitmapImageRep.ImageRepFromData (imageData);
var im = new NSImage ();
im.AddRepresentation (imageRep);
im.Size = new System.Drawing.SizeF ((float)view.Bounds.Width, (float)view.Bounds.Height);
return im;
}
示例9: addFrame
partial void addFrame (NSObject sender)
{
NSImage image;
lock (this){
if (currentImage == null)
return;
var img = CIImage.FromImageBuffer (currentImage);
Console.WriteLine (img);
var imageRep = NSCIImageRep.FromCIImage (CIImage.FromImageBuffer (currentImage));
image = new NSImage (imageRep.Size);
image.AddRepresentation (imageRep);
}
movie.AddImage (image, new QTTime (1, 10), attrs);
movie.CurrentTime = movie.Duration;
movieView.NeedsDisplay = true;
}
示例10: ConvertToBitmap
public override object ConvertToBitmap(object handle, double width, double height, double scaleFactor, ImageFormat format)
{
int pixelWidth = (int)(width * scaleFactor);
int pixelHeight = (int)(height * scaleFactor);
if (handle is CustomImage) {
var flags = CGBitmapFlags.ByteOrderDefault;
int bytesPerRow;
switch (format) {
case ImageFormat.ARGB32:
bytesPerRow = pixelWidth * 4;
flags |= CGBitmapFlags.PremultipliedFirst;
break;
case ImageFormat.RGB24:
bytesPerRow = pixelWidth * 3;
flags |= CGBitmapFlags.None;
break;
default:
throw new NotImplementedException ("ImageFormat: " + format.ToString ());
}
var bmp = new CGBitmapContext (IntPtr.Zero, pixelWidth, pixelHeight, 8, bytesPerRow, Util.DeviceRGBColorSpace, flags);
bmp.TranslateCTM (0, pixelHeight);
bmp.ScaleCTM ((float)scaleFactor, (float)-scaleFactor);
var ctx = new CGContextBackend {
Context = bmp,
Size = new SizeF ((float)width, (float)height),
InverseViewTransform = bmp.GetCTM ().Invert (),
ScaleFactor = scaleFactor
};
var ci = (CustomImage)handle;
ci.DrawInContext (ctx);
var img = new NSImage (((CGBitmapContext)bmp).ToImage (), new SizeF (pixelWidth, pixelHeight));
var imageData = img.AsTiff ();
var imageRep = (NSBitmapImageRep)NSBitmapImageRep.ImageRepFromData (imageData);
var im = new NSImage ();
im.AddRepresentation (imageRep);
im.Size = new SizeF ((float)width, (float)height);
bmp.Dispose ();
return im;
}
else {
NSImage img = (NSImage)handle;
NSBitmapImageRep bitmap = img.Representations ().OfType<NSBitmapImageRep> ().FirstOrDefault ();
if (bitmap == null) {
var imageData = img.AsTiff ();
var imageRep = (NSBitmapImageRep)NSBitmapImageRep.ImageRepFromData (imageData);
var im = new NSImage ();
im.AddRepresentation (imageRep);
im.Size = new SizeF ((float)width, (float)height);
return im;
}
return handle;
}
}
示例11: ToNS
public static NSImage ToNS(this Image image, int? size = null)
{
if (image == null)
return null;
var source = image.Handler as IImageSource;
if (source == null)
return null;
var nsimage = source.GetImage();
if (size != null)
{
var rep = nsimage.BestRepresentation(new CGRect(0, 0, size.Value, size.Value), null, null);
if (rep.PixelsWide > size.Value || rep.PixelsHigh > size.Value)
{
var max = Math.Max(nsimage.Size.Width, nsimage.Size.Height);
var newsize = new CGSize((int)(size.Value * nsimage.Size.Width / max), (int)(size.Value * nsimage.Size.Height / max));
nsimage = nsimage.Resize(newsize);
}
else
{
nsimage = new NSImage();
nsimage.AddRepresentation(rep);
}
}
return nsimage;
}
示例12: RenderImage
partial void RenderImage(NSObject sender)
{
var size = ImageView.Bounds.Size;
int pixelWidth = (int) size.Width, pixelHeight = (int) size.Height;
//var bitmapData = new char[pixelWidth * pixelHeight * PIXEL_BYTES];
// TODO: Clean up this memory
var bitmapData = Marshal.AllocHGlobal(pixelWidth * pixelHeight * PIXEL_BYTES);
var imageRep = new NSBitmapImageRep(bitmapData, pixelWidth, pixelHeight, SAMPLE_SIZE, SAMPLE_NUMBER, false,
false, NSColorSpace.CalibratedRGB, pixelWidth * PIXEL_BYTES, 0);
//var imageRep = new NSBitmapImageRep(new RectangleF(PointF.Empty, size));
var image = new NSImage(size);
var film = new ColorSurfaceFilm(pixelWidth, pixelHeight, 1);
var scene = new SimpleScene().CreateScene(film);
scene.Render();
var imageBuffer = new NSBitmapImageRepImageBuffer(imageRep);
film.Present(imageBuffer);
image.AddRepresentation(imageRep);
ImageView.Image = image;
}
示例13: Create
public object Create(IconFrame frame, Func<Stream> load)
{
var img = new NSImage();
img.AddRepresentation(new LazyImageRep { Load = load });
return new Bitmap(new BitmapHandler(img));
}
示例14: ConvertToBitmap
public override object ConvertToBitmap(object handle, int pixelWidth, int pixelHeight, ImageFormat format)
{
if (handle is CustomImage) {
var flags = CGBitmapFlags.ByteOrderDefault;
int bytesPerRow;
switch (format) {
case ImageFormat.ARGB32:
bytesPerRow = pixelWidth * 4;
flags |= CGBitmapFlags.PremultipliedFirst;
break;
case ImageFormat.RGB24:
bytesPerRow = pixelWidth * 3;
flags |= CGBitmapFlags.None;
break;
default:
throw new NotImplementedException ("ImageFormat: " + format.ToString ());
}
var bmp = new CGBitmapContext (IntPtr.Zero, pixelWidth, pixelHeight, 8, bytesPerRow, Util.DeviceRGBColorSpace, flags);
bmp.TranslateCTM (0, pixelHeight);
bmp.ScaleCTM (1, -1);
var ctx = new CGContextBackend {
Context = bmp,
Size = new SizeF (pixelWidth, pixelHeight),
InverseViewTransform = bmp.GetCTM ().Invert ()
};
var ci = (CustomImage)handle;
ci.DrawInContext (ctx);
var img = new NSImage (((CGBitmapContext)bmp).ToImage (), new SizeF (pixelWidth, pixelHeight));
var imageData = img.AsTiff ();
var imageRep = (NSBitmapImageRep) NSBitmapImageRep.ImageRepFromData (imageData);
var im = new NSImage ();
im.AddRepresentation (imageRep);
return im;
}
else
return handle;
}
示例15: ToNS
public static NSImage ToNS(this Image image, int? size = null)
{
if (image == null)
return null;
var source = image.Handler as IImageSource;
if (source == null)
return null;
var nsimage = source.GetImage();
if (size != null)
{
var mainScale = Screen.PrimaryScreen.RealScale;
var scales = new [] { 1f, 2f }; // generate both retina and non-retina representations
var sz = (float)Math.Ceiling(size.Value / mainScale);
var rep = nsimage.BestRepresentation(new CGRect(0, 0, sz, sz), null, null);
sz = size.Value;
var imgsize = image.Size;
var max = Math.Max(imgsize.Width, imgsize.Height);
var newimagesize = new CGSize((nint)(sz * imgsize.Width / max), (nint)(sz * imgsize.Height / max));
var newimage = new NSImage(newimagesize);
foreach (var scale in scales)
{
sz = (float)Math.Ceiling(size.Value * scale / mainScale);
rep = nsimage.BestRepresentation(new CGRect(0, 0, sz, sz), null, null);
max = (int)Math.Max(rep.PixelsWide, rep.PixelsHigh);
sz = (float)Math.Ceiling(size.Value * scale);
var newsize = new CGSize((nint)(sz * rep.PixelsWide / max), (nint)(sz * rep.PixelsHigh / max));
newimage.AddRepresentation(rep.Resize(newsize, imageSize: newimagesize));
}
nsimage = newimage;
}
return nsimage;
}