P
patricklee
Unregistered / Unconfirmed
GUEST, unregistred user!
如何将图像保存在自定义的文件里面,我用下面的两种方法都只能将
图像的指针保存(8字节指针),保存图像到数据库可用TBlobField方法,
那保存图像到自定义文件用什么方法呢?
下面没有注释的是第一种方法,有注释的是第二种方法
---------------------------
type
MyType=Record
sss:string[40];
BMap:TBitmap;
end;
-------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
MT:MyType;
FF:File of MyType;
//Buf:TMemoryStream;
begin
MT.sss:=edit1.text;
MT.BMap:=TBitmap.Create;
// Buf:=TMemoryStream.Create;
// Image1.Picture.Bitmap.SaveToStream(Buf);
// Buf.Position:=0;
// MT.BMap.SaveToStream(Buf);
MT.BMap.Assign(Image1.picture.Bitmap);
try
AssignFile(FF,'e:/123.myt');
Rewrite(FF);
write(FF,MT);
// MT.BMap.Free;---当我不注释这句时一按BUTTON2就程序崩溃
finally
closeFile(FF);
end;
// Buf.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
MT:MyType;
FF:File of MyType;
begin
if FileExists('e:/123.myt') then
begin
AssignFile(FF,'e:/123.myt');
Reset(FF);
try
Read(FF,MT);
except
closeFile(FF);
end;
edit1.Text:=MT.sss;
Image2.Picture.Bitmap.Assign(MT.BMap);
end;
end;
图像的指针保存(8字节指针),保存图像到数据库可用TBlobField方法,
那保存图像到自定义文件用什么方法呢?
下面没有注释的是第一种方法,有注释的是第二种方法
---------------------------
type
MyType=Record
sss:string[40];
BMap:TBitmap;
end;
-------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
MT:MyType;
FF:File of MyType;
//Buf:TMemoryStream;
begin
MT.sss:=edit1.text;
MT.BMap:=TBitmap.Create;
// Buf:=TMemoryStream.Create;
// Image1.Picture.Bitmap.SaveToStream(Buf);
// Buf.Position:=0;
// MT.BMap.SaveToStream(Buf);
MT.BMap.Assign(Image1.picture.Bitmap);
try
AssignFile(FF,'e:/123.myt');
Rewrite(FF);
write(FF,MT);
// MT.BMap.Free;---当我不注释这句时一按BUTTON2就程序崩溃
finally
closeFile(FF);
end;
// Buf.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
MT:MyType;
FF:File of MyType;
begin
if FileExists('e:/123.myt') then
begin
AssignFile(FF,'e:/123.myt');
Reset(FF);
try
Read(FF,MT);
except
closeFile(FF);
end;
edit1.Text:=MT.sss;
Image2.Picture.Bitmap.Assign(MT.BMap);
end;
end;