AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia [GR32] How to blend two TBitmap32s
Thema durchsuchen
Ansicht
Themen-Optionen

[GR32] How to blend two TBitmap32s

Ein Thema von WojTec · begonnen am 19. Sep 2010 · letzter Beitrag vom 19. Sep 2010
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#1

[GR32] How to blend two TBitmap32s

  Alt 19. Sep 2010, 16:45
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:

procedure Multiply(F: TColor32; var B: TColor32; M: TColor32);

I tried this:
Delphi-Quellcode:
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
);
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?
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#2

AW: [GR32] How to blend two TBitmap32s

  Alt 19. Sep 2010, 16:52
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
  [...]
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#3

Re: [GR32] How to blend two TBitmap32s

  Alt 19. Sep 2010, 17:08
Delphi-Quellcode:
    ImageMap.DrawMode := dmBlend;
    ImageMap.OnPixelCombine := BlendMode.Multiply;
    ImageMap.MasterAlpha := 0;
    ImageMap.DrawTo(ShapeMap, 0, 0);

    Image321.Bitmap.Assign(ShapeMap);
I tried and effect is identical.
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#4

AW: [GR32] How to blend two TBitmap32s

  Alt 19. Sep 2010, 17:20
What effect is identical? It'd really help if you were more specific about what you want to achieve and what is happening instead.
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.861 Beiträge
 
Delphi 11 Alexandria
 
#5

AW: [GR32] How to blend two TBitmap32s

  Alt 19. Sep 2010, 17:26
Perhaps show a screenshot or similar
Markus Kinzler
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#6

Re: [GR32] How to blend two TBitmap32s

  Alt 19. Sep 2010, 18:14
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
Miniaturansicht angehängter Grafiken
i.jpg  
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.686 Beiträge
 
Delphi 2007 Enterprise
 
#7

AW: [GR32] How to blend two TBitmap32s

  Alt 19. Sep 2010, 18:28
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.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)

Geändert von Medium (19. Sep 2010 um 18:37 Uhr)
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#8

AW: [GR32] How to blend two TBitmap32s

  Alt 19. Sep 2010, 18:38
I think this should do it, but I haven't tested it:
Delphi-Quellcode:
function ColorAlgebra(F, B, M: TColor32): TColor32;
begin
  // 1. multiply
  Result := ColorModulate(F, B);
  // 2. blend
  Result := BlendRegEx(Result, B, M);
end;
[edit]
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]

Geändert von Namenloser (19. Sep 2010 um 18:46 Uhr)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#9

Re: [GR32] How to blend two TBitmap32s

  Alt 19. Sep 2010, 19:08
@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:
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;
Whats wrong with this?

Multiply() method supports alpha. In this way I realized blending and opacity in my layers (5).

Geändert von WojTec (19. Sep 2010 um 19:12 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:51 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz