![]() |
[GR32] How to blend two TBitmap32s
I don't know how to blend two bitmaps if these bitmaps are not layers. For layers I'm using OnPixelCombine with assigned procedures like this:
Delphi-Quellcode:
procedure Multiply(F: TColor32; var B: TColor32; M: TColor32);
I tried this:
Delphi-Quellcode:
but MasterAlpha parasm work diffrent than master alpha in top layer (opacity). This param decide which bitmap should be more visible (0 = first, 255 = second). How to blend bitmaps like layers?
function ColorAlgebra(F, B, M: TColor32): TColor32;
begin BlendMode.Multiply(F, B, M); // the same procedure for OnPixelCombine Result := BlendRegEx(F, B, M); end; BlendTransfer(Blended, 0, 0, Blended.BoundsRect, ImageMap, ImageMap.BoundsRect, ShapeMap, ShapeMap.BoundsRect, ColorAlgebra, 200 ); |
AW: [GR32] How to blend two TBitmap32s
Why so complicated? I've always simply done it like this:
Delphi-Quellcode:
var
A,B: TBitmap32; begin [...] A.MasterAlpha := 127; // 50% A.DrawMode := dmBlend; A.DrawTo(B, 0, 0); // B now contains the blended image [...] |
Re: [GR32] How to blend two TBitmap32s
Delphi-Quellcode:
I tried and effect is identical.
ImageMap.DrawMode := dmBlend;
ImageMap.OnPixelCombine := BlendMode.Multiply; ImageMap.MasterAlpha := 0; ImageMap.DrawTo(ShapeMap, 0, 0); Image321.Bitmap.Assign(ShapeMap); |
AW: [GR32] How to blend two TBitmap32s
What effect is identical? It'd really help if you were more specific about what you want to achieve and what is happening instead.
|
AW: [GR32] How to blend two TBitmap32s
Perhaps show a screenshot or similar
|
Re: [GR32] How to blend two TBitmap32s
Liste der Anhänge anzeigen (Anzahl: 1)
Ok guys, please look at attached picture:
I want to blend 2 with 1 and get 5. In my method I got 3, in @NamenLozer's method I got 4. In my program that suppots layers I got 5 and this is valid effct (opacity is 100%, white is not visible). Are you understand what I mean? I want to get 5 effect without layers. :) @mkinzler, thanks for advise :) |
AW: [GR32] How to blend two TBitmap32s
That's a simple multiplication, and has nothing in the world to do with alpha. Just multiply 1 and 2, and be done.
Edit: Well, it looks like in 5 alpha controls the strength, so that the result becomes B1 * (alpha2+(1-alpha2)*B2) Edit2: And be aware, that whenever we talk about colors, their intensity is thought to range between 0 and 1. So if you have to work with Bytes, don't forget to scale them to 0..1, or you'll get wrong results. |
AW: [GR32] How to blend two TBitmap32s
I think this should do it, but I haven't tested it:
Delphi-Quellcode:
[edit]
function ColorAlgebra(F, B, M: TColor32): TColor32;
begin // 1. multiply Result := ColorModulate(F, B); // 2. blend Result := BlendRegEx(Result, B, M); end; Only your assumption that alpha=0 would result in picture 2 is false. What you'd really get is a picture that has the background in the middle and then fades to solid black near the edges. Nowhere in this picture you'd see anything white. Because if you did, then you'd logically also have some white in it when alpha>0, which is what happens in 3 and 4. [/edit] |
Re: [GR32] How to blend two TBitmap32s
@NamenLozer, this is black blured border on white background. I mean white color in multiply mode is neutral (not visible) ;)
Here is test code:
Delphi-Quellcode:
Whats wrong with this?
function ColorAlgebra(F, B, M: TColor32): TColor32;
begin // BlendMode.Multiply(F, B, M); // Result := BlendRegEx(F, B, M); // 1. multiply Result := ColorModulate(F, B); // 2. blend Result := BlendRegEx(Result, B, M); end; procedure TForm18.Image321Click(Sender: TObject); var ImageMap, ShapeMap, Blended: TBitmap32; begin ImageMap := TBitmap32.Create; ShapeMap := TBitmap32.Create; Blended := TBitmap32.Create; try // Bitmap.SetSize(240, 180); // Bitmap.Clear(clWhite32); ImageMap.Assign(Image321.Bitmap); ShapeMap.SetSize(ImageMap.Width, ImageMap.Height); Blended.SetSize(ImageMap.Width, ImageMap.Height); // vignette is generated, can use existing img too [vignette code here, working on ShapeMap] Blended.MasterAlpha := 0; ImageMap.MasterAlpha := 0; ShapeMap.MasterAlpha := 0; // BlendTransfer(Blended, 0, 0, Blended.BoundsRect, ImageMap, ImageMap.BoundsRect, // ShapeMap, ShapeMap.BoundsRect, ColorAlgebra, 0 // ); // Image321.Bitmap.Assign(Blended); ImageMap.DrawMode := dmBlend; ImageMap.OnPixelCombine := BlendMode.Multiply; ImageMap.MasterAlpha := 0; ImageMap.DrawTo(ShapeMap, 0, 0); Image321.Bitmap.Assign(ShapeMap); finally ImageMap.Free; ShapeMap.Free; Blended.Free; end; end; Multiply() method supports alpha. In this way I realized blending and opacity in my layers (5). |
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:01 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz