marlon_ric
asked on
storing and reading jpeg,gif,image file on an SQLserver database
hi experts,
I'm trying to load a picture using delphi6 into a database which by the way a Microsoft SQL server database version 7. My problem is when I load a bitmap it respond with an error message of "Invalid blob length", unless the size of bitmap is very small. This lead me to try loading a jpeg instead but it only respond with a different error messages "JPEG error #52" and "bitmap image is not valid".
I sincerely hope you can advice me on this because its very important to my job. I'll give this question 250 points. Thank you very much.
My code is as follows:
Image1.Picture.LoadFromFil e('c:\my_p icture.jpg ');
with Table1 do
begin
insert;
Table1pic.Assign(Image1.Pi cture.grap hic);
Post;
end;
and also try
with Table1 do
begin
insert;
j:= TJPEGImage.Create;
j.LoadFromFile(OpenDialog1 .FileName) ;
Table1pic.Assign(j);
Post;
end;
and last
with Table1 do
begin
insert;
fs := TFileStream.Create(OpenDia log1.filen ame, fmOpenRead);
bs:= TBlobStream.create(Table1P ic, bmWrite);
bs.CopyFrom(fs, 0);
bs.Free;
fs.Free;
post;
end;
I'm trying to load a picture using delphi6 into a database which by the way a Microsoft SQL server database version 7. My problem is when I load a bitmap it respond with an error message of "Invalid blob length", unless the size of bitmap is very small. This lead me to try loading a jpeg instead but it only respond with a different error messages "JPEG error #52" and "bitmap image is not valid".
I sincerely hope you can advice me on this because its very important to my job. I'll give this question 250 points. Thank you very much.
My code is as follows:
Image1.Picture.LoadFromFil
with Table1 do
begin
insert;
Table1pic.Assign(Image1.Pi
Post;
end;
and also try
with Table1 do
begin
insert;
j:= TJPEGImage.Create;
j.LoadFromFile(OpenDialog1
Table1pic.Assign(j);
Post;
end;
and last
with Table1 do
begin
insert;
fs := TFileStream.Create(OpenDia
bs:= TBlobStream.create(Table1P
bs.CopyFrom(fs, 0);
bs.Free;
fs.Free;
post;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>because it generates compiler error of "too many actual parameter"
which delphi version do you have?
>but still it gives the error "bitmap image is not valid".
a) your database-table-fieldtype should be a blob-type,
rather than a graphic-type
b) you can't use a tdbimage for displaying a jpeg-image, use a timage instead
meikl ;-)
which delphi version do you have?
>but still it gives the error "bitmap image is not valid".
a) your database-table-fieldtype should be a blob-type,
rather than a graphic-type
b) you can't use a tdbimage for displaying a jpeg-image, use a timage instead
meikl ;-)
ASKER
1)im using delphi version 6.
2)actually the datatype that I use for this field is "Image type" on SQLServer. But I guess this is the only true blob field for the images data on this database because I try to change it into a "varBinary" and it complains on error "type mismatch"
3)yes, im using TImage.
2)actually the datatype that I use for this field is "Image type" on SQLServer. But I guess this is the only true blob field for the images data on this database because I try to change it into a "varBinary" and it complains on error "type mismatch"
3)yes, im using TImage.
ASKER
1)im using delphi version 6.
2)actually the datatype that I use for this field is "Image type" on SQLServer. But I guess this is the only true blob field for the images data on this database because I try to change it into a "varBinary" and it complains on error "type mismatch"
3)yes, im using TImage.
2)actually the datatype that I use for this field is "Image type" on SQLServer. But I guess this is the only true blob field for the images data on this database because I try to change it into a "varBinary" and it complains on error "type mismatch"
3)yes, im using TImage.
do you use ado, bde or other
for connecting to the database?
for connecting to the database?
ASKER
I use bde which connect through odbc.
did you thought to use ado instead of bde?
anyway it should work,
if you have persistent fields,
then delete it and try again,
after restructuring your table field
to varbinary
meikl ;-)
anyway it should work,
if you have persistent fields,
then delete it and try again,
after restructuring your table field
to varbinary
meikl ;-)
ASKER
hi again,
I dont know how but the code you gave me above suddenly work.
I save it into the database as
with Table1 do
begin
insert;
Table1PatientId.asString:= 'marlon';
TBlobField(table1Pic).Load FromFile (OpenDialog1.filename);
Post;
end;
I read it as
bs:= TBlobStream.create(Table1P ic, bmRead);
j:= TJPEGImage.Create;
j.loadfromStream(bs);
Image1.Picture.graphic:= j;
and it works thank you very much kretzschmar.
One last thing, how can I use GIF, delphi doesn't seem to have a TGIFImage for GIF, is there any class that encapsulate it just like TJPEGImage for JPEG?
I dont know how but the code you gave me above suddenly work.
I save it into the database as
with Table1 do
begin
insert;
Table1PatientId.asString:=
TBlobField(table1Pic).Load
Post;
end;
I read it as
bs:= TBlobStream.create(Table1P
j:= TJPEGImage.Create;
j.loadfromStream(bs);
Image1.Picture.graphic:= j;
and it works thank you very much kretzschmar.
One last thing, how can I use GIF, delphi doesn't seem to have a TGIFImage for GIF, is there any class that encapsulate it just like TJPEGImage for JPEG?
ASKER
One last thing, how can I use GIF, delphi doesn't seem to have a TGIFImage for GIF, is there any class that encapsulate it just like TJPEGImage for JPEG?
glad you got it work :-))
there is a good tgifimage from melander,
download here
http://www.torry.net/vcl/graphics/gif/gifimage.exe
but don't know if it will work with d6,
just try
meikl ;-)
there is a good tgifimage from melander,
download here
http://www.torry.net/vcl/graphics/gif/gifimage.exe
but don't know if it will work with d6,
just try
meikl ;-)
ASKER
with Table1 do
begin
insert;
TBlobField(table1Pic).Load
post
end;
but still it gives the error "bitmap image is not valid".
I removed "ftblob" from your
"TBlobField(table1Pic).Loa
because it generates compiler error of "too many actual parameter"
marlon.