/// <summary> /// Returns an autoreleased NSImage, consisting of the selected portion of the reciever's image. /// If there's no selection, this method will return the original image. /// </summary> public NSImage CroppedImage() { NSRect sourceImageRect = RectCoveredByImageInBounds(this.Cell.CastTo<NSImageCell>(), this.Bounds); NSRect newImageBounds = NSRect.NSIntersectionRect(this.selectionMarker.SelectedRect, sourceImageRect); if (!NSRect.NSIsEmptyRect(newImageBounds)) { NSImage newImage = new NSImage(sourceImageRect.size); NSAffineTransform pathAdjustment = NSAffineTransform.Transform; NSBezierPath croppingPath = this.selectionMarker.SelectedPath; pathAdjustment.TranslateXByYBy(-NSRect.NSMinX(sourceImageRect), -NSRect.NSMinY(sourceImageRect)); croppingPath = pathAdjustment.TransformBezierPath(croppingPath); newImage.LockFocus(); NSGraphicsContext.CurrentContext.ShouldAntialias = this.shouldAntiAlias; NSColor.BlackColor.Set(); croppingPath.Fill(); this.Image.CompositeToPointOperation(NSPoint.NSZeroPoint, NSCompositingOperation.NSCompositeSourceIn); newImage.UnlockFocus(); newImage.Autorelease(); return newImage; } return this.Image; }
public void AnimateNextExpressionFrame() { this._expressionFrameTimer = null; NSDictionary frameDictionary = this._curFrameArray.ObjectAtIndex(this._curFrameIndex).CastTo<NSDictionary>(); // Grab image and force draw. Use cache to reduce disk hits NSString frameImageName = frameDictionary[kCharacterExpressionFrameImageFileNameKey].CastTo<NSString>(); Id imageName = this._imageCache[frameImageName]; if (imageName != null) { this._curFrameImage = imageName.CastTo<NSImage>(); } else { this._curFrameImage = new NSImage(NSBundle.MainBundle.PathForResourceOfType(frameImageName, NSString.Empty)); this._imageCache[frameImageName] = this._curFrameImage; this._curFrameImage.Release(); } this.Display(); // If there is more than one frame, then schedule drawing of the next and increment our frame index. if (this._curFrameArray.Count > 1) { this._curFrameIndex++; this._curFrameIndex %= this._curFrameArray.Count; this._expressionFrameTimer = NSTimer.ScheduledTimerWithTimeIntervalTargetSelectorUserInfoRepeats(frameDictionary[kCharacterExpressionFrameDurationKey].CastTo<NSNumber>().FloatValue, this, ObjectiveCRuntime.Selector("animateNextExpressionFrame"), null, false); } }
public void ApplicationDidFinishLaunching(NSNotification notification) { // Gets the DRBurn icon and assign it another name NSImage icon = NSImage.ImageNamed(DiscRecordingUIFramework.DRBurnIcon); icon.SetName("OldDRBurnIcon"); // Gets the Monobjc icon and assign it as default icon icon = new NSImage(NSBundle.MainBundle.PathForImageResource("Monobjc.icns")); icon.SetName(DiscRecordingUIFramework.DRBurnIcon); }
/// <summary> /// Create a <see cref="NSImage"/> from a file. /// </summary> /// <param name="filename">The filename.</param> /// <returns>An autoreleased <see cref="NSImage"/> instance</returns> public static NSImage ImageFromFile(NSString filename) { NSImage result = null; if (filename != null) { NSData data = NSData.DataWithContentsOfFile(filename); result = new NSImage(data); result.Autorelease(); } return result; }
public void ApplicationDidFinishLaunching(NSNotification notification) { NSThread.MakeMultiThreaded (); this.imageRep = new NSBitmapImageRep (IntPtr.Zero, width, height, 8, 4, true, false, "NSCalibratedRGBColorSpace", 4 * width, 32); NSImage image = new NSImage (new NSSize (width, height)); image.AddRepresentation (this.imageRep); this.imageView.Image = image; Thread t = new Thread (this.DoComputation); t.IsBackground = true; t.Start (); }
/// <summary> /// Create a <see cref="NSImage"/> from a stream. /// </summary> /// <param name="stream">The stream.</param> /// <returns>An autoreleased <see cref="NSImage"/> instance</returns> public static NSImage ImageFromStream(Stream stream) { NSImage result = null; if (stream != null) { byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); NSData data = new NSData(buffer); result = new NSImage(data); data.Release(); result.Autorelease(); } return result; }
public void ApplicationDidFinishLaunching(NSNotification notification) { // Gets the DRErase icon and assign it another name NSImage icon = NSImage.ImageNamed(DiscRecordingUIFramework.DREraseIcon); icon.SetName("OldDREraseIcon"); // Gets the Monobjc icon and assign it as default icon icon = new NSImage(NSBundle.MainBundle.PathForImageResource("Monobjc.icns")); icon.SetName(DiscRecordingUIFramework.DREraseIcon); NSNotificationCenter.DefaultCenter.AddObserverSelectorNameObject(this, ObjectiveCRuntime.Selector("eraseCompleted:"), DREraseProgressPanel.DREraseProgressPanelDidFinishNotification, null); this.EraseCompleted(null); }
public override void MouseDown(NSEvent theEvent) { NSPasteboard dragPasteboard = NSPasteboard.PasteboardWithName(NSPasteboard.NSDragPboard); NSImage dragImage = new NSImage(this.Image.Size); dragPasteboard.DeclareTypesOwner(NSArray.ArrayWithObject(NSPasteboard.NSTIFFPboardType), this); dragPasteboard.AddTypesOwner(NSArray.ArrayWithObject(NSPasteboard.NSPDFPboardType), this); dragImage.LockFocus(); this.Image.DissolveToPointFraction(NSPoint.NSZeroPoint, 0.5f); dragImage.UnlockFocus(); dragImage.ScalesWhenResized = true; dragImage.Size = this.Bounds.size; this.DragImageAtOffsetEventPasteboardSourceSlideBack(dragImage, this.Bounds.origin, NSSize.NSZeroSize, theEvent, dragPasteboard, this, true); dragImage.Release(); }
public void OpenPanelDidEndReturnCodeContextInfo(NSOpenPanel sheet, NSInteger returnCode, IntPtr contextInfo) { NSImage image = new NSImage(sheet.Filename).SafeAutorelease(); this.imageView.Image = image; this.ImageChanged(null); }
public NSImage Snapshot(NSRect sourceRect) { NSImage snapshot = new NSImage(sourceRect.size); this.LockFocus(); NSBitmapImageRep rep = new NSBitmapImageRep(sourceRect).SafeAutorelease(); this.UnlockFocus(); snapshot.AddRepresentation(rep); snapshot.Autorelease(); return snapshot; }
/// <summary> /// Decrypts the given data and return an image. /// </summary> /// <param name="encryptedData">The encrypted artwork data.</param> /// <param name="encryptionSeed">The encryption seed to use.</param> /// <returns>The decrypted artwork image.</returns> public static NSImage ImageFromEncryptedData(NSData encryptedData, NSString encryptionSeed) { NSData decryptedData = NSData.DecryptData(encryptedData, encryptionSeed); NSImage image = new NSImage(decryptedData); return image.SafeAutorelease<NSImage>(); }
/// <summary> /// Converts the given object to the type of this converter, using the specified context and culture information. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides a format context.</param> /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo"/> to use as the current culture.</param> /// <param name="value">The <see cref="T:System.Object"/> to convert.</param> /// <returns> /// An <see cref="T:System.Object"/> that represents the converted value. /// </returns> /// <exception cref="T:System.NotSupportedException"> /// The conversion cannot be performed. /// </exception> public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value) { // As pool are scoped, it does not hurt if we create ours during the method call. using (NSAutoreleasePool pool = new NSAutoreleasePool()) { byte[] rawData = value as byte[]; if (rawData == null) { return base.ConvertFrom (context, culture, value); } // The image creation will be based on a NSData instance that wraps the byte array NSData data = new NSData (rawData); NSImage image = new NSImage (data); data.Release (); return image; // TODO: Find a way to avoid the memory leak as we do not release the instance... } }