Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

picture in Oracle 8's Blob field

Posted on 1999-07-22
6
Medium Priority
?
555 Views
Last Modified: 2010-04-04
Oracle 8 have Blob field, it store picture.
when I use dbImage,it say 'bitmap image is not valid'
how can i do ?
0
Comment
Question by:jianl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1390550
Can you show us the code where you place the picture into the blob field?

Cheers,

Raymond.
0
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1390551
Let's hope that meikl's code will help you...
=====================
   this is a sample unit how to store jpeg files in a blobfield
   gif goes similar, but you must download this freeware component

   http://www.torry.webnorth.com/vcl/graphics/gifimage.zip

        in the uses clause add the units
        jpeg and gifunit


       unit db_pict_u;

       interface

       uses
         Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

         Db, DBTables, ExtCtrls, DBCtrls, StdCtrls, Mask, Menus, jpeg; // JPeg unit
   is used

       type
         TForm1 = class(TForm)
           DBEdit1: TDBEdit;   // A other DBField
           DBNavigator1: TDBNavigator;
           Table1: TTable;
           DataSource1: TDataSource;
           PopupMenu1: TPopupMenu;     // a Popup linked to Image1
           LoadPicture1: TMenuItem;    // the MenuItem of the Popup
           OpenDialog1: TOpenDialog;   // OpenDialog
           Image1: TImage;             // Visual Output for the JPeg
           procedure FormCreate(Sender: TObject);
           procedure FormDestroy(Sender: TObject);
           procedure LoadJPEG1Click(Sender: TObject);      // File Load and Store in
   DB
           procedure Table1AfterScroll(DataSet: TDataSet); // Get JPeg and Display
   in Image1
         private
           { Private-Deklarationen }
         public
           { Public-Deklarationen }
         end;

       var
         Form1: TForm1;
         JPegImage : TJpegImage;  //A temporary JPeg-Object

       implementation

       {$R *.DFM}

       procedure TForm1.FormCreate(Sender: TObject);
       begin
         JpegImage := TJPegImage.Create; // Create JPeg-Object
         Table1.Open;
       end;

       procedure TForm1.FormDestroy(Sender: TObject);
       begin
         Table1.Close;
         JPegImage.Free;  // Free JPeg-Object
       end;

       procedure TForm1.LoadJPEG1Click(Sender: TObject);
       Var
         MyBlobStream : TBlobStream;      // Streams
         MyJPegStream : TMemoryStream;
       begin
         if (Table1.State = dsEdit) or  (Table1.State = dsInsert) then    // Do only if in
   edit mode
         begin
           If opendialog1.Execute then    // If file selected
           begin
             if Table1.FieldByName('Bild2').IsBlob then   // this line can deleted
             begin
               MyJPegStream := TMemoryStream.Create;      // Handle JPegFile
               JPegImage.LoadFromFile(opendialog1.filename);
               JPegImage.SaveToStream(MyJPegStream);
               // Prepare Blob
               MyBlobStream :=
   TBlobStream.Create(TBlobField(Table1.FieldByName('Bild2')),bmReadWrite);
               MyBlobStream.CopyFrom(MyJPegStream,0);  // Copy JPeg into
   BlobField
               Image1.Picture.Assign(JPegImage);  // Display
               MyJPegStream.Free;  //Free all
               MyBlobStream.Free;
             end;
           end;
         end else ShowMessage('Table is not in Edit Mode!');
       end;

       procedure TForm1.Table1AfterScroll(DataSet: TDataSet);
       Var
         MyBlobStream : TBlobStream;
       begin
         // Do Only if a JPeg available
         if (Table1.FieldByName('Bild2').IsBlob) and
   (not(Table1.FieldByName('Bild2').IsNull)) then
         begin
           // Prepare Streams
           MyBlobStream :=
   TBlobStream.Create(TBlobField(Table1.FieldByName('Bild2')),bmRead);
           JPegImage.LoadFromStream(MyBlobStream);
           Image1.Picture.Assign(JPegImage);  //Display JPeg
           MyBlobStream.Free;  // Free Stream
         end
         else image1.Picture := Nil;  // No JPeg saved disable display
       end;

       end.


   additional you shoulduse a field which determines which grafic-typ is stored

   meikl
------------------------
 here is a unit which stores both grafictypes and display both in an Image-Control
 tested on paradox (blobtype-binary) and Interbase (typ Blob)
 the table have a structure like this

 ID = Number
 Typ = Char(3)
 Picture=Blob

 the unit

 unit db_pict_u2;

 interface

 uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
   ExtDlgs, Db, DBTables, ExtCtrls, DBCtrls, StdCtrls, Mask,
   Jpeg,  //Jpeg-Unit used
   GifUnit;  // Gif-Unit used

 type
   TForm1 = class(TForm)
     Image1: TImage;              //only for Visualizing
     DBEdit1: TDBEdit;            //a other dbfield
     DBNavigator1: TDBNavigator;  //db-navigation
     Table1: TTable;              //the table, where the images are stored
     DataSource1: TDataSource;
     OpenPictureDialog1: TOpenPictureDialog;  //for loading picture
     Button1: TButton;
     procedure Button1Click(Sender: TObject); //execute load and preStore to the Blobfield
     procedure FormCreate(Sender: TObject);   //TableOpen
     procedure FormDestroy(Sender: TObject);  //TableClose
     procedure Table1AfterScroll(DataSet: TDataSet); //Retrieve Blob and Display
   private
     { Private-Deklarationen }
   public
     { Public-Deklarationen }
   end;

 var
   Form1: TForm1;

 implementation

 {$R *.DFM}

 procedure TForm1.Button1Click(Sender: TObject);  //This i Have made easier
 Var
   ExtS : String[4];  //Holds The Extension
 begin
   if (Table1.State = dsEdit) or  (Table1.State = dsInsert) then    // Do only if in edit mode
   begin
     If openpicturedialog1.Execute then    // If file selected
     begin
       if Table1.FieldByName('Picture').IsBlob then   // this line can deleted
       begin  //remember the Extension
         ExtS := copy(AnsiUpperCase(ExtractFileExt(OpenPictureDialog1.FileName)),2,MaxLongInt);
         if ExtS = 'JPEG' then ExtS := 'JPG';  //Noramlize Extension
         if (ExtS = 'JPG') or (ExtS = 'GIF') then  //If one of these extensions
         begin
           try
             TBlobField(Table1.FieldByName('Picture')).LoadFromFile(openpicturedialog1.filename);  //Store
 the File in the Blob
             Table1.FieldByName('Typ').AsString := ExtS; //Store the Extension in the Grafic-TypField
             image1.Picture.LoadFromFile(openpicturedialog1.filename); //Load Image, also from file
           except
             showMessage('Error during BlobOperation');
           end;
         end
         else showmessage('no jpg or gif-file selected');
       end;
     end;
   end else ShowMessage('Table is not in Edit Mode!');
 end;

 procedure TForm1.FormCreate(Sender: TObject);
 begin
   Table1.Open;
 end;

 procedure TForm1.FormDestroy(Sender: TObject);
 begin
   Table1.Close;
 end;

 procedure TForm1.Table1AfterScroll(DataSet: TDataSet);
 Var
   MyJpegImage : TJpegImage;  //if define this gloabal, you win a little perfomance
   MyGifImage : TGifFile;           //in this case you must create and free it on a other event
   MyBlobStream : TBlobStream;
 begin
   // Do Only if a Picture available
   if (Table1.FieldByName('Picture').IsBlob) and (not(Table1.FieldByName('Picture').IsNull)) then
   begin  //create a blobstream
     MyBlobStream := TBlobStream.Create(TBlobField(Table1.FieldByName('Picture')),bmRead);
     if Table1.FieldByName('Typ').Asstring = 'GIF' then  //if grafictyp = gif
     begin
       MyGifImage := TGifFile.Create;               //create GifObject, can also be done Global
       MyGifImage.LoadFromStream(MyBlobStream);     //get the information from the blob
       Image1.Picture.Assign(MyGifImage.AsBitmap);  //Display Gif
       MyGifImage.Free;                             //Free Object
     end
     else  //can only be JPG
     begin
       MyJPegImage := TJPegImage.Create;         //create JPegObject, can also be done global
       MyJPegImage.LoadFromStream(MyBlobStream); //get the information from the blob
       Image1.Picture.Assign(MyJPegImage);       //Display JPeg
       MyJPegImage.Free;                         //Free Object
     end;
     MyBlobStream.Free;  // Free Stream
   end
   else image1.Picture := Nil;  // No JPeg saved disable display
 end;

 end.


 meikl
======================
*PHEW*... That was a hard work...

Thanks meikl :)

-vik-
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1390552
;-)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 1390553
hi jianl,

remark

my code provided by vik works on all database-systems,
which provides blobs, not only paradox.

the dbimage-component can only used on database-systems, where the bde can determine that the blob is a tgraphic-blobfield, the bde can't do this by mostly sql-based database systems, so that you have to work with the tblobstream to push the datacontent to a object which can handle the data.

if you use Bitmap-images, you handle this over the TBitmap-Object.

last not least, it should work.

good luck

meikl ;-)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1390554
hehe... you said it ;-)
0
 

Author Comment

by:jianl
ID: 1390555
Thank you!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

661 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