高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】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
|