![]() |
【转帖】extract thumbnail to file
extract thumbnail to file
extract thumbnail to file the old opendwg kit had a call to pull the preview from a dwg into an outboard file. how do i accomplish this in dwgdirect? thanks in advance void oddbdatabase::writefile(odstreambuf* pfilebuff, oddb::savetype type, oddb: wgversion version, bool savethumbnailimage = false, int dxfprecision); you have to set the fourth parameter in writefile method to true to save the file preview. thanks much for the reply. i dont think i explained the question clearly. what i have is an open dwg, read only. what i want to do is locate the thumbnail bmp or wmf within it, and export that to an outboard bmp or wmf file, not a dwg file. or, at least get it into a data structure like odthumbnailimage so that i can then write that into a bmp/wmf file. thanks again for replying. so i have gotten a little further i now have the following; odthumbnailimage odimage; odstreambufptr sb = svcs.createfile(pname); oddbgetpreviewbitmap(sb, &odimage); sb.release; at this point, odimage.bmp.empty() = false, meaning i have gotten the bitmap into the structure. is there a call to write that data structure out to a bmp, or metafile? in the "old days", we had the call; adextractbmptofile(adhandle, outfile); which would locate the drawing's bmp, and write it to outfile in one call. couldnt there be something comparable in dwgdirect? check void cpreviewdib: rawpreview(hdc dc, int x, int y, int width, int height) method in odamfcapp example for reference thanks for the reply, sergey in fact, i have already looked there - the problem is, that code draws the bitmap, which i have no need to do. the tool i am working on does not render the dwg, it pulls attribute, xref, and thumbnails out in a batch run. the only interface it has is a dialog that says "working". this tool will pull data from tens of thousands of dwgs in one run. we are trying to keep our extraction to ten drawings a second - even this results in several hours of processing. what i want to do, is simply get the thumbnail out of the dwg into its own file.bmp, like adextractbmptofile() used to do. am i correct in believing that you think i want to draw the bmp, or, are you saying i will need to project it to get a windows handle to it, and then save it to file myself from there? if so, i would request the direct kit get the code from adextractbmptofile(), which worked great. thanks again for the reply! you can use oddbgetpreviewbitmap() function (declared in dbdatabase.h) to get oddbthumbnailimage object. its bmp member contains dib. to save bmp file you need to write bitmapfileheader to the file followed by contents of oddbthumbnailimage::bmp. sergey slezkin thanks sergey - "i got it!!" for anyone interested, here is the code which created a bmp that photoshop liked. if anyone has improvements, i'm listening. /////////////////////////////////////////////////////////////////////////////// int cdwgdirect::extractthumbnail(cstring &csoutfile) { int iret = 0; odthumbnailimage odimage; try { oddbgetpreviewbitmap(svcs.createfile( m_pdb->getfilename()), &odimage ); } catch(...) { return iret; } if (! odimage.hasbmp()) return iret; if( csoutfile.getlength() < 4 || stricmp(csoutfile.right(4), ".bmp") ) csoutfile += ".bmp"; bitmapinfoheader *pheader; pheader = (bitmapinfoheader *)(odimage.bmp.begin() ); if(!pheader) return iret; //found this algorythm in msdn int bisizeimage = ((((pheader->biwidth * pheader->bibitcount) + 31) & ~31) >> 3) * pheader->biheight; if(!bisizeimage) return iret; handle hf = createfile(csoutfile, generic_read | generic_write, (dword) 0, null, create_always, file_attribute_normal, (handle) null); if (hf == invalid_handle_value) return iret; //use num colors for offset to bits calculation int ncolors = 1 << pheader->bibitcount; // fill in the fields of the file header bitmapfileheader hdr; hdr.bftype = ((word) ('m' << 8) | 'b'); // is always "bm" hdr.bfsize = bisizeimage + sizeof( hdr );//globalsize (hdib) + sizeof( hdr ); hdr.bfreserved1 = 0; hdr.bfreserved2 = 0; hdr.bfoffbits = (dword) (sizeof( hdr ) + pheader->bisize + ncolors * sizeof(rgbquad)); // write the file header dword dwtmp; writefile(hf, (lpstr)&hdr, sizeof(hdr), (lpdword) &dwtmp, null); // write the dib header and the bits writefile(hf, (lpstr) pheader, odimage.bmp.length(), (lpdword) &dwtmp, null); iret = closehandle(hf); return(iret); } |
所有的时间均为北京时间。 现在的时间是 04:52 PM. |