Jump to content

Display image after selecting element in grid


Gauravg

Recommended Posts

2 minutes ago, Sherzod said:

Hello,


procedure TMainForm.UniDBGrid1SelectionChange(Sender: TObject);
begin

end;

UniDBGrid.OnSelectionChange ?

Hello Sherzod,

I know it has to be done either on cellclicked or selectionchange of grid. To add image normally to an image control we specify UniImage.Picture.LoadFromFile(FolderPath+'images\'+IntToStr(adr)+'.jpg').

I want to display image which is in variant variable. I want to know which prooerty of image control i need to use to set image from variant type.

Untitled.png

Link to comment
Share on other sites

5 minutes ago, irigsoft said:

What kind of variable (jpeg, bmp, png) or  other image files formats ?

Hello, 

oImage: variant;
oImage:=DSetObject.FieldByName('Pic').AsVariant;
UniImage1.Picture := oImage;//which property of control need to be used to set image

Thank you

Link to comment
Share on other sites

Just now, Gauravg said:

Hello, 

oImage: variant;
oImage:=DSetObject.FieldByName('Pic').AsVariant;
UniImage1.Picture := oImage;//which property of control need to be used to set image

Thank you

I use it by this way to show/draw image in grid:

1. I save images in database, and show it in uniDBGrid when draw Grid

if (Sender As TDBGrid).DataSource.DataSet.RecNo >= 0 then begin
    (SENDER AS TDBGrid).Canvas.FillRect(Rect);
    R := Rect;
    R.Right := R.Left + Trunc((R.Right - R.Left) );
    if (Column.Field is TBlobField)
    AND (Column.Width > 0)
    then begin
      TRY
        bmpImage := tBitmap.Create;
        bmpStream := TMemoryStream.Create;

        //load from datasource

//LoadFromBlobField (Column.Field,bmpStream);

      //load from file

bmpStream.loadFromFile ('Youpath');
        bmpStream.Position := 0;
        bmpImage.LoadFromStream (bmpStream);
        bmpImage.Assign(ResizeBmp (bmpImage,Column.Width,Column.Width));
        IF THackDBGrid(Sender).DefaultRowHeight <> Column.Width then
            THackDBGrid(Sender).DefaultRowHeight := Column.Width;
        THackDBGrid (Sender).RowHeights [0] := THackDBGrid (Sender).Canvas.TextHeight('Wg') + 4;
        (Sender As TDBGrid).Canvas.StretchDraw (R, bmpImage);

        (SENDER AS TDBGrid).Canvas.Brush.Style := bsClear;
 

      FINALLY
        bmpStream.Free;
        bmpImage.Free;
      END;
    end;

end;

You can use this to draw bitmap object of uniImage.Picture.Bitmap

Link to comment
Share on other sites

function LoadFromBlobField(const AField: TField; const Stream: TStream): boolean;
var
  ResultStr: string;
  PResultStr: PChar;
begin
  Result := false;
  if (Assigned(AField)) and (Assigned(Stream)) then begin
    try
      ResultStr := AField.Value;
      PResultStr := PChar(ResultStr);
      Stream.Write(PResultStr^, Length(ResultStr));
      Stream.Seek(0,0);
      Result := true;
    except
    end;
  end;
end;

 

I think AField can be a variant type or just be used to apply the value of the field to the image

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...