Why is ImageRep data different from File.binread?

I am a bit inexperienced. But I want to know why ImageRep.data is different than File.binread?
How can I get the same data as File.binread from ImageRep?

image_rep = Sketchup::ImageRep.new;
p= 'C:\Users\Ajay\Desktop\test.png';
x = image_rep.data;
y = File.binread(p);

Because ImageRep data is not in PNG data format. Nor is it in JPG format.

The documentation for the C API has more explanation in SketchUp C API: SUColorOrder Struct Reference, …

A simple struct with four indices indicating the ordering of color data within 32-bit bitmap images. 32-bit bitmap images have 4 channels per pixel: red, green, blue, and alpha where the alpha channel indicates the transparency of the pixel. SketchUpAPI expects the channels to be in different orders on Windows vs. Mac OS. Bitmap data is exposed in BGRA and RGBA byte orders on Windows and Mac OS, respectively. The color order indices facilitate platform independent code when it is necessary to manipulate image pixel data. The struct’s data also applies to 24-bit bitmap images except that such images don’t have an alpha channel so the SUColorOrder::alpha_index variable can be ignored.

… so, the internal format used by SketchUp is a bitmap.

Pay attention to the differing byte order for the 2 platforms.

1 Like

You don’t, the fileformat is not something that ImageRep deals with. If you want the raw compressed bytes of the fileformat you need to stick to File.binread.