Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

storing and reading jpeg,gif,image file on an SQLserver database

Posted on 2003-03-17
11
Medium Priority
?
284 Views
Last Modified: 2013-11-19
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.LoadFromFile('c:\my_picture.jpg');
    with Table1 do
    begin
    insert;
    Table1pic.Assign(Image1.Picture.graphic);
    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(OpenDialog1.filename, fmOpenRead);
    bs:= TBlobStream.create(Table1Pic, bmWrite);
    bs.CopyFrom(fs, 0);
    bs.Free;
    fs.Free;
    post;
  end;
0
Comment
Question by:marlon_ric
  • 6
  • 5
11 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 1000 total points
ID: 8156805
try

TBlobField(table1Pic).LoadFromFile('Filename',ftBlob);

meikl ;-)
0
 

Author Comment

by:marlon_ric
ID: 8156929
thanks! I tried

with Table1 do
  begin
  insert;
  TBlobField(table1Pic).LoadFromFile(OpenDialog1.filename);
  post
end;

but still it gives the error "bitmap image is not valid".

I removed "ftblob" from your
  "TBlobField(table1Pic).LoadFromFile('Filename',ftBlob);"
because it generates compiler error of "too many actual parameter"

marlon.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8156939
>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 ;-)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:marlon_ric
ID: 8157163
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.
0
 

Author Comment

by:marlon_ric
ID: 8157249
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.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8157274
do you use ado, bde or other
for connecting to the database?
0
 

Author Comment

by:marlon_ric
ID: 8157356
I use bde which connect through odbc.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8157570
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 ;-)
0
 

Author Comment

by:marlon_ric
ID: 8157737
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).LoadFromFile  (OpenDialog1.filename);
    Post;
  end;

I read it as

  bs:= TBlobStream.create(Table1Pic, 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?
0
 

Author Comment

by:marlon_ric
ID: 8157757
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?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8157826
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 ;-)
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question