FHannes Posted February 10, 2012 Share Posted February 10, 2012 (edited) In SCAR Divi 3.31 I've made a small change to the encoding for bitmaps so it can very easily be encoded or decoded outside of SCAR. The 'c' type bitmap encoding is set up by converting every pixel of the bitmap row-by-row into a RGB values and suing those in the same sequence as ANSI encoded characters to build a string formatted as 'RGBRGBRGB...', after this the string is compressed with the ZLib compression library and encoded in Base64. Finally 'c' is appended to the front of the string to indicate the encoding type. Here an example of how a bitmap is manually decoded in SCAR (you need SCAR Divi 3.31): [scar]var Bmp, Bmp2, W, H, I, Color: Integer; Str, Tmp: AnsiString; begin try // Load bitmap Bmp := BitmapFromString(19, 16, 'ceNplkwmWojAURd1Tb6HW0lvotfQW3EKBIKgoEAI' + 'IKFOCyiDI4A7sH1JSnOp33mH8l4Sfl/WxWDPnsptLznWyDHZv8Fw5lhu/2p3uWvjQ4w6lg' + '0XBT3j1ZZexsnMDLxYL2b3CE+WYq165DUrtVB+ixkg6iwx29gTzSrA0ejHq9ZufR5yxxS6' + 'o9iGArUV7Oxvcy7DC2WSOzA2S7GztXDderp0rI24w6W06ONkgmKlgEgFRARE+ivnrmwKJK' + 'JUsojiXrV/oUW0lrU06h/afRjI65WXv8nHCrxccBT0UUSzbZHO8HU6lGdeYAPvgIB8IPLF' + 'wPX1ENELZYjVaUBhhjZIGpw1MlRdzc/b/OfOj5ud6dEdJDaBosZ78eWvCp/p5o0AGB5OGr' + '9rHW3N8AudrZEQ1gt6mD8Ut4Ha5XH7MxPHvLgH+d/TI4pQ1R/Eq1at4wRzn4A+EC9PWoR0' + 'HVb/a+Pc5zsHpZ7/albSYJaeHdWQJ9wrFKxW/BFx94z+0jx6QNzPtMYWsDjbtV/gi2Syls' + 'BdYyFngYbOUkG01qLZBvT3Xu3Ozj9tD0plsazwxmAyfEDnEIieiDJaGhda+rJzb2snZTMZ' + 'fABD21CFu9bRH9GllgPf/ABzKAUs='); // Convert the bitmap back to a string ^^^ Str := BitmapToString(Bmp); // Get the dimensions of the bitmap GetBitmapSize(Bmp, W, H); finally // Free the original bitmap FreeBitmap(Bmp); end; // Create a new bitmap with the dimensions of the original Bmp2 := BitmapFromString(W, H, ''); try // Check the bitmap prefix (This is an indicator for the bitmap string format) if Str[1] = 'c' then begin // Decode and decompress the bitmap with the prefix removed Str := ZLibDecompress(Base64ToStr(Copy(Str, 2, Length(Str) - 1))); // Loop through all pixels which are stored in the string as RGBRGBRGB... for I := 0 to Length(Str) div 3 - 1 do begin // Get the RGB characters for the current pixel Tmp := Copy(Str, I * 3 + 1, 3); // Convert the RGB characters to a color Color := RGBToColor(Byte(Tmp[1]), Byte(Tmp[2]), Byte(Tmp[3])); // Calculate the coordinates of the color on the bitmap and color the pixel FastSetPixel(Bmp2, I mod W, I div W, Color); end; // Show the new bitmap DebugBitmap(Bmp2); end; finally // Free the new bitmap FreeBitmap(Bmp2); end; end.[/scar] This insight should make it easier for people to for example encode bitmaps in PHP or other languages which can then be used in SCAR. Edited February 10, 2012 by Freddy Quote Link to comment Share on other sites More sharing options...