How draw a shadow effect in a complete Bitmap image?

How draw a shadow effect in a complete Bitmap image?



I want know if is possible draw a shadow effect in a complete Bitmap image already existent and after have a effect similar to this example below, where all area behind modal Form is my new Bitmap image already with the shadow effect? =>



enter image description here





idownvotedbecau.se/noattempt idownvotedbecau.se/nocode
– Dave Nottage
May 14 at 5:42




1 Answer
1



This is pretty easy. First we need a routine that fades a given bitmap:


procedure FadeBitmap(ABitmap: TBitmap);
type
PRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray = array[word] of TRGBTriple;
var
SL: PRGBTripleArray;
y: Integer;
x: Integer;
begin
ABitmap.PixelFormat := pf24bit;

for y := 0 to ABitmap.Height - 1 do
begin
SL := ABitmap.ScanLine[y];
for x := 0 to ABitmap.Width - 1 do
with SL[x] do
begin
rgbtRed := rgbtRed div 2;
rgbtGreen := rgbtGreen div 2;
rgbtBlue := rgbtBlue div 2;
end;
end;
end;



Then, when we want to display our modal message, we create a bitmap 'screenshot' of our current form, fade it, and place it on top of all controls of the form:


procedure TForm1.ButtonClick(Sender: TObject);
var
bm: TBitmap;
pn: TPanel;
img: TImage;
begin

bm := GetFormImage;
try
FadeBitmap(bm);

pn := TPanel.Create(nil);
try
img := TImage.Create(nil);
try
img.Parent := pn;

pn.BoundsRect := ClientRect;
pn.BevelOuter := bvNone;
img.Align := alClient;

img.Picture.Bitmap.Assign(bm);

pn.Parent := Self;

ShowMessage('Hello, Faded Background!');

finally
img.Free;
end;
finally
pn.Free;
end;
finally
bm.Free;
end;

end;



A VCL form with a faded background when a modal window is shown.



Hint: If you have more than one modal dialog to display in your application, you probably want to refactor this. To this end, have a look at TApplicationEvent's OnModalBegin and OnModalEnd events.


TApplicationEvent


OnModalBegin


OnModalEnd





i already have a TImagecomponent on Form (not runtime created) and not use TPanel, then how apply this shadow only to stay above TImageand instead of ShowMessage show a Form2?
– user9672569
May 14 at 12:17



TImage


TPanel


TImage


ShowMessage


Form2





To display Form2 instead of a message box, replace ShowMessage('Hello, Faded Background!'); with with TForm2.Create(Self) do try ShowModal; finally Free; end;. But this is Delphi basics, so you can read all about it in any Delphi tutorial.
– Andreas Rejbrand
May 14 at 12:25



ShowMessage('Hello, Faded Background!');


with TForm2.Create(Self) do try ShowModal; finally Free; end;





not must ShowModal, only Show (normal). I tested showing normally,and shadow effect not worked.
– user9672569
May 14 at 12:28



ShowModal


Show





And also i not need of a TPanel. Only TImage + Form2.Show + shadow effect behind Form2
– user9672569
May 14 at 12:35



TPanel


TImage


Form2.Show


Form2





@KKK: In your question, you specifically wrote "modal". Of course it doesn't work with only Show, because Show returns immediately, so the shadow removal code is executed directly. If you want to use a non-modal popup form, you need to move the shadow removal code to the time when you close the popup. Further, since a TImage is a graphic control, it cannot be on top of windowed controls. Hence the panel.
– Andreas Rejbrand
May 14 at 12:54



Show


Show


TImage






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

ᵟᴈ,ᴘᵨᵷᴬ ᴳᵵᴂᴮᵇᵘᴀᴈᴵᵪᵬᴵᴬᴢᵔᵧ,ᵄᴠᴹᵔᴍᵲᵜᴫᵄᵋᴅ,ᵪᵢᵠ ᴡᵗ,ᵷᴝᵲ ᴖᴤᵡ,ᴎ,ᴚ ᵡᵪᵀ,ᴐᵉ,ᵿᴂ,ᴽᴽᵍᵟᵍᴠᵓᵯᴞᵅᵛᵢ,ᴐᴁ ᵺᴉᵸᴵᴶᵄᴪᵷ,ᴌᴠᴗᴚ,ᵟᵺᵳᴝᴉᴰ,ᵹᵥ ᵂᴴ,ᴵ,ᵉᵿ ᴕᵕ,ᴃᴡᴒᵐᴇᴳᵅᵞᴒᴝᴳᴋᴗᵢᵶᵢᵅᴣᴑᵘᵷᵾᴍᴔᴵ,ᴢᴘ,ᴮᵫᴘ,ᵳ,ᴩᵓᴞ