几何尺寸与公差论坛------致力于产品几何量公差标准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-04, 03:42 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】add embedded image to database

add embedded image to database
add embedded image to database
i'm not too experienced in dwgdirect, so maybe the solution of my problem is easy to find, but i've tried to look in the examples and the forum without luck...
i'm exporting components drawn in my vc++ mfc application to a dwg-file. lines and circles and so on works fine, but i just can't figure out how to export images (cimage in vc).
i've looked at the example dbfiller.cpp, and managed to export a linked image but i need to get it stored in the dwg. there is some code in dwfimport (w2dimport.cpp) that seems to do the right thing, but i can't get it to work with a cimage. i've tried to save the cimage to a istream, read the stream into a cbytearray and then use the addimage of w2dimport. not working... at least not for me...
please help me - and i'm afraid i need detailed instructions of how to do or where to look...
thanks
håkan
not too experiences in the dwg format either...
me again, just some additional info...
it is possible to store images embedded in the dwg-file?
my "w2dimport" attempt creates a new jpg image-file of my cimage and then links it to the exported dwg. i want to only get one file (the dwg). is it impossible? is it the jpg format that is the problem?
i have never worked with autocad (and i don't have it), i just use the free dwg viewer to check my results... so i don't really know how images are handled in autocad.
thanks
håkan
you can embed raster inside dwg using oddbole2frame entity.
you need to create an ole object in your application and make oddbole2frame from it.
but this will work only on windows. and not all viewers may support ole even on windows.
sergey slezkin
i don't really understand... is there any example that could be of any help to me? the oddbole2frame isn't self-explaining (at least not to me). too many unknowns...
i have one dwg-file, created in autocad, just containing one bitmap and it's represented as an acdbole2frame (according to odamfcapp), so it seems like this is the way to go.
if you don't have any specific example of the oddbole2frame, is there any other entity, handled in a similar way that would guide me?
thanks
håkan
setoleobject???
hi again,
i 've trying to figure out how to use the oddbole2frame all day. and i'm totally lost. if anyone have some sample code where a oddbole2frame is added to the database... i'd be very grateful.
i don't get how the object is supposed to be put into the oddbole2frame. to me it seems like the action to use is setoleobject, which i find in oddboleframe, but this line is green (in my editor - comments). making it less green by moving it outside the comment makes the compilation go fine but, of course, the program to crash.
my program looks like this now:
oddbole2frameptr pole;
cbytearray bytes;
...
hr = m_image.save(pstream, gdiplus::imageformatjpeg);
...
pstream->read(bytes.getdata(), m_nfilesize, &ibytesread);
colevariant v(bytes);
...
pole->setoleobject(v); // wish this one would work...
...
pspace->appendoddbentity(pole);
suppose it's not even close of the right way to do it... but how?
please help!!
håkan
here is sample code:
code:
oddbblocktablerecordptr pblock; // block to append ole to
oddbole2frameptr pole = oddbole2frame::createobject();
pole->setdatabasedefaults();
// set common entity's properties
pblock->appendoddbentity(pole);

odrectangle3d rec3d; // rectangle defining position
pole->setposition(rec3d);

// 1 for model space entity, 0 for ps
pole->setmodelflag( (pblock->objectid() == pdatabase->getmodelspaceid())
? 1
: 0);
// this part is application specific
hglobal hmem = ... // get the ole data
dword dwsize = ::globalsize(hmem);
byte * pdata = (byte*)::globallock(hmem);
odbytedataptr pbytes = pole->compdocfile(true); // get it for write
pbytes->writeat(0,pdata,dwsize);
// again application specific
::globalunlock(hmem);
::globalfree(hmem);
sergey slezkin
thank you, this works great, but i still have some problems...
if i open an image in ms paint, select it and copy it to the clipboard and then read the clipboard to create the ole object and insert it into the oddbole2frame (using your code sample), then everything is great... opening the dwg works just as expected.
however, when i try to create the ole object from within the application, nothing works...
which clipboard formats do i have to create?
when i look at the formats created by ms paint, i get
- embed source
- object descriptor
- cf_metafilepict
- cf_dib
but from my application, i haven't succeeded to create all of these, depending on the way of putting the information on the clipboard, i have managed to create embed source and object descriptor or cf_dib or cd_bitmap... and all i get when i open the is a blank screen and/or error messages (like "%1 already exists"). so i suppose i don't provide the information it needs...
which one (or all?) do i need to create to have an object that meets the specifications for a valid oddbole2frame?
thanks...
håkan
problem solved! finally... don't know how many hours... not a beautiful solution, but at least, it seems to work...
had to create a temporary file to make a valid dib and attach it to a coledatasource, get the lpdataobject, attach it to a coledataobject and finally create a coleclientitem by createstaticfromdata and put it on the clipboard. then read the clipboard and write it to the oddbole2frame... now autocad happily shows the embedded image...
there must be a much more efficient of doing this... hope there will be something in the samples in the coming versions?
thanks again! without your help i still would have been where i started.
håkan
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】database 不能作为字段? yang686526 ObjectARX(VB.NET/C#) 0 2009-04-20 10:58 AM
【转帖】database-resident entity与not database-resident entity有什么区别? yang686526 ObjectARX(C++) 0 2009-04-16 09:47 AM
【转帖】ghost image stays on screen after opening part, pull down me yang686526 SolidWorks二次开发 0 2009-04-13 11:05 AM


所有的时间均为北京时间。 现在的时间是 10:45 AM.


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