1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
AnsiString BitmapToRTF(Graphics::TBitmap *pict)
{
Cardinal bis, bbs, I;
AnsiString bi, bb, hexpict, achar;
AnsiString rtf = "{\\rtf1 {\\pict\\dibitmap ";
//On récupère la taille du header & la taille de l'image
GetDIBSizes(pict->Handle, bis, bbs);
bi.SetLength(bis);
bb.SetLength(bbs);
//On stocke les infos header et data respectivement dans des char tab bi & bb
GetDIB(pict->Handle, pict->Palette, &((bi.c_str())[0]), &((bb.c_str())[0]));
hexpict.SetLength((bi.Length() + bb.Length()) * 2);
I = 1;
for (bis = 0; bis < bi.Length(); bis++) //Partie header du bmp
{
achar = IntToHex((int)((bi.c_str())[bis]), 2);
const int SizeHexa = achar.Length();
if (SizeHexa == 1)
achar = "0" + achar;
else //On a affaire à des puissances de 2
{
(hexpict.c_str())[I-1] = (achar.c_str())[SizeHexa -2];
(hexpict.c_str())[I] = (achar.c_str())[SizeHexa -1];
}
I += 2;
}
for (bbs = 0; bbs < bb.Length(); bbs++) //Partie "data" du bmp
{
achar = IntToHex((int)((bb.c_str())[bbs]), 2);
const int SizeHexa = achar.Length();
if (SizeHexa == 1)
achar = "0" + achar;
else //On a affaire à des puissances de 2
{
(hexpict.c_str())[I-1] = (achar.c_str())[SizeHexa -2];
(hexpict.c_str())[I] = (achar.c_str())[SizeHexa -1];
}
I += 2;
}
return (rtf + hexpict + " }}");
} //BitmapToRTF() |