How to export a image from a component by ruby

Hi there,
When i choose a image component, then click Edit->image(1 in model)-> export, I can export a image entity as its source file.

First question: Is there any way to do this by ruby? I only find a function View.write_image in API document. But seems like it doesn’t do what I want.

Second question: Is there any way to make this image component encode to BASE64? So that I can post it to a Webdialog as a parameter. Or just, if I can print this image on a Webdialog with some others methods?

Thanks for your help, and sorry for broken English
Weinan

An image entity is a special type of component (that consists of 4 edges and a rectangular textured face). Its material is hidden from the materials list, but it has a material object.

TextureWriter can write textures of faces, but also groups and images. To avoid that perspective transformations are baked into the exported image, most developers apply the material to a temporary empty group. But this should not be necessary here because images in SketchUp have usually no perspective transformation (they are rectangular).

For me this worked:

tw = Sketchup.create_texture_writer
tw.load(image_entity, true)
tw.write(image_entity, filepath)

This returns a status (0 for success).

In case you want to access the material object directly:
face = image_entity.definition.entities.grep(Sketchup::Face).first material = face.material

SketchUp’s API currently only allows to write image to the file system, not to retrieve (or manipulate) the pixel data in memory. So you would export the image to a temporary folder, and then pass this path to the webdialog.

Thanks for the information, these would be very helpful