Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Image can show preview-image in dwg file (autocad file name) Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
02-Jun-03
Category
VCL-General
Language
Delphi 2.x
Views
113
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: devuser devuser 

I have writen a component from image which can show the preview-image in dwg file

Answer:

1   unit DWGView;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7     ExtCtrls;
8   
9   type
10    BITMAPINFO256 = record
11      bmiHeader: BITMAPINFOHEADER;
12      bmiColors: array[0..255] of RGBQUAD;
13    end;
14  
15  type
16    TNoPreviewEvent = procedure(Sender: TOBject) of object;
17    TFileErrorEvent = procedure(Sender: TOBject; DWGName: string) of object;
18  
19    TDWGView = class(TImage)
20    private
21      FDWGVersion: string;
22      FDWGFile: string;
23      FNoPreviewEvent: TNoPreviewEvent;
24      FOnFileError: TFileErrorEvent;
25      FImage: TImage;
26      procedure SetDWGFile(const Value: string);
27      procedure SetFImage(const Value: TImage);
28      { Private declarations }
29    protected
30      procedure ReadDWG;
31      constructor TDWGView;
32      { Protected declarations }
33    public
34      { Public declarations }
35    published
36      { Published declarations }
37      property Image: TImage read FImage write SetFImage;
38  
39      property DWGFile: string read FDWGFile write SetDWGFile;
40      property DWGVersion: string read FDWGVersion;
41      property OnNoPreview: TNoPreviewEvent read FNoPreviewEvent write 
42  FNoPreviewEvent;
43      property OnFileError: TFileErrorEvent read FOnFileError write FOnFileError;
44    end;
45  
46  procedure register;
47  
48  implementation
49  
50  procedure register;
51  begin
52    RegisterComponents('Voice', [TDWGView]);
53  end;
54  
55  procedure TDWGView.ReadDWG;
56  var
57    DWGF: TFileStream; // ?¼???ļ?
58    MemF: TMemoryStream; // ??¾????ö?é
59    BMPF: TMemoryStream; // ?»?¼?ļ?
60    SentinelF: TMemoryStream; //?¨Õ÷×Ö¶?  16×Ö½?
61  
62    bif: BITMAPINFO256; // ?»?¼?ļ??Å?¢
63    bfh: BITMAPFILEHEADER; // ?»?¼?ļ??ļ??· 14×Ö½?
64  
65    PosSentinel: LongInt; // ?¨Õ÷×Ö¶??»Ö?
66  
67    LenPreview: Integer; // ³??¨Õ÷×Ö¶?Ö®??Õ?�ö?¤???¼¯¬??¾?µÄ³¤¶?
68    RasterPreview: ShortInt; // ?µ?÷?¤???¼¯¬????µÄ?»�öµ?×Ö½?Õ???
69    // 0  ²»±£???¤???¼¯¬ 1  ±£??BMP?¼¯¬
70      // 2  ±£??WMF?¼¯¬    3  ?¬?±±£??BMP??WMF?¼¯¬
71    PosBMP: Integer; // ?¼¯¬µÄÕ¿?µ?»Ö?£¬²»?»¶�???»?¼
72    LenBMP: Integer; // ?¼¯¬³¤¶?£¬²»?¬BITMAPFILEHEADER??¾?£¬²»?»¶�???»?¼
73    IndexPreview: Integer;
74    TypePreview: Shortint; // ?¼¯¬????
75  begin
76    if Assigned(FOnFileError) then
77      FOnFileError(Self, FDWGFile);
78    DWGF := TFileStream.Create(FDWGFile, fmOpenRead);
79    BMPF := TMemoryStream.Create;
80    MemF := TMemoryStream.Create;
81    SentinelF := TMemoryStream.Create;
82    try
83      SetLength(FDWGVersion, 6);
84      DWGF.ReadBuffer(FDWGVersion[1], 6);
85      DWGF.Position := 13; // ?ļ?¯??¼13´¦Ö�???¨Õ÷×Ö¶?
86      DWGF.read(PosSentinel, 4);
87      DWGF.Position := PosSentinel;
88      SentinelF.CopyFrom(DWGF, 16); // ¶????¨Õ÷×Ö¶?
89      DWGF.read(LenPreview, 4); // ¶???
90      DWGF.read(RasterPreview, 1); // ¶????¼¯¬????
91      for IndexPreview := RasterPreview - 1 downto 0 do
92      begin
93        MemF.Position := 0;
94        MemF.CopyFrom(DWGF, 9); // ?¼¯¬???ö?é 9×Ö½?
95        MemF.Position := 0;
96        MemF.read(TypePreview, 1); // TypePreview ?¼¯¬????
97        case TypePreview of
98          1: ; // ?¼??µÄ???öÄ???
99          2:
100           begin
101             // BMP?¼¯¬,??DWG?ļ?Ö?±£´¿µÄBMP?¼¯¬?É????????×?BMP¹¿·¶µÄ
102             // ?¼?ó?ļ???¾?£¬µ«??²»±£´¿BITMAPFILEHEADER??¾?
103             MemF.Position := 1;
104             MemF.read(PosBMP, 4); // 2,5
105             MemF.read(LenBMP, 4); // 6,9
106             DWGF.Position := PosBMP;
107             DWGF.ReadBuffer(bif, sizeof(bif));
108 
109             with bif do
110             begin
111               bmiColors[0].rgbBlue := 0;
112               bmiColors[0].rgbGreen := 0;
113               bmiColors[0].rgbRed := 0;
114 
115               bmiColors[225].rgbBlue := 255;
116               bmiColors[225].rgbGreen := 255;
117               bmiColors[225].rgbRed := 255;
118             end;
119 
120             bfh.bfType := $4D42;
121             bfh.bfSize := LenBMP + sizeof(bfh); //
122             bfh.bfReserved1 := 0;
123             bfh.bfReserved2 := 0;
124             bfh.bfOffBits := 14 + $28 + 1024;
125 
126             BMPF.Position := 0;
127             BMPF.write(bfh, sizeof(bfh));
128             BMPF.WriteBuffer(bif, sizeof(bif));
129             BMPF.CopyFrom(DWGF, LenBMP - 1064);
130             BMPF.Position := 0;
131             Picture.Bitmap.LoadFromStream(BMPF);
132           end;
133         3: ; // WMF?ļ?£¬?ü´¸Ó?22×Ö½?³¤µÄAldus?ļ??·
134       end;
135 
136     end;
137   finally
138     SentinelF.Free;
139     MemF.Free;
140     DWGF.Free;
141     BMPF.Free;
142   end;
143 
144 end;
145 
146 procedure TDWGView.SetDWGFile(const Value: string);
147 begin
148   FDWGFile := Value;
149   ReadDWG;
150 end;
151 
152 procedure TDWGView.SetFImage(const Value: TImage);
153 begin
154   FImage := Value;
155 end;
156 
157 constructor TDWGView.TDWGView;
158 begin
159   //TODO: Add your source code here
160   FDWGFile := '';
161   FDWGVersion := '';
162 end;
163 
164 end.



			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC