Menu
  • HOME
  • TAGS

Memory leaks while using NSReadPixel in a cycle

objective-c,xcode,nsimage

Calling -lockFocus causes a snapshot of the image to be made. It's not something to be done lightly. Move the locking and unlocking of focus outside of the tight loop and you should be fine. Alternately, you could work out another way to read pixel data out of images. Unfortunately,...

When using UIImageJPEGRepresentation what number retains full resolution?

ios,uiimage,nsimage,uiimagejpegrepresentation

About scale The quality of the resulting JPEG image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). ...

Errors with CIFilter and Swift 2: '_' is not convertible to 'String' + Type of expression is ambiguous without more context

swift,cocoa,core-image,nsimage,swift2

extension NSImage { func gaussianBlurOfRadius(radius: CGFloat) -> NSImage { let image = self image.lockFocus() let beginImage = CIImage(data: image.TIFFRepresentation!)! let params = [kCIInputImageKey : beginImage, kCIInputRadiusKey: radius] let filter = CIFilter(name: "CIGaussianBlur", withInputParameters: params)! let output = filter.valueForKey("outputImage") as! CIImage let rect = NSMakeRect(0, 0, size.width, size.height) output.drawInRect(rect, fromRect: rect,...

Get NSRunningApplication's icon with an other size

ios,objective-c,osx,uiimage,nsimage

the icon you get back is a NSImage that has ITS size set to 32x32. Means that if you draw it now, it will choose an appropriate NSImageRepresentation. From the Log you can see it has many different ones - they are the perse data so all you need to...

In Cocoa how to scale a NSImage with no transparency

cocoa,transparency,nsimage,alpha-transparency

I found a solution... I changed the representationUsingType... I used JPEGFileType so the image has no transparencies at all... here the changed code: NSData *dataToWrite = [rep representationUsingType:NSJPEGFileType properties:nil]; ...

Creating NSImage from CGImageRef causes image pixel size to double

objective-c,cocoa,nsimage,cgimageref

The documentation for initWithCGImage:size: states: You should not assume anything about the image, other than that drawing it is equivalent to drawing the CGImage. In the end I just continued on working with NSBitmapImageRep instances directly....

Using image libraries for Mac OS X apps in Swift

xcode,osx,swift,nsimage

In this situation, you can use NSImage just like UIImage: NSImage(named: "Something") ...

AFNetworking 2 - Image upload - Request failed: unsupported media type (415)

objective-c,osx,afnetworking-2,nsimage

With the support of Mattijs from TinyPNG I've got it working! Thanks Mattijs! The problem was, that the TinyPNG API expects the request body to only be the image data, which isn't the case with the multipart form data body I used in my original code. My working solution is:...

Typecast NSImage to Any and downcast it back to NSImage

swift,casting,nsimage,any

Phew, this manages to pack many different issues into a tiny amount of code :-) This explanation is long so you might find you know the first part of it but may as well start at the beginning... NSImage(byReferencingFile) is what’s called a “failable initializer” – that is, an initializer...

How to Convert PDF to NSImage and change the DPI?

ios,xcode,osx,pdf,nsimage

Since OS X 10.8, NSImage has a block based initialiser to draw vector based content into a bitmap. The idea is to provide a drawing handler that is called whenever a representation of the image is requested. The relation between points and pixels is expressed by passing a NSSize (in...

App reply not called when passing non-null parameter from NSXPCConnection

osx,nsimage,xpc,nsxpcconnection

It appears that all objects passed via the connection must conform to the NSSecureCoding protocol, which NSImage does not conform to. NSData does conform to this protocol, and now I am passing it through the connection (not sure why it didn't work when I tried NSData earlier). I am creating...

How to scale from CVImageBufferRef — or — why didn't setPixelBufferAttributes work?

objective-c,cocoa,core-graphics,nsimage,quartz-core

It seems that setPixelBufferAttributes was ignored on the first request so in the callback when the image is received from the camera I check the size and issue the request again if not correct. This seems to have fixed the issue.

Getting a CGContextRef from an NSImage (without using the deprecated graphicsPort)

osx,core-graphics,nsimage

Looks like a bug. File it with Apple and then just go on using the deprecated method. Deprecated doesn't mean unavailable or "don't dare use this". It means it should be avoided in new code where possible and you should considered yourself warned that it may eventually go away....

Drawing artifacts when drawing a NSString in a NSButton

cocoa,nsstring,drawrect,nsimage,nsbutton

Try drawing the image into [self bounds] rather than into dirtyRect. Drawing the string probably dirties part of your button, causing your code to draw the image into that dirtyRect....

Setting the NSImage of a NSImageView from a NSURL

objective-c,osx,cocoa,nsimage,nsimageview

Okay, so I feel stupid now. I'm still learning stuff so I wasn't sure why it was freezing up until I noticed Xcode kept switching to the "Debug" panel, which clued me into what might be happening. I figured out I accidentally clicked a line number, which apparently sets breakpoints...

Proportionally scale and rotate NSImage for drawInRect

objective-c,cocoa,nsview,drawrect,nsimage

Short Version Add: imageRect.origin.x += NSWidth(drawRect) / 2 - NSHeight(drawRect) / 2; imageRect.origin.y += NSHeight(drawRect) / 2 - NSWidth(drawRect) / 2; after the call to proportionallyScale in drawRect Long Version I took this in two steps: bounding and scaling the image, and then repositioning it within viewport. You can probably...

Using NSAffineTransform to rotate NSImage results in a file twice the size

objective-c,cocoa,nsimage,image-rotation,nsaffinetransform

I still don't know the root cause of this, but one work around is to save to the JPEG representation instead of the TIFF. The method I wrote is as follows : - (void)CompressAndSaveImg:(NSImage *)img ToDiskAt:(NSString *)path WithCompressionFactor:(float)value{ NSData *imgData = [img TIFFRepresentation]; NSBitmapImageRep *imgRep = [NSBitmapImageRep imageRepWithData:imgData]; NSNumber *compressionFactor...

Is there any way to Convert NSView Contain Subviews into NSImage?

objective-c,cocoa,nsview,nsimage

I am able to solve my problem with the following Code // Setup the image to render NSRect imgRect = _collageView.frame; NSSize imgSize = imgRect.size; NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:imgSize.width pixelsHigh:imgSize.height bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bitmapFormat:NSAlphaFirstBitmapFormat bytesPerRow:0 bitsPerPixel:0]; NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithBitmapImageRep:rep];...

How do I draw NSGradient to NSImage?

osx,rubymotion,nsimage,nsgradient

I don’t know about RubyMotion, but here’s how to do it in Objective-C: NSGradient *grad = [[NSGradient alloc] initWithStartingColor:[NSColor redColor] endingColor:[NSColor blueColor]]; NSRect rect = CGRectMake(0.0, 0.0, 50.0, 50.0); NSImage *image = [[NSImage alloc] initWithSize:rect.size]; NSBezierPath *path = [NSBezierPath bezierPathWithRect:rect]; [image lockFocus]; [grad drawInBezierPath:path angle:0.0]; NSBitmapImageRep *imgRep = [[NSBitmapImageRep alloc]...