Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Get picture

I put TImage (alClient) in form and I put TPanel in front of TImage.
How to get picture the behind of TPanel and next painted in TPanel.
(I don't want using TLabel !)

Regards,
Joely
0
joely
Asked:
joely
  • 5
  • 4
1 Solution
 
viktornetCommented:
YOu mean you want to paint the same picture that is in TImage and pasted(paint) it onto TPanel?? If that's what you want I think I got an idea, but I'm not exactly sure if it works...

Cheers,
Viktor
0
 
joelyAuthor Commented:
Yes, I want to paint the same picture.
Just picture behind of TPanel.
(Align of TPanel not alClient like TImage !!!).
0
 
viktornetCommented:
Well, here is what I had in mind...

procedure TForm1.Button1Click(Sender: TObject);
var
  DC : hDC;
begin
  DC := GetDC(Panel1.Handle);
  BitBlt(DC, 2, 2, Panel1.Width-4, Panel1.Height-4, Image1.Canvas.Handle, 0, 0, SRCCOPY);
  ReleaseDC(Panel1.Handle, DC);
end;

Hope this helps...

Cheers,
Viktor
0
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.

 
joelyAuthor Commented:
Hello Vik

If I put TLabel in TPanel so this component not visible. Why ?
0
 
viktornetCommented:
Because what happens in the procedure above is that I get the DC(Device Context) of the TImage and copy that to the DC of the TPanel. What happens is that if you have any graphical controls like TLabel(It's a graphical control) it will not bee seen since the DC is the painting that you see on the Control...

You can try MyLabel.Refresh; or MyLabel.Update; after you do the procedure I gave you above, so you can allow the Label to be painted again... try it out and tell me what happens...

Cheers,
Viktor
0
 
viktornetCommented:
You could even try MyLabel.Invalidate; and see if it works...
0
 
joelyAuthor Commented:
Hello Vik

I found another problem.

This is Semi Transparent Label component.
Put this component in front of TImage and you'll know what I meant about Semi Tranparent Label.

Try to put this component in TPanel and use procedure that you gave me.
You'll find out that this component isn't working as it should be.

Please install this component.

unit STLabel;

interface

uses
  Windows, Classes, StdCtrls, Controls, Graphics;

type
  TEffect = (teBlackness,teDSTInvert,teMergeCopy,teMergePaint,teNotSRCCopy,
            teNotSRCErase,tePATCopy,tePATInvert,tePATPaint,teSRCAnd,teSRCCopy,
            teSRCErase,teSRCInvert,teSRCPaint,teWhiteness);

  TSemiTransparentLabel = class(TGraphicControl)
  private
    FEffect: TEffect;

    procedure SetEffect(Value:TEffect);
  protected
    procedure Paint; Override;
  public
    constructor Create(AOwner:TComponent); override;
  published
    property Color;
    property Effect:TEffect read FEffect write SetEffect;
  end;

procedure Register;

implementation

const
  Effects : array[TEffect] of Integer = (BLACKNESS,DSTINVERT,MERGECOPY,
            MERGEPAINT,NOTSRCCOPY,NOTSRCERASE,PATCOPY,PATINVERT,PATPAINT,SRCAND,
            SRCCOPY,SRCERASE,SRCINVERT,SRCPAINT,WHITENESS);

constructor TSemiTransparentLabel.Create(AOwner:TComponent);
begin
  inherited Create(AOwner);
  SetBounds(0,0,100,25);
  Color := clRed;
  FEffect := teSRCAnd;
end;

procedure TSemiTransparentLabel.Paint;
var Bmp1:TBitmap;
begin
  Bmp1:=TBitmap.Create;
  Bmp1.Width:=Width;
  Bmp1.Height:=Height;
  Bmp1.Canvas.Brush.Style:=bsSolid;
  Bmp1.Canvas.Brush.Color:=Color;
  Bmp1.Canvas.FillRect(Rect(0,0,Width,Height));
  BitBLT(Bmp1.Canvas.Handle,0,0,Width,Height,Canvas.Handle,0,0,Effects[FEffect]);
  Canvas.Draw(0,0,Bmp1);
  Bmp1.Free;
//  inherited;
end;

procedure TSemiTransparentLabel.SetEffect(Value:TEffect);
begin
  if FEffect<>Value then
  begin
    FEffect := Value;
    Invalidate;
  end;
end;

procedure Register;
begin
  RegisterComponents('Samples', [TSemiTransparentLabel]);
end;

end.
0
 
joelyAuthor Commented:
Hello Vik

I have the answer.
0
 
viktornetCommented:
Hello Joely!

Sorry I didn't reply, but I've been very busy with school lately and I really don't have time for working with Delphi that much.. Also I've been studying C/C++ and some Assembler so that eats uo all of my spare time...

Regards,
Viktor Ivanov
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now