在Paradox总存取图像的问题,很是急,快(50分)

  • 主题发起人 主题发起人 shadow_1980
  • 开始时间 开始时间
S

shadow_1980

Unregistered / Unconfirmed
GUEST, unregistred user!
我用paradox作表,bmp字段想存图像(位图),谁知道用什么格式,是binary还是graphic.用什么方法可以把图像xx.bmp存进表中,请高手们给出写道机器上就可以用的代码。谢谢了/我用一个按钮来控制位图存到表中。快些告诉我啊!
 
你可以用剪贴板实现
 
老兄,给个代码行吗?我在书上看到过,但不明白怎么用.有Tblob(table1.fieldbyname('bmp')).loadfromfile(c:/construe.bmp).但是不好使啊!难道没有人知道吗?帮帮忙了
 
var
BMP:TBitmap;
BlobStream:TBlobStream;
begin
BMP:=TBitmap.Create;
try
BMP.LoadFromFile('xx.bmp');
try
BlobStream:=TBlobStream.Create(TBlobField(Table1.FieldByName('图片')),bmWrite);
BMP.SaveToStream(BlobStream);
finally
BlobStream.Free;
end;
finally
BMP.Free;
end;
end;

 
to xda :系统提示blobstream没有初始化,这是怎么回事
 
最好是binary
我以前写过的,可是现在的机器不是我的,有空了找找以前写的。不过楼上写的差不多。
procedure SavePictureToDatabase;
var
BlobField: TField;
BS: TStream;
begin
with Query1 do
begin
Insert;
BlobField := FieldByName('picturefield');
BS := CreateBlobStream(BlobField,bmWrite);
Bitmap.SavetoStream(BS);
Post;
end;
end;
 
知道的朋友快来告诉我啊,不够可以加分的。明天我就要把程序教给老板。可还有这个问题没法解决。帮帮忙。最好是给出实例的。至少也要刻意直接就用[:(][:(]
 
以下摘自Delphi帮助文件:
读操作:
Stream:=TadoblobStream.Create(qry.fieldbyname('FileBlob') as TBlobField, bmRead);

写操作:
Writes data from a memory buffer to a BLOB field object.

Delphi syntax:

function Write(const Buffer; Count: Longint): Longint; override;

C++ syntax:

virtual int __fastcall Write(const void *Buffer, int Count);

Description

Use Write to copy data from a null-terminated string (or comparable) buffer in memory to the BLOB field object. Write copies data from the buffer to the current position in the BLOB field object (current position indicated by the Position property). Write copies the number of bytes specified in Count or the number of bytes remaining in the memory buffer (counting from the current position to the end), whichever is less. Write can be called multiple times during the lifetime of a TADOBlobStream, each call copying less than the total number of bytes to be copied.

Count represents the maximum number of bytes to copy in a single call to Write. Count may be less than, the same as, or greater than the number of bytes actually contained in the memory buffer. If Count is greater than the actual number of bytes present or remaining in the memory buffer, copying stops at the last byte. No penalty is incurred on exceptions generated by specifying a number greater than the actual size of the contents.

Write updates the Size property to Position + Count, and sets the Position property to the new value of Size. Thus, any data that was stored in the memory stream in the Count bytes after the current position is lost when calling Write.

After successful execution, Write returns the number of bytes copied to the BLOB field object. If the return value is less than Count, the most likely reason is that the end of the buffer was reached prior to copying the specified number of bytes.

var
P: PChar;
S: Integer;
BS: TADOBlobStream;
begin
if not (ADOTable1.State in [dsEdit, dsInsert]) then
ADOTable1.Edit;
BS := TADOBlobStream.Create(TMemoField(ADOTable1.Fields[1]), bmWrite);
try
S := Memo1.GetTextLen;
Inc(S);
P := AllocMem(S);
FillChar(P^, S, #0);
Memo1.GetTextBuf(P, S);
BS.Write(P^, S);
finally
BS.Free;
FreeMem(P, S);
end;

end;
 
如何才能将他从数据库中引用出来呢?用DBimage无法显示
 
你可以看Delphi自己带的例子。
数据库别名 DBDEMOS 表biolife 用graphic 存图片。
保存用:
Table1.Edit ;
(Table1.FieldByName('graphic') as TBlobField).Assign(Image1.Picture);
Table1.Post;
 
to :shadow_1980
是编译时提示BlobStream没有初始化吗?如果是这样的话应该没问题的。
 
接受了,谢谢大家
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部