Sha256: d99505909c3fb85cdd5fd9c4705b687dbe571cf924ca463c1e2778344c2bd0a9
Contents?: true
Size: 1.1 KB
Versions: 54
Compression:
Stored size: 1.1 KB
Contents
class NSImage # @return [NSData] an NSData object in an image file format. compression is # optional, and only supported on the JPEG formats 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 end
Version data entries
54 entries across 54 versions & 1 rubygems