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

x
?
Solved

JPG Images into TDBCtrlGrid

Posted on 1999-06-25
16
Medium Priority
?
769 Views
Last Modified: 2013-11-19
Hi everyone.

My objetive is to load Blob fields containing either BitMap or Jpeg (or TIFF, or GIF,...) in something similar to a TDBCtrlGrid.

I have tried some methods but:

1.- TDBImage does not load Jpg/Jpeg images,
2.- When I try the DBCtrlGrid.OnPaintPanel to upload the images manually, I get bizarre results, making me think that I'm not accesing the correct record of the associated DataSet.

Does anyone know how to make it, out of making an array of images and loading it one by one?

Thanks

Felixin
0
Comment
Question by:Felixin
[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
  • 5
  • 5
16 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 450 total points
ID: 1384524
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1384525
hi Felixin,

there is someone faster (zif you are it)
this should do it

//Sample unit for Storing JPG-Images in the JPeg-Format
//in a BlobField in Paradox
//It is recommended, that the BlobField in Paradox is
//Typ Binary, not Graphic, because the file will be stored
//Free for Use
//Appendix: Its a sample, therefore no try, except, finally blocks included
//Created January 1999
//Expanded June 1999 with a DBCtrlGrid

unit db_pict_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBTables, ExtCtrls, DBCtrls, StdCtrls, Mask, Menus, jpeg, DBCGrids; // JPeg unit is used

type
  TForm1 = class(TForm)   // 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;
    DBCtrlGrid1: TDBCtrlGrid;
    Image1: TImage;
    DBEdit1: TDBEdit;
    Table2: TTable;             // 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);
    procedure DBCtrlGrid1PaintPanel(DBCtrlGrid: TDBCtrlGrid;
      Index: Integer); // Get JPeg and Display in Image1
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

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

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;


//Store
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 (only JPeg-Files)
    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;

//Get
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);
    MyBlobStream.Free;  // Free Stream
  end
  else image1.Picture := Nil;  // No JPeg saved disable display
end;


procedure TForm1.DBCtrlGrid1PaintPanel(DBCtrlGrid: TDBCtrlGrid;
  Index: Integer);
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);
    MyBlobStream.Free;  // Free Stream
  end
  else image1.Picture := Nil;  // No JPeg saved disable display
end;

end.

meikl
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1384526
appendix,

my sample above is for jpeg only, if you want to store mutliple formats, you must determine with an additional field, which format is stored and of course depending of this information you have another get- and storing routine.

meikl
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Author Comment

by:Felixin
ID: 1384527
Hi Zifnab,

I'm checking your answer.

Anyway, thanks for being so fast.

I'll be answering you soon.

Felixin
0
 
LVL 2

Author Comment

by:Felixin
ID: 1384528
ZifNab,

The code that you sent me was, most of all, equal to what I wrote before asking this question.

What was wrong with it was the allign property of the TImage in my code!:
When testing your code, I've just put a TImage on the panel, without setting the Allign property to alClient, as it was in my project .... and it worked. Then I thought that the diference was just this, and tried changing the align property to alClient...AND IT STOPPED WORKING!: only the first image was repeated on each panel, as it was doing on my project.

Very bizarre!.

Anyway, yours was the answer, yours are the points.

I have to be fair.

Thanks.

Felixin
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1384529
?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1384530
? zif, has you sent code ?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1384531
No, I don't understand anything about it, I only referenced to the components!
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1384532
Felexin, can you clearefy? Are you using kretzschmar's example or one of the components I've proposed?
0
 
LVL 2

Author Comment

by:Felixin
ID: 1384533
I'm sorry, I made a mistake.

I'm using kretzschmar code example.

I'm really sorry. Tell me what can I do, and I'll make it.

Felixin
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1384534
hi felixin,

it doesn't matter, you have nothing to do.
i was just wondering. glad that is now working for you.

meikl
0
 
LVL 2

Author Comment

by:Felixin
ID: 1384535
Well,

Thank you anyway

Felixin
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1384536
kretzschmar, I can give you the same amount of points, that's fair I guess. Only problem then is still that I've recieved some points.

Felixin, how much points were on this q'n?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1384537
hi zif,

let it be, points are not all of life.
it is more important that felixin can go on.

but, thanks for the offer

meikl ;-)
0
 
LVL 2

Author Comment

by:Felixin
ID: 1384538
Boys,

I'm gonna cry  ;-)).

Points were 150.

Thanks to you two.

Thanks a lot.

Felixin
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1384539
ok, let it be this time.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Add visuals to your Prezi to keep your audience engaged. Learn how to embed images, edit them, and more in this video micro tutorial. Select "Insert" from the top menu in your Prezi editor: Select "Image": A toolbar will pop in from the right …
Learn the basics of inputting and editing your text components in Prezi. We will cover how to set styles, position, and group your text components. In your Prezi editor, click anywhere on the canvas to add text: A flashing cursor informs you that yo…
Suggested Courses

670 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