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

Version Path
sugarcube-4.0.0 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.5.0 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.4.2 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.4.1 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.4.0 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.3.7 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.3.6 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.3.5 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.3.4 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.3.3 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.3.2 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.3.1 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.3.0 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.2.0 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.1.1 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.1.0 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.0.8 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.0.7 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.0.6 lib/osx/sugarcube-nsdata/nsimage.rb
sugarcube-3.0.5 lib/osx/sugarcube-nsdata/nsimage.rb