nsimage

Thin white lines being added when cropping an image (Objective-C OSX)

回眸只為那壹抹淺笑 提交于 2019-12-12 11:35:32
问题 I am cutting up a large image and saving it into many different images. I first implemented this in iOS and it is working fine, but when I try and port the code to OSX , a thin white line (1 pixel) appears on the top and right of the image. The line is not pure white, or solid (see sample below). Here is the iOS code to make one sub-image, that works like a champ: -(void)testMethod:(int)page forRect:(CGRect)rect{ NSString *filePath = @"imageName"; NSData *data = [HeavyResourceManager

Getting NSImage from CGImageRef

旧街凉风 提交于 2019-12-12 08:19:59
问题 I am trying process an image in CoreGraphics and then return the processed image back to an NSImage for saving and displaying. I have ample resources on how to perform these functions in iOS but the helper methods seem to be missing in NSImage . In iOS the class method is imageWithCGImage: , how can you do this in Mac OS? 回答1: The matching method in NSImage is initWithCGImage:size: . The second argument takes the image's size in points. The factor between the size in pixels (of the CGImage)

MacOS and Swift 3 - how to pass result from one filter to another

强颜欢笑 提交于 2019-12-12 05:09:32
问题 Expanding question from this thread. I'm not sure how to pass the result from CIAffineClamp as a source for CIGaussianBlur . The following code builds just fine but does not yield a resulting image. guard let blurFilter = CIFilter(name: "CIGaussianBlur"), let clampFilter = CIFilter(name: "CIAffineClamp"), let imageURL = Bundle.main.url(forResource: "my-image", withExtension: "png"), let ciImage = CIImage(contentsOf: imageURL) else { return } let transform = AffineTransform.identity

Loading image to Image Cell from URL

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 04:48:46
问题 I'm learning to code in swift. I'm trying to load an image onto an image cell located within an image well.I'm using the following code import Cocoa class ViewController: NSViewController { @IBOutlet weak var well: NSImageCell! @IBAction func clickme(_ sender: Any) { let image = NSImage(byReferencing:NSURL(string: "http://imgsv.imaging.nikon.com/lineup/lens/zoom/normalzoom/af-s_dx_18-140mmf_35-56g_ed_vr/img/sample/sample1_l.jpg")! as URL) well.image=image; } override func viewDidLoad() {

How to resize - resample - change file size - NSImage

泪湿孤枕 提交于 2019-12-12 03:47:18
问题 I have made a lot of search on google, followed a lot of GitHub code, without success. I need to read a jpeg file, which have a DPI = 72, and size = 16000x1096 for example I need, then, to resize it, in order to save a jpeg file, with 72 DPI, 800x548 pixels this, under OSX, so I can use NSIMAGE, not UIImage ! I don't care if I lose some quality ! finally, after making som ma-ny tries, I put here my latest code, and require some help please : // get source image, jpeg, 1600x1196, 72 dpi let

How can i find the file type after loading NSImage withContentsOfFile

寵の児 提交于 2019-12-12 00:53:32
问题 I need to know which image file type was used in the file i loaded with "initWithContentsOfFie" because i don't want to trust the file extension. Unfortunately i can't find anything about the format in NSImage and NSImageRep, 回答1: NSImage doesn't keep that information, because it's of no further use. You'll need to drop down to CGImageSource to get the info you want. 来源: https://stackoverflow.com/questions/3590003/how-can-i-find-the-file-type-after-loading-nsimage-withcontentsoffile

How to retrieve the backing image for an `[NSCursor arrowCursor]` (say) as an `NSImage`

允我心安 提交于 2019-12-11 21:14:27
问题 The documentation for NSCursor doesn't seem to provide any way of retrieving the actual cursor images. Can anyone suggest a method? 来源: https://stackoverflow.com/questions/56304537/how-to-retrieve-the-backing-image-for-an-nscursor-arrowcursor-say-as-an-n

How to Convert PDF to NSImage and change the DPI?

徘徊边缘 提交于 2019-12-11 11:17:05
问题 I have tried to convert PDF Pages to NSImage and save to JPG files successfully. However the output result is as normal 72 DPI. I want to change the DPI to 300 DPI but failed. Below is the code: - (IBAction)TestButton:(id)sender { NSString* localDocuments = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0]; NSString* pdfPath = [localDocuments stringByAppendingPathComponent:@"1.pdf"]; NSData *pdfData = [NSData dataWithContentsOfFile:pdfPath];

Images being flipped when adding to NSAttributedString

微笑、不失礼 提交于 2019-12-11 05:58:27
问题 I have a strange problem when resizing an image that's in a NSAttributedString. The resizing extension is working fine, but when the image is added to the NSAttributedString, it gets flipped vertically for some reason. This is the resizing extension: extension NSImage { func resize(containerWidth: CGFloat) -> NSImage { var scale : CGFloat = 1.0 let currentWidth = self.size.width let currentHeight = self.size.height if currentWidth > containerWidth { scale = (containerWidth * 0.9) /

NSImage release() in AppleScriptObjC

◇◆丶佛笑我妖孽 提交于 2019-12-11 04:29:16
问题 I'm creating a Table View with small images displayed in each row. The data source holds an image for each row of an table. I create images thru set img to NSImage()'s alloc()'s initWithContentsOfFile_(thePath) . Next I display the image of selected row in bigger, browser view thru set imageView's image to img . Problem is that I'm running out of memory because I use the same representation for both views. (Images are around 500x400). I'm trying to figure out how to make a smaller version