高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】his Is Code Of Dwg Preview For Vb .net . Please Tell Me Equ
this is code of dwg preview for vb .net . please tell me equ
this is code of dwg preview for vb .net . please tell me equivalent function in vc++
'example
'me.button1.image = dwgthumbnail.dwgpreviewasimage("c:\test.dwg")
public class dwgthumbnail
private structure bitmapfileheader
dim bftype as short
dim bfsize as integer
dim bfreserved1 as short
dim bfreserved2 as short
dim bfoffbits as integer
end structure
private structure bitmapinfoheader
dim bisize as integer
dim biwidth as integer
dim biheight as integer
dim biplanes as short
dim bibitcount as short
dim bicompression as integer
dim bisizeimage as integer
dim bixpelspermeter as integer
dim biypelspermeter as integer
dim biclrused as integer
dim biclrimportant as integer
end structure
private structure imgrec
dim byttype as byte
dim lngstart as integer
dim lnglen as integer
end structure
shared function dwgpreviewasimage(byval strfile as string) as system.drawing.image
dim bytcnt as byte
dim bytbmpbuff() as byte
dim lngfile as integer
dim lngseek as integer
dim bmpfheader as bitmapfileheader
dim udtheader as bitmapinfoheader
dim udtrec as imgrec
dim myimage as system.drawing.image
try
dwgpreviewasimage = nothing
if len(dir(strfile)) = 0 then exit function
lngfile = freefile()
fileopen(lngfile, strfile, openmode.binary)
seek(lngfile, 14)
fileget(lngfile, lngseek) 'lngseek is lngimgloc
fileget(lngfile, bytcnt, lngseek + 21)
if bytcnt <> 2 then exit function
lngseek = seek(lngfile)
fileget(lngfile, udtrec, lngseek + 9)
seek(lngfile, udtrec.lngstart + 1)
fileget(lngfile, udtheader)
'restricted to 8 bit bitmaps
if udtheader.bibitcount <> 8 then exit function
'note: bytbmpbuff contains entire file, less bmpfheader
redim bytbmpbuff(udtrec.lnglen)
'set bitmapfileheader values
bmpfheader.bfoffbits = udtrec.lnglen - udtheader.bisizeimage + 1
bmpfheader.bftype = 19778
seek(lngfile, udtrec.lngstart + 1)
fileget(lngfile, bytbmpbuff)
fileclose(lngfile)
lngfile = freefile()
'write image into memorystream
dim ms as new system.io.memorystream
dim w as new system.io.binarywriter(ms)
w.write(bmpfheader.bftype)
w.write(bmpfheader.bfsize)
w.write(bmpfheader.bfreserved1)
w.write(bmpfheader.bfreserved2)
w.write(bmpfheader.bfoffbits)
w.write(bytbmpbuff)
myimage = system.drawing.image.fromstream(ms)
w.close()
ms.close()
'return image
dwgpreviewasimage = myimage
exit function
catch ex as exception
msgbox(ex.tostring)
end try
end function
end class
here's something that works for me to extract the thumbnails from a dwg file with dwgdirect 2.1 and vc++...
lpbitmapinfo bminfo = null;
long bminfosize ;
odrdfilebuf sfile( fn );
odthumbnailimage odimage;
oddbgetpreviewbitmap(&sfile, &odimage );
if (odimage.hasbmp())
{
bminfo = (bitmapinfo *)malloc(odimage.bmp.length()*sizeof(byte));
memcpy(*bminfo, odimage.bmp.begin(), odimage.bmp.length());
bminfosize = (long)(odimage.bmp.length());
}
if(bminfo!= null)
{
bitmapinfoheader *lph = &(lpbi->bmiheader);
int ncolors = lph->biclrused ?
lph->biclrused :
1 << lph->bibitcount;
lpvoid lpdibbits;
if( lph->bibitcount > 8 )
lpdibbits = (lpvoid)((lpdword)(lpbi->bmicolors +
lph->biclrused) +
((lph->bicompression == bi_bitfields) ? 3 : 0));
else
lpdibbits = (lpvoid)(lpbi->bmicolors + ncolors);
cclientdc dc(null);
cpalette pal;
// create and select a logical palette if needed
if( ncolors <= 256 &&
dc.getdevicecaps(rastercaps) & rc_palette)
{
uint nsize = sizeof(logpalette) +
(sizeof(paletteentry) * ncolors);
logpalette *plp = (logpalette *) new byte[nsize];
plp->palversion = 0x300;
plp->palnumentries = ncolors;
for( int i=0; i < ncolors; i++)
{
plp->palpalentry[i].pered = lpbi->bmicolors[i].rgbred;
plp->palpalentry[i].pegreen = lpbi->bmicolors[i].rgbgreen;
plp->palpalentry[i].peblue = lpbi->bmicolors[i].rgbblue;
plp->palpalentry[i].peflags = 0;
}
pal.createpalette( plp );
delete[] plp;
// select and realize the palette
(void)dc.selectpalette( &pal, false );
dc.realizepalette();
}
lph->bisize = sizeof(bitmapinfoheader);
hbitmap hbm = createdibitmap(
dc.getsafehdc(), // handle to device context
lph, // pointer to bitmap info header
(long)cbm_init, // initialization flag
lpdibbits, // pointer to initialization data
lpbi, // pointer to bitmap info
dib_rgb_colors ); // color-data usage
thank you
thank you pete .. my code is working now ..
|