麻烦大家,我想问个菜鸟问题,关于ACCESS里照片的问题 (0分)

  • 主题发起人 主题发起人 bluesky1000
  • 开始时间 开始时间
B

bluesky1000

Unregistered / Unconfirmed
GUEST, unregistred user!
我用ACCESS建了一个单位人事管理的数据库,需要照片,我将有一个字段命名为PHOTO,属性
选的是OLE(不知对不对,因为我只看到只有OLE能够选图片)又进行了“插入位图图像”的
操作。
在程序中,加了一个DBIMAGE构件,想着用来显示ACCESS中PHOTO的图片,可程序一运行,就
提示:Project project1.exe raised exception class EInvalidGraphic with message
'Bitmap image is not valid'
请问这是怎么回事?怎样解决呢?
当我把ACCESS中的PHOTO字段清空后,用DELPHI程序倒是可以录入。但第一条数据录完后,
录第二条时,就提示:Non-blob column in table required to perform operation,
可当我用ACCESS,把第二条记录的PHOTO字段也加上位图图像,也清空掉,再用DELPHI程序
录入就可以了,同样,当到了第三条记录(空记录),又出现了如上的问题。
这是为什么?怎样解决呢?
不胜感谢,在线听候您的指导
  
 
我也遇到类似的问题。我后来干脆没要照片这个字段了。
以前有人告诉我在InterBase中用Ctrl+V粘贴到数据库就可以了。
或者在程序用DBImage加照片添加如下代码:
Edit;
TBlobField(FieldByName('ImageOrTExtField')).LoadFromFile('aimageortextfile');
Post;
不知能帮到你否?!
 
这个问题我也遇到,笨点就笨点,瞧瞧我网 上瞧到的,有没有用?
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, DB, ADODB, DBCtrls, Grids, DBGrids, ComCtrls, ToolWin,
jpeg, ExtCtrls, ExtDlgs, DBActns, ActnList, StdCtrls;
type
TForm1 = class(TForm)
CoolBar1: TCoolBar;
ToolBar1: TToolBar;
adoCon: TADOConnection;
adoPic1: TADODataSet;
DataSource1: TDataSource;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
DBGrid1: TDBGrid;
DBImage1: TDBImage;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
ActionList1: TActionList;
DataSetFirst1: TDataSetFirst;
DataSetPrior1: TDataSetPrior;
DataSetNext1: TDataSetNext;
DataSetLast1: TDataSetLast;
DataSetInsert1: TDataSetInsert;
DataSetDelete1: TDataSetDelete;
DataSetPost1: TDataSetPost;
SpeedButton9: TSpeedButton;
OpenPictureDialog1: TOpenPictureDialog;
SavePictureDialog1: TSavePictureDialog;
SpeedButton10: TSpeedButton;
DBGrid2: TDBGrid;
SpeedButton12: TSpeedButton;
SpeedButton13: TSpeedButton;
SpeedButton14: TSpeedButton;
SpeedButton15: TSpeedButton;
SpeedButton16: TSpeedButton;
SpeedButton17: TSpeedButton;
SpeedButton18: TSpeedButton;
SpeedButton19: TSpeedButton;
SpeedButton20: TSpeedButton;
adoPic2: TADODataSet;
DataSource2: TDataSource;
Image1: TImage;
ActionList2: TActionList;
DataSetFirst2: TDataSetFirst;
DataSetPrior2: TDataSetPrior;
DataSetNext2: TDataSetNext;
DataSetLast2: TDataSetLast;
DataSetInsert2: TDataSetInsert;
DataSetDelete2: TDataSetDelete;
DataSetPost2: TDataSetPost;
DataSetCancel1: TDataSetCancel;
SpeedButton21: TSpeedButton;
DataSetCancel2: TDataSetCancel;
SpeedButton22: TSpeedButton;
StatusBar1: TStatusBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
Label1: TLabel;
Label2: TLabel;
SpeedButton11: TSpeedButton;
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton10Click(Sender: TObject);
procedure adoPic2AfterScroll(DataSet: TDataSet);
procedure SpeedButton13Click(Sender: TObject);
procedure SpeedButton12Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure SpeedButton11Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
uses About;
{$R *.dfm}
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
st: TStringStream;
Str : String;
Jpeg1 : TJPEGIMAGE;
bmp:TBitmap;
begin
if OpenPictureDialog1.Execute then
begin
bmp:=TBitmap.Create;
Str := ExtractFileExt(OpenPictureDialog1.filename);
Str := Copy(Str,2,3);
if Str='bmp' then
bmp.LoadFromFile(OpenPictureDialog1.FileName)
else
if Str='jpg' then
begin
Jpeg1 := TJPEGIMAGE.Create;
Jpeg1.LoadFromFile(OpenPictureDialog1.FileName);
bmp.Assign(Jpeg1);
end;
st := tstringstream.create('');
bmp.SaveToStream(st);
adoPic1.Edit;
adoPic1.FieldByName('PicData').AsString:= st.datastring;
end;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
adoPic1.Edit;
adoPic1.FieldByName('PicData').AsString:='';
adoPic1.Post;
end;

procedure TForm1.SpeedButton10Click(Sender: TObject);
var
Str : String;
Jpeg : TJPEGIMAGE;
bmp :TBitmap;
begin
if adoPic1.FieldByName('PicData').AsString ='' then
exit
else
begin
bmp:=TBitmap.Create;
bmp.Assign(DBImage1.Picture.Bitmap);
end;
if savePicturedialog1.Execute then
begin
Str := ExtractFileExt(savePictureDialog1.filename);
Str := Copy(Str,2,3);
if Str = 'bmp' then
bmp.SaveToFile(savePicturedialog1.FileName)
else
if Str = 'jpg' then
begin
//这里用到了把bmp格式转换为jpg格式的技术
Jpeg := TJPEGIMAGE.Create;
Jpeg.Assign(bmp);
Jpeg.SaveToFile(savePictureDialog1.FileName);
end
else
ShowMessage('对不起,暂时不支持其它格式!');
end;
end;

procedure TForm1.adoPic2AfterScroll(DataSet: TDataSet);
var
str:String;
begin
if DataSet.State=dsBrowse then
begin
str:=Trim(DataSet.FieldByName('picpath').AsString);
if (str<>'') and FileExists(str)then
Image1.Picture.LoadFromFile(str)
else
Image1.Picture.Bitmap:=nil;
end
else
if DataSet.State =dsInsert then
Image1.Picture.Bitmap :=nil;
end;

procedure TForm1.SpeedButton13Click(Sender: TObject);
var
str:String;
begin
if OpenPictureDialog1.Execute then
begin
str:=OpenPictureDialog1.FileName;
Image1.Picture.LoadFromFile(str);
adoPic2.Edit;
if ExtractFilePath(ParamStr(0))=ExtractFilePath(str) then
str:=ExtractFileName(str);
adoPic2.FieldByName('picpath').AsString :=str;
end;
end;

procedure TForm1.SpeedButton12Click(Sender: TObject);
begin
Image1.Picture.Bitmap :=nil;
adoPic2.Edit;
adoPic2.FieldByName('picpath').AsString :='';
end;

procedure TForm1.ToolButton2Click(Sender: TObject);
begin
Application.Terminate;
end;

procedure TForm1.ToolButton1Click(Sender: TObject);
begin
Form_About.ShowModal;
end;

procedure TForm1.SpeedButton11Click(Sender: TObject);
var
Str : String;
Jpeg : TJPEGIMAGE;
bmp :TBitmap;
begin
if Image1.Picture.Bitmap =nil then
exit
else
bmp:=TBitmap.Create;
bmp.Assign(Image1.Picture.Bitmap);
if savePicturedialog1.Execute then
begin
Str := ExtractFileExt(savePictureDialog1.filename);
Str := Copy(Str,2,3);
if Str = 'bmp' then
bmp.SaveToFile(savePicturedialog1.FileName)
else
if Str = 'jpg' then
begin
//这里用到了把bmp格式转换为jpg格式的技术
Jpeg := TJPEGIMAGE.Create;
Jpeg.Assign(bmp);
Jpeg.SaveToFile(savePictureDialog1.FileName);
end
else
ShowMessage('对不起,暂时不支持其它格式!');
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
str:String;
begin
if adoCon.Connected then
adoCon.Connected :=false;
str:='Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;'+
'Data Source='+ExtractFilePath(ParamStr(0))+'picdata.mdb;'+
'Mode=Share Deny None;Extended Properties="";Jet OLEDB:System database="";'+
'Jet OLEDB:Registry Path="";Jet OLEDB:Database Password="";'+
'Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;'+
'Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;'+
'Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;'+
'Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don'+''''+'t Copy Locale on Compact=False;'+
'Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False';
adoCon.ConnectionString :=str;
try
adoCon.Connected :=true;
adoPic1.Active :=true;
adoPic2.Active :=true;
except
ShowMessage('找不到数据库文件!');
Application.Terminate;
end;
end;

end.
 

Similar threads

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