CheckSum |
尚未結案
|
笨男人
一般會員 發表:4 回覆:3 積分:1 註冊:2004-02-20 發送簡訊給我 |
|
StrongLemon
高階會員 發表:10 回覆:166 積分:105 註冊:2004-04-18 發送簡訊給我 |
用TFileStream操作吧
1.TFileStream.Create
constructor Create(const FileName: string; Mode: Word); overload;
constructor Create(const FileName: string; Mode: Word; Rights: Cardinal); 2.位置操作for I:=0 to Size
property Position: Int64;
property Size: Int64; 3.讀寫
function Read(var Buffer; Count: Longint): Longint; override;
function Write(const Buffer; Count: Longint): Longint; override; 4.搜尋
function Seek(Offset: Longint; Origin: Word): Longint; overload; virtual;
function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; override; 5.轉換,寫個Function ByteToInt 別人寫的範例"請問如何存取binary檔 "
http://delphi.ktop.com.tw/topic.php?topic_id=36778 發表人 - StrongLemon 於 2004/05/21 10:52:27
|
笨男人
一般會員 發表:4 回覆:3 積分:1 註冊:2004-02-20 發送簡訊給我 |
感謝StrongLemon的回答
我看了您所連結的範例程式,真是不好意思,我試了好久還是試不出來
不知道可否再提供一個範例讓我試試看呢?謝謝您了! 笨男人
引言: 用TFileStream操作吧 1.TFileStream.Create constructor Create(const FileName: string; Mode: Word); overload; constructor Create(const FileName: string; Mode: Word; Rights: Cardinal); 2.位置操作for I:=0 to Size property Position: Int64; property Size: Int64; 3.讀寫 function Read(var Buffer; Count: Longint): Longint; override; function Write(const Buffer; Count: Longint): Longint; override; 4.搜尋 function Seek(Offset: Longint; Origin: Word): Longint; overload; virtual; function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; override; 5.轉換,寫個Function ByteToInt 別人寫的範例"請問如何存取binary檔 " http://delphi.ktop.com.tw/topic.php?topic_id=36778 發表人 - StrongLemon 於 2004/05/21 10:52:27 |
StrongLemon
高階會員 發表:10 回覆:166 積分:105 註冊:2004-04-18 發送簡訊給我 |
這個範例是讀取地圖檔
格式為寬度(2Byte)高度(2Byte)是否為可經過(1Byte)
總共2+2+400*400=160004Byte
procedure TForm1.Button1Click(Sender: TObject); var I: Integer; X,Y: Integer; mapFileName,StringTemp:String; mapStream:TFileStream; mapHeight,mapWidth:Integer; Actual_read,StreamIndex:Longint; mapBitmap:TBitmap; WordBuffer:Word;//一次讀兩個Byte ByteBuffer:Byte;//一次讀一個Byte checksum:Integer; begin checksum:=0; mapFileName:='iz_dun00.fld'; mapStream:= TFileStream.Create(mapFileName,fmOpenRead); mapBitmap:=TBitmap.Create; try Actual_read:=mapStream.Read(WordBuffer,SizeOf(WordBuffer)); if Actual_read>0 then begin mapWidth:=WordBuffer; end; Actual_read:=mapStream.Read(WordBuffer,SizeOf(WordBuffer)); if Actual_read>0 then begin mapHeight:=WordBuffer; end; Button1.Caption:=IntTostr(mapWidth) ' ' IntTostr(mapHeight); Img_Map.Width:=mapWidth; Img_Map.Height:=mapHeight; mapBitmap.Width:=mapWidth; mapBitmap.Height:=mapHeight; for Y := mapHeight - 1 downto 0 do // Iterate begin for X := 0 to mapWidth - 1 do // Iterate begin Actual_read:=mapStream.Read(ByteBuffer,SizeOf(ByteBuffer)); if Actual_read>0 then begin //加入你的Checksum計算 checksum:=checksum ByteBuffer; end; if Actual_read>0 then begin //Img_Map.Canvas.PenPos:=Point(X,Y); if ByteBuffer=0 then begin //Pen.Color:=; Img_Map.Canvas.Pixels[X,Y]:=clBlack; mapBitmap.Canvas.Pixels[X,Y]:=clBlack; end else if ByteBuffer=1 then begin //Img_Map.Canvas.Pen.Color:=clBlue; Img_Map.Canvas.Pixels[X,Y]:=clBlue; mapBitmap.Canvas.Pixels[X,Y]:=clBlue; end; end; end; // for end; // for mapBitmap.SaveToFile('test.bmp'); finally // wrap up FreeAndNil(mapStream); FreeAndNil(mapBitmap); end; // try/finally end; |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |