selas
asked on
image doubles, how to fix it?
Then person has no image, it gets previous person picture
My code is:
procedure TForm1.DBCtrlGrid1PaintPan el(DBCtrlG rid: TDBCtrlGrid;
Index: Integer);
begin
Jpeg:=TJpegImage.create;
tmp:=TMemoryStream.create;
try
if not TBlobField(AdoQuery1.Field ByName('nu otrauka')) .IsNull then //is there a picture?
begin
TBlobField(AdoQuery1.field byname('nu otrauka')) .SaveToStr eam(tmp);
tmp.Seek(0, soFromBeginning);
Jpeg.LoadFromStream(tmp);
Image1.Picture.Assign(jpeg );
Image1.visible := true;
end
else
begin
Image1.Picture.Bitmap.Assi gn(Nil); //there is no Image
Image1.visible := false;
end;
finally
jpeg.Free;
tmp.Free;
end;
end;
How to fix it?
My code is:
procedure TForm1.DBCtrlGrid1PaintPan
Index: Integer);
begin
Jpeg:=TJpegImage.create;
tmp:=TMemoryStream.create;
try
if not TBlobField(AdoQuery1.Field
begin
TBlobField(AdoQuery1.field
tmp.Seek(0, soFromBeginning);
Jpeg.LoadFromStream(tmp);
Image1.Picture.Assign(jpeg
Image1.visible := true;
end
else
begin
Image1.Picture.Bitmap.Assi
Image1.visible := false;
end;
finally
jpeg.Free;
tmp.Free;
end;
end;
How to fix it?
ASKER
i tried:
Image1.Picture.Assign(Nil) ; //there is no Image
or
Image1.Picture := Nil; //there is no Image
but images still doubles....
Image1.Picture.Assign(Nil)
or
Image1.Picture := Nil; //there is no Image
but images still doubles....
hmm,
as far as i remember i run into the same problem (years ago),
but don't know how i solved this, yet.
as far as i remember correct, the dbctrlgrid replicates the controls for each panel,
so the goal should be to find the replicated imagecontrol associated with the
displayed record (which is not the current record)
guess i had a solution with use of a dummy calculated field.
will search in my archives this evening
meikl ;-)
as far as i remember i run into the same problem (years ago),
but don't know how i solved this, yet.
as far as i remember correct, the dbctrlgrid replicates the controls for each panel,
so the goal should be to find the replicated imagecontrol associated with the
displayed record (which is not the current record)
guess i had a solution with use of a dummy calculated field.
will search in my archives this evening
meikl ;-)
hi,
searched my archives, but it points out that i have not solved this.
i removed the TImage from the tdbctrlgrid, and placed it beside the grid,
to show only the image of the current-record.
sorry, that i have no solution
meikl ;-)
searched my archives, but it points out that i have not solved this.
i removed the TImage from the tdbctrlgrid, and placed it beside the grid,
to show only the image of the current-record.
sorry, that i have no solution
meikl ;-)
Now, if this is an Access database, I don't see how he's getting the image correctly in the first place.
Access adds and extra header to the image in the blob field and you have to trim the stream to get
the image out.
I will need to create a testbed table but I think I have a solution to this problem.
Access adds and extra header to the image in the blob field and you have to trim the stream to get
the image out.
I will need to create a testbed table but I think I have a solution to this problem.
Now IS this an Access database?
ASKER
No i'm using mysql and getting data with AdoQuery
What is the FIELDTYPE for the field that contains the image?
Did you know it is not very efficient to store images in a database?
It is better to store the path to the image in the database and
store the image on disk.
Did you know it is not very efficient to store images in a database?
It is better to store the path to the image in the database and
store the image on disk.
ASKER
Field type is blob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think with the DBImage having the TDataLink, it causes the DBCtrlGrid panel painting to act differently.
Look how is done in TDBImage.
Before
if not TBlobField(AdoQuery1.Fiel. .......... .
put
Image1.Picture.Graphic := nil;
Regards
mottor
Before
if not TBlobField(AdoQuery1.Fiel.
put
Image1.Picture.Graphic := nil;
Regards
mottor
>Image1.Picture.Bitmap.Ass
use
Image1.Picture.Assign(Nil)
or
Image1.Picture := Nil; //there is no Image
instead
an old solution of mine found at
https://www.experts-exchange.com/questions/10175461/JPG-Images-into-TDBCtrlGrid.html#1384525
was for paradox, but will applyable also for other databases
//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:
procedure DBCtrlGrid1PaintPanel(DBCt
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:
begin
Table1.Close;
JPegImage.Free; // Free JPeg-Object
end;
//Store
procedure TForm1.LoadJPEG1Click(Send
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'
begin
MyJPegStream := TMemoryStream.Create; // Handle JPegFile
JPegImage.LoadFromFile(ope
JPegImage.SaveToStream(MyJ
// Prepare Blob
MyBlobStream := TBlobStream.Create(TBlobFi
MyBlobStream.CopyFrom(MyJP
Image1.Picture.Assign(JPeg
MyJPegStream.Free; //Free all
MyBlobStream.Free;
end;
end;
end else ShowMessage('Table is not in Edit Mode!');
end;
//Get
procedure TForm1.Table1AfterScroll(D
Var
MyBlobStream : TBlobStream;
begin
// Do Only if a JPeg available
if (Table1.FieldByName('Bild2
begin
// Prepare Streams
MyBlobStream := TBlobStream.Create(TBlobFi
JPegImage.LoadFromStream(M
Image1.Picture.Assign(JPeg
MyBlobStream.Free; // Free Stream
end
else image1.Picture := Nil; // No JPeg saved disable display
end;
procedure TForm1.DBCtrlGrid1PaintPan
Index: Integer);
Var
MyBlobStream : TBlobStream;
begin
// Do Only if a JPeg available
if (Table1.FieldByName('Bild2
begin
// Prepare Streams
MyBlobStream := TBlobStream.Create(TBlobFi
JPegImage.LoadFromStream(M
Image1.Picture.Assign(JPeg
MyBlobStream.Free; // Free Stream
end
else image1.Picture := Nil; // No JPeg saved disable display
end;
end.
hope this helps
meikl ;-)