Class: Sketchup::ImageRep

Inherits:
Object
  • Object
show all

Overview

References an image representation object.

Version:

  • SketchUp 2018

Instance Method Summary # collapse

Constructor Details

#initializeSketchup::ImageRep #initialize(filepath) ⇒ Sketchup::ImageRep

The #initialize method creates a new image object. The image object will have no data if a path to the image is not provided.

Examples:

Default constructor

image_rep = Sketchup::ImageRep.new

Construct from file

image_rep = Sketchup::ImageRep.new("/path/to/image.jpg")

Overloads:

Raises:

  • (ArgumentError)

    if the file path or image is invalid.

Version:

  • SketchUp 2018

Instance Method Details

#bits_per_pixelInteger

The #bits_per_pixel method gets the number of bits per pixel in the image.

Examples:

image_rep = Sketchup::ImageRep.new
image_rep.load_file("/path/to/image.jpg")
bpp = image_rep.bits_per_pixel

Returns:

  • (Integer)

Version:

  • SketchUp 2018

#color_at_uv(u, v, bilinear = false) ⇒ Sketchup::Color?

The #color_at_uv method returns a color corresponding to the UV texture coordinates

Examples:

image_rep = Sketchup::ImageRep.new
image_rep.load_file("/path/to/image.jpg")
color = image_rep.color_at_uv(0.7, 0.5, false)

Parameters:

  • u (Float)

    The U texture coordinate.

  • v (Float)

    The V texture coordinate.

  • bilinear (Boolean) (defaults to: false)

    Use bilinear texture filtering. This interpolates the colors instead of picking the nearest neighbor.

Returns:

Version:

  • SketchUp 2018

#colorsArray<Sketchup::Color>?

The #colors method returns an array of Color for each pixel in the image.

Examples:

image_rep = Sketchup::ImageRep.new
image_rep.load_file("/path/to/image.jpg")
colors = image_rep.colors

Returns:

Version:

  • SketchUp 2018

#dataString?

The #data method gets the pixel data for an image in a string of bytes.

Examples:

image_rep = Sketchup::ImageRep.new
image_rep.load_file("/path/to/image.jpg")
byte_string = image_rep.data
byte_string.each_byte { |byte| puts byte, ' ' }

Returns:

Version:

  • SketchUp 2018

#heightInteger

The #height method returns the height of an image.

Examples:

image_rep = Sketchup::ImageRep.new
image_rep.load_file("/path/to/image.jpg")
image_rep.height

Returns:

  • (Integer)

Version:

  • SketchUp 2018

#load_file(filepath) ⇒ Object

The #load_file method loads image data from the specified file.

Examples:

image_rep = Sketchup::ImageRep.new
image_rep.load_file("/path/to/image.jpg")

Parameters:

Raises:

  • (ArgumentError)

    if the filepath or image is invalid.

Version:

  • SketchUp 2018

#row_paddingInteger

The #row_padding method returns the size of the row padding of an image in bytes.

Examples:

image_rep = Sketchup::ImageRep.new
image_rep.load_file("/path/to/image.jpg")
image_rep.row_padding

Returns:

  • (Integer)

Version:

  • SketchUp 2018

#save_file(filepath) ⇒ Object

The #save_file method saves an image data object to an image file specified by a path.

Examples:

image_rep = Sketchup::ImageRep.new
image_rep.load_file("/path/to/image1.jpg")
# do stuff with the image representation
image_rep.save_file("/path/to/save/image2.jpg")

Parameters:

Version:

  • SketchUp 2018

#set_data(width, height, bits_per_pixel, row_padding, pixel_data) ⇒ Sketchup::ImageRep

Note:

The encoding of the pixel_data String parameter should be ASCII-8BIT. Any other encoding could corrupt the binary data.

The #set_data method sets the pixel data of the Sketchup::ImageRep.

Examples:

Setting new data

image_rep = Sketchup::ImageRep.new
image_rep.load_file("/path/to/image.jpg")
new_image_rep = image_rep.set_data(800, 600, 24, 0, pixel_data)

Parameters:

  • width (Integer)

    The width of the pixel data. Must be greater than 0.

  • height (Integer)

    The height of the pixel data. Must be greater than 0.

  • bits_per_pixel (Integer)

    The bits per pixel for the pixel data. Must be either 8/24/32.

  • row_padding (Integer)

    The row padding for the pixel data which is sized in bytes. Row padding is used to pad each row with zeros so that each scanline on the pixel data will end on the data-type boundry.

  • pixel_data (String)

    The binary string containing the pixel data representing the new image.

Returns:

Raises:

  • (ArgumentError)

    If width, height, bits_per_pixel or pixel_data are invalid.

  • (TypeError)

    If width, height, bits_per_pixel or pixel_data are wrong data types.

Version:

  • SketchUp 2018

#sizeInteger

The #size method gets the total size of the image data in bytes.

Examples:

image_rep = Sketchup::ImageRep.new
image_rep.load_file("/path/to/image.jpg")
data_size = image_rep.size

Returns:

  • (Integer)

Version:

  • SketchUp 2018

#widthInteger

The #width method returns the width of an image.

Examples:

image_rep = Sketchup::ImageRep.new
image_rep.load_file("/path/to/image.jpg")
image_rep.width

Returns:

  • (Integer)

Version:

  • SketchUp 2018