Viewing DWG,DXF,HPGL,BMP and Gif's..

Posted on 1997-09-10
Last Modified: 2013-11-19
I'd like to be able to view DWG,DXF,HPGL,BMP and Gif's  by using one component, like the original TImage - Component. If there isn't any component with these capabilities, maybe I can manufacture one. The problem here is that I am not used to making my own components, however I guess it's not that hard once you've learned it. I'd like some suggestions on how to solve this problem, either by giving me a name on a component already existing, or give me a good way to start making my own component.

I looked at DR DWG, but it's way too expensive for me, besides, it doesn't handle all of the fileformats i'd like it to...

I run Delphi Developer 2.0...

Erik N.
Question by:Erik N
  • 3
  • 2

Expert Comment

ID: 1344549
For all this format you probably need own component, but for some of this format you can use component on the network.
Tell me if you can make new copmonent over TImage ?
If you can then probably you need know how to read DXF, Gif .... ?

Accepted Solution

ptiemann earned 60 total points
ID: 1344550
Hello Erik,
If really want to do this.. (read last paragraph in my reply!)
I'd take a look at \source\vcl\graphics.pas, class TPicture:

{ TPicture is a TGraphic container. It is used in place of a TGraphic if the graphic can be of any TGraphic class.

  LoadFromFile and SaveToFile are polymorphic. For example, if the TPicture is holding an Icon, you can LoadFromFile a bitmap file, where if the class was TIcon you could only read .ICO files. }

They dirty way would be to modify TPicture directly. You should derive some "TMyPicture" from TPicture and write your own "LoadFromFile" depending on the file format.

Now, here, why I WOULD NOT DO THIS:

- Delphi's way to handle palette conflicts in not very good. Palette problems occur, when you have a 256-color machine and display more than one picture with different palettes simultaneously. So you better work on the palette handling as well.

- Implementing image file formats can take you much time. DWG,DXF,HPGL,BMP and Gif's.. ? You're mixing vector and raster (BMP, GIF) formats.
I have implemented BMP, GIF, JPEG, PNG, TIFF, RLE .. 13 image file formats. All raster, BTW. Believe me, it's a lot of work.
Ok, if you stick with BMP and GIF of the raster formats, you took the 2 easiest ones.
I once found PD sources for .DWG which I temporarily integrated in my viewer. I don't want to discourage you, but you're going to spend some time on this..

Another idea:
With Word and other packages, there are those Import/ Export plugin filters that read/ write a file and deliver you a Windows DIB handle. They're really easy to work with, I added their usage to my graphics application too.
And there are import filters for the vector formats as well as for raster formats. Hm, the latest version of _Word_ missed GIF, I think. If you want to sell your application you need to think about the license situation. Most people have some office software installed, so they have those filters.

I don't know for what purposes you need it.. hope this is some useful input for you,

Author Comment

by:Erik N
ID: 1344551
To ptiemann..

It seems to be a little harder than I thought from the beginning...
What if I only view vector-formats? Is it easier then?
Maybe there is a component somewhere wich handle the formats Dwg,Dxf (and perhaps HPGL). I am not an expert-programmer so I may have to limit my demands a little.....

Erik N.

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.


Expert Comment

ID: 1344552
I could not find a viewer for DWG _and_ DXF because I didn't find the specification for one of the formats. The other one, I had found something from a third party. It could be that you need to experiment with sample files and detect yourself, how changing the file has influence on the resulting output file. That way you get to know the format. Have fun :-)

Since you said that you are not an expert programmer, I would strongly recommend to PURCHASE something for whatever you need. A easy file format like BMP - the easiest one! - takes more than one day, you have to deal with things like:

- memory allocation (bitmap is big, insufficient RAM)

- picture has 24 bits/pixel, graphic card has only 8 bpp. Just this stuff takes several thousands of lines of code, if you want to solve it.. hot buzz words are: "Color reduction" - how to display that needs 1Mio colors with 256 colors, methods to do so are: "Dithering" (I know 3 dither algorithms), "Heckbert quantisation" or just "nearest color" (looks ugly) etc.

- palette management (as said before, 2 pictures with conflicting palette entries want to be displayed simultanously - Windows has something built in for that, but ..)

- use a HBMP (faster for display) or the raw bits (allows you to manipulate easier)..? Best choice: keep the raw bits in memory and have a HBMP for a proxie. If you happen to come to this point, take a look at the DIB driver - it's a lot more reliable than the normal (HBMP) drivers. Yes, there's functions you better will not use because some graphic card manufacturers did a buggy job. I'm talking about "StretchBits" - whereas the matching DIB function works fine.

- BMP is harmless.. GIF files are compressed. But you'll find dozens of solutions for GIF already.. everybody seems to feel the need to code that once in his/ her live - me too. It's not exactly trivial, but well described. You may want to remember that there is some license problem for GIF files (actually: the LZW algorithm)- Unisys forces you to pay some fee. Better use the PNG format or at lease support both. I guess this is why Word doesn't have GIF any more in its list

==> unless you are a hobby programmer who doesn't care for his/ her leisure time - and in such a case it doesn't matter how slow, buggy or late the product is.. - invest some money and buy a ready solution.
I don't say this because I would sell - I don't. (Except my image database .. see "TrueBase")

Your subject is a perfect example where people can reuse code from a third party. As indicated, I personally implemented 13 image file formats wich took me together with the surrounding application about 3 years. Three years. 2 of them on the file formats, I'd say.
When I wanted to port the app to Win32, I decided to buy a library; I chose "ImageLib", which is $500. Certainly an expensive component, but it would have taken me more time than $500 is worth.

Don't waste your time! I'm sure your live is more interesting spending it other ways.

ImageLib does not support the vector formats, but I remember to have seen a component which does about 30 image file formats including vector formats. The name was like "Silver..".
In Germany, around 1994, it was like $850 for _one_ platform, e.g. Win32 or Unix. You also could get the sourcecode for about $2000.. but
(a) software is more expensive in Europe in general
(b) prices probably changed

If you don't sell your application very widely = you know, who is going to use it, try the Adobe Import filters which I mentioned in my first reply. Reliable, little coding and free.
I can help you with that.

Expert Comment

ID: 1344553
In my first sentence I meant:
"I could not WRITE a viewer for DWG _and_ DXF..."

Author Comment

by:Erik N
ID: 1344554
Thank you very much for your excellent answer ptiemann!!!
I won't try this, since it seems that I won't make it within a reasonable amount of time....

Erik N.

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
watermark on the graphic 9 81
Delphi IDE crash without error message ... 7 91
How to build JSON File in Delphi 6 3 34
DBCtrlGrid, Delphi, Scroll 8 14
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this Micro Tutorial viewers will learn the basic shortcuts and functions of Illustrator. The viewer will learn about the paintbrush tool, anchor points, font sizing, and more.
Learn the basics of inputting and editing your text components in Prezi. We will cover how to set styles, position, and group your text components. In your Prezi editor, click anywhere on the canvas to add text: A flashing cursor informs you that yo…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question