几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » DirectDWG
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-05-07, 05:04 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】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 ..
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】preview image 9thumbnail0 dont save in dwg 2004 yang686526 DirectDWG 0 2009-05-06 10:22 PM
【转帖】no lineweights on bmp-expor yang686526 DirectDWG 0 2009-05-06 06:34 PM
【转帖】nls error yang686526 DirectDWG 0 2009-05-06 06:34 PM
【转帖】error while exporting to dwg yang686526 DirectDWG 0 2009-05-05 09:48 AM
【转帖】[求助]请求编程,查询符合要求条件的dwg文件 yang686526 数据库ObjectDBX 0 2009-04-19 05:36 PM


所有的时间均为北京时间。 现在的时间是 01:12 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多