Topic: MVD VCL Question

Hello Dmitry, and a happy new year to you.


I have a question, just out of curiosity : do you use a special Component to display images in MVD or is it a standard Delphi one ?


I am specially interested in that functionality where when clicked, an image displayed in an Image of DBImage component opens full size.
How did you do that ? Is it an extra Delphi Component ?


Cheers and happy new year again


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: MVD VCL Question

Hello.


I just created own class based on TImage to extend functionality.

Dmitry.

3 (edited by mathmathou 2018-01-06 06:32:46)

Re: MVD VCL Question

Thanks Dmitry,


Exploring your suggestion, I ended up with a procedure (on click of the TImage) but there are various cases to consider :
- image is in landscape or portrait mode
- image is larger or smaller to screen resolution


I known this is not MVD but Delphi, but this is what I came up with. This work fine in my application but would you mind giving your advises, I'm sure I overlooked some details (I use TImage because all major image formats are already supported and I don't need to convert)


NOTE : the form that displays the image is created on click and destroyed on Close and images are displayed with a ratio of 0.9 to their original size


//-06-DISPLAYING IMAGE FULL SIZE ON CLICK
procedure TfrmAssetEdit.Image3Click(Sender: TObject);
var
  F_Im_View : TfrmImageView;
  ImageH, ImageW, ScreenH, ScreenW : Integer;
  RatioI : Double;
begin
    try
       F_Im_View := TfrmImageView.Create(nil);
      //Screen Dimensions
      ScreenH := Screen.Height;
      ScreenW := Screen.Width;

      //Image Dimensions
      ImageH := Image3.Picture.Height;
      ImageW := Image3.Picture.Width;
      //Image Ration
      RatioI := ImageW / ImageH;
        if RatioI > 1  then  //Image is in landscape mode
          begin
            if (ImageW <= ScreenW) AND (ImageH <= ScreenH)then
              begin
                F_Im_View.Image1.Picture := Image3.Picture;
                F_Im_View.ClientWidth := Round(ImageW * 0.9);
                F_Im_View.Image1.Width := Round(ImageW * 0.9);
                F_Im_View.ClientHeight := Round(ImageH * 0.9);
                F_Im_View.Image1.Height := Round(ImageH * 0.9);
                F_Im_View.Image1.Proportional := True;
                F_Im_View.ShowModal;
              end
            else
              begin
                F_Im_View.Image1.Picture := Image3.Picture;
                F_Im_View.ClientHeight := Round(ScreenH * 0.9);
                F_Im_View.Image1.Height := Round(ScreenH * 0.9);
                F_Im_View.ClientWidth :=  Round(ImageW * ScreenH * 0.9 / ImageH);
                F_Im_View.Image1.Width := Round(ImageW * ScreenH * 0.9 / ImageH);
                F_Im_View.Image1.Proportional := True;
                F_Im_View.ShowModal;
              end;
          end
        else if RatioI <= 1 then //Image is in Portait mode
          if (ImageW <= ScreenW) AND (ImageH <= ScreenH)then
              begin
                F_Im_View.Image1.Picture := Image3.Picture;
                F_Im_View.ClientWidth := Round(ImageW * 0.9);
                F_Im_View.Image1.Width := Round(ImageW * 0.9);
                F_Im_View.ClientHeight := Round(ImageH * 0.9);
                F_Im_View.Image1.Height := Round(ImageH * 0.9);
                F_Im_View.Image1.Proportional := True;
                F_Im_View.ShowModal;
              end
          else
              begin
                F_Im_View.Image1.Picture := Image3.Picture;
                F_Im_View.ClientHeight := Round(ScreenH * 0.9);
                F_Im_View.Image1.Height := Round(ScreenH * 0.9);
                F_Im_View.ClientWidth := Round((ImageW * ScreenH * 0.9) / ImageH);
                F_Im_View.Image1.Width := Round((ImageW * ScreenH * 0.9) / ImageH);
                F_Im_View.Image1.Proportional := True;
                F_Im_View.ShowModal;
              end;
    finally
      F_Im_View.Free;
  end;
end;

Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: MVD VCL Question

Delphi code from TdbImage component

OnClick on Image call the procedure:

frmdbCoreImageViewer.ShowImageViewer(Self.Picture);

procedure TfrmdbCoreImageViewer.ShowImageViewer(Pic: TPicture);
begin
  Self.AutoSize := false;
  imgView.Picture.Assign(Pic);

  // if picture is larger than screen
  if (((Pic.Width) - 20) > Screen.Width) or (((Pic.Height) - 20) > Screen.Height) then
  begin
    Show;
    Self.WindowState := wsMaximized;
    imgView.Stretch := true;
  end else
  begin
    Show;
    Self.WindowState := wsNormal;
    imgView.Stretch := false;
    Self.ClientWidth := imgView.Picture.Width;
    Self.ClientHeight := imgView.Picture.Height;
  end;
end;
Dmitry.