此代码在TBlobField行中提供Access违规:
procedure TfrmCapture.Button3Click(Sender: TObject);
var
j: TJPEGImage;
S: TFileStream;
begin
J := TJPEGImage.Create;
try
J.Assign(Image1.Picture.Graphic);
J.CompressionQuality := 80;
J.Compress;
J.SaveToStream(S);
S.Position := 0;
TBlobField(frmSignout.tblImg.FieldByName('Picture')).LoadFromStream(S);
finally
J.Free;
end;
Image1.Picture := nil;
Close;
end;
Run Code Online (Sandbox Code Playgroud)
基本上我试图将Timage转换为JPEG然后将其保存到Image字段(MSSQL express)任何想法如何修复它?
您没有实例化TFileStream保存到:
procedure TfrmCapture.Button3Click(Sender: TObject);
var
J: TJPEGImage;
S: TFileStream;
begin
J := TJPEGImage.Create;
try
J.Assign(Image1.Picture.Graphic);
J.CompressionQuality := 80;
J.Compress;
S := TFileStream.Create('c:\path to\somefile.jpg', fmCreate); // <-- add this!
try
J.SaveToStream(S);
S.Position := 0;
TBlobField(frmSignout.tblImg.FieldByName('Picture')).LoadFromStream(S);
finally
S.Free; // <-- add this
end;
finally
J.Free;
end;
Image1.Picture := nil;
Close;
end;
Run Code Online (Sandbox Code Playgroud)
话虽这么说,我建议完全避免使用该文件(除非你真的需要它)并使用TDataSet.CreateBlobStream()而不是TBlobField.LoadFromStream():
procedure TfrmCapture.Button3Click(Sender: TObject);
var
J: TJPEGImage;
S: TStream;
begin
J := TJPEGImage.Create;
try
J.Assign(Image1.Picture.Graphic);
J.CompressionQuality := 80;
J.Compress;
S := frmSignout.tlbImg.CreateBlobStream(frmSignout.tblImg.FieldByName('Picture'), bmWrite);
try
J.SaveToStream(S);
finally
S.Free;
end;
finally
J.Free;
end;
Image1.Picture := nil;
Close;
end;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
163 次 |
| 最近记录: |