高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】support For Non-bmp Images In Dwf Files
support for non-bmp images in dwf files
support for non-bmp images in dwf files
i am trying to raster jpg image embedded in .dwf file. the dwfimagemanager sends in odmemorystream to exrastermodule::loadrasterimage(odstreambuf *pbuf). the function handles images with type = 19778 (!!!)(.bmp). but i couldn't load jpg image. what is this type number for and how do i handle other formats. i can successfully export .dwf to .dwg and load the jpg images since .dwg module sends in the filename to exrastermodule::loadrasterimage(const odstring &filename) and it handles all image formats. is there anyway i can do similar with .dwf module or is there any otherway to interpret the odmemorystream buffer to handle file formats other than .bmp
thanks.
first, i agree that "type = 19778 " is not graceful way to check if first 2 bytes are "bm" sequence starting bitmap file.
raster services are placed to examples folder and are available as source code because handling all possible raster formats is enomous job and most developers have some 3-d party raster library available.
loadrasterimage(filename) has implementation using jpeg-6b and snowbound libraries.
lt was possible to implement loadrasterimage(odstreambuf) creating a temporary file and calling filename version but some raster libraries may have more efficient way to do it via call-back functions reading the data for example.
also we'll check if dwfimport realy needs to load raster file as gi image. probably it would be possible to create a raster file, imagedef and image entity without parsing the raster data.
sergey slezkin
data format for odstreambuf in loadrasterimage(odstreambuf)
first of all, thank you very much for prompt reply.
is there anyway to find out type of image the odstreambuf in loadrasterimage(odstreambuf) is referring to, so that i can load and use right library to display the image? or any other way around to display images other than bmp?
thanks
inside loadrasterimage(odstreambuf) where is no additional information on image format. usually first characters in the stream indicate it.
dwf import before calling loadrasterimage(odstreambuf) has this information.
i want to check if it's possible simply save the image file (contents of odstreambuf) without parsing it by raster services.
sergey slezkin
sergey,
did you determine if "it's possible simply save the image file (contents of odstreambuf) without parsing it by raster services." i'm curious about this too...
tyler
dwf import uses raster services to load image for immediate display only. having gi image loaded or not, does not affect file contents. if user raster services do not support given image type, import works just as if there were no raster services. that is - the image will be saved and inserted in dwg, but, naturally, it will not be rendered by the importing application.
if you need not to display the image right away, you may unload raster services module and the image will be saved and inserted in dwg, without parsing. or you can just return null pointer for unknown raster type from your raster services module.
raster type is usually determined by first bytes (signature) of the file.
vladimir
last edited by vkalinin; 29th june 2005 at 07:49 amfff">.
hi,
here is what i did to make it simple and see whats in the odstreambuf:
code:
odgirasterimageptr exrastermodule::loadrasterimage(odstreambuf *pbuf)
{
cfile tempfile("tmp.jpg", cfile::modecreate | cfile::modereadwrite | cfile::typebinary);
tempfile.write(pbuf, pbuf->length());
tempfile.close();
}
included image is a .jpg image, the sample file() is attached.
when i try to open the saved jpeg file using image editor, it can not open that file.
attached files (358.2 kb, 9 views)
one side note to be added in above post:
converting the dwf to dwg and then, from dwg saving jpg file and opening it with image editor works.
quote:
originally posted by jaisam
hi,
here is what i did to make it simple and see whats in the odstreambuf:
code:
odgirasterimageptr exrastermodule::loadrasterimage(odstreambuf *pbuf)
{
cfile tempfile("tmp.jpg", cfile::modecreate | cfile::modereadwrite | cfile::typebinary);
tempfile.write(pbuf, pbuf->length());
tempfile.close();
}
included image is a .jpg image, the sample file() is attached.
when i try to open the saved jpeg file using image editor, it can not open that file.
that is strange, to say the least. what is the image length in both cases?
vladimir
in both cases the buffer length read from file is 188900 bytes.
could you please attach the image saved by your raster services?
vladimir
images
required images are attached. remove .txt extension from dwf_saved filename. the forum identifies it as invalid jpg and wouldn't allow me to attach.
attached images (184.5 kb, 9 views)
attached files (184.5 kb, 4 views)
is there any updates on this issue? or any suggested fixes to get the correct image file from .dwf?
thanks.
i checked that dwfimport creates image files and references to them in dwg correctly even if raster services are unable to load the raster image (or if where is no raster services at all.) so you need not implement them. i checked this in odamfcapp sample.
note that .jpg file is written not at import moment but at the same time you write .dwg file.
the jpg you saved obviously is not a jpeg file. i think that in your code odstreambuf * pbuf is simply casted to char* and you write to file not stream contents but a piece of memory starting at the begining of odstreambuf object.
to get stream contents you need to call getbytes().
sergey slezkin
|