Class: NSImage
- Defined in:
- lib/osx/sugarcube-color/nsimage.rb,
lib/osx/sugarcube-nsdata/nsimage.rb
Instance Method Summary collapse
- #cgcolor(alpha = nil) ⇒ Object
- #nscolor(alpha = nil) ⇒ NSColor
-
#nsdata(format = :png, compression = 0.9) ⇒ NSData
optional, and only supported on the JPEG formats.
- #skcolor(alpha = nil) ⇒ Object
Instance Method Details
#cgcolor(alpha = nil) ⇒ Object
13 14 15 |
# File 'lib/osx/sugarcube-color/nsimage.rb', line 13 def cgcolor(alpha=nil) nscolor(alpha).CGColor end |
#nscolor(alpha = nil) ⇒ NSColor
4 5 6 7 8 9 10 11 |
# File 'lib/osx/sugarcube-color/nsimage.rb', line 4 def nscolor(alpha=nil) color = NSColor.colorWithPatternImage(self) if not alpha.nil? color = color.colorWithAlphaComponent(alpha.to_f) end color end |
#nsdata(format = :png, compression = 0.9) ⇒ NSData
optional, and only supported on the JPEG formats
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/osx/sugarcube-nsdata/nsimage.rb', line 5 def nsdata(format=:png, compression=0.9) self.lockFocus bitmap_rep = NSBitmapImageRep.alloc.initWithFocusedViewRect(NSMakeRect(0, 0, self.size.width, self.size.height)) self.unlockFocus case format when :png, :PNG return bitmap_rep.representationUsingType(NSPNGFileType, properties: nil) when :jpg, :jpeg, :JPG, :JPEG return bitmap_rep.representationUsingType(NSJPEGFileType, properties: { NSImageCompressionFactor => compression }) when :jpg2000, :jpeg2000, :JPG2000, :JPEG2000 return bitmap_rep.representationUsingType(NSJPEG2000FileType, properties: { NSImageCompressionFactor => compression }) when :tif, :tiff, :TIF, :TIFF return bitmap_rep.representationUsingType(NSTIFFFileType, properties: nil) when :gif, :GIF return bitmap_rep.representationUsingType(NSGIFFileType, properties: nil) when :bmp, :BMP return bitmap_rep.representationUsingType(NSBMPFileType, properties: nil) end end |
#skcolor(alpha = nil) ⇒ Object
17 18 19 |
# File 'lib/osx/sugarcube-color/nsimage.rb', line 17 def skcolor(alpha=nil) nscolor(alpha) end |