AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Bitmap-Ausschnitt einfärben

Ein Thema von stahli · begonnen am 21. Feb 2014 · letzter Beitrag vom 21. Feb 2014
 
Benutzerbild von stahli
stahli

Registriert seit: 26. Nov 2003
Ort: Halle/Saale
4.352 Beiträge
 
Delphi 11 Alexandria
 
#10

AW: Bitmap-Ausschnitt einfärben

  Alt 21. Feb 2014, 12:37
Ja, AlphaBlend passt gut.

Für den Fall, dass jemand in dem Bereich Infos sucht, hier der aktuelle Stand:

Delphi-Quellcode:
  procedure UnderMouseEffectDrawTransp;
  var
    tmpBitmap: TBitmap;
  begin
    tmpBitmap := TBitmap.Create;
    tmpBitmap.Width := ClientRect.Width;
    tmpBitmap.Height := ClientRect.Height;
    tmpBitmap.Canvas.Brush.Style := bsDiagCross;
    tmpBitmap.Canvas.Brush.Color := clWhite;
    tmpBitmap.Canvas.FillRect(TRect.Create(0, 0, tmpBitmap.Width,
      tmpBitmap.Height));
    // tmpBitmap.SaveToFile('xxx.bmp');
    DrawTransparentBitmap(tmpBitmap, aBitmap.Canvas, ClientRect, $07);
    // aBitmap.Canvas.Brush.Color := clYellow;
    // aBitmap.Canvas.FillRect(aRect);
    // SetStretchBltMode(aBitmap.Canvas.Handle, COLORONCOLOR);
    // StretchBlt(aBitmap.Canvas.Handle, ClientRect.Left, ClientRect.Top,
    // ClientRect.Width, ClientRect.Height, tmpBitmap.Canvas.Handle, 0, 0,
    // tmpBitmap.Width, tmpBitmap.Height, SRCCOPY);
    // aBitmap.Canvas.CopyMode := cmWhiteness;
    // aBitmap.Canvas.CopyRect(ClientRect, tmpBitmap.Canvas,
    // tmpBitmap.Canvas.ClipRect);
    tmpBitmap.Free;
  end;

  procedure MouseDownEffectDrawTransp;
  var
    tmpBitmap: TBitmap;
  begin
    tmpBitmap := TBitmap.Create;
    tmpBitmap.Width := ClientRect.Width;
    tmpBitmap.Height := ClientRect.Height;
    tmpBitmap.Canvas.Brush.Style := bsDiagCross;
    tmpBitmap.Canvas.Brush.Color := clWhite;
    tmpBitmap.Canvas.FillRect(TRect.Create(0, 0, tmpBitmap.Width,
      tmpBitmap.Height));
    // tmpBitmap.SaveToFile('xxx.bmp');
    DrawTransparentBitmap(tmpBitmap, aBitmap.Canvas, ClientRect, $10);
    // aBitmap.Canvas.Brush.Color := clYellow;
    // aBitmap.Canvas.FillRect(aRect);
    // SetStretchBltMode(aBitmap.Canvas.Handle, COLORONCOLOR);
    // StretchBlt(aBitmap.Canvas.Handle, ClientRect.Left, ClientRect.Top,
    // ClientRect.Width, ClientRect.Height, tmpBitmap.Canvas.Handle, 0, 0,
    // tmpBitmap.Width, tmpBitmap.Height, SRCCOPY);
    // aBitmap.Canvas.CopyMode := cmWhiteness;
    // aBitmap.Canvas.CopyRect(ClientRect, tmpBitmap.Canvas,
    // tmpBitmap.Canvas.ClipRect);
    tmpBitmap.Free;
  end;

  function Clamp(Value: Integer; Min, Max: Integer): Byte; inline;
  begin
    Result := Value;
    if Result < Min then
      Result := Min;
    if Result > Max then
      Result := Max;
  end;

  procedure AdjustLuminance(Bmp: TBitmap; Offset: SmallInt);
  var
    // Bmp: TBitmap;
    Pixel: PRGBQuad;
    X, Y: Integer;
  begin
    Bmp.PixelFormat := pf32Bit;
    for Y := ClientRect.Top to ClientRect.Bottom do
    begin
      // Pointer auf 1. Pixel in der Zeile holen
      Pixel := Bmp.Scanline[Y];
      System.Inc(Pixel, ClientRect.Left);
      for X := ClientRect.Left to ClientRect.Right do
      begin
        Pixel^.rgbRed := Clamp(Integer(Pixel^.rgbRed) + Offset, 0, 255);
        Pixel^.rgbGreen := Clamp(Integer(Pixel^.rgbGreen) + Offset, 0, 255);
        Pixel^.rgbBlue := Clamp(Integer(Pixel^.rgbBlue) + Offset, 0, 255);

        // ein Pixel nach rechts gehen
        System.Inc(Pixel);
      end;
    end;
  end;

  procedure UnderMouseEffectLumi;
  begin
    AdjustLuminance(aBitmap, -2); // Abdunkeln
  end;

  procedure MouseDownEffectLumi;
  begin
    AdjustLuminance(aBitmap, -5); // Abdunkeln
  end;

  procedure UnderMouseEffectAlpha;
  var
    tmpBitmap: TBitmap;
    BlendFunc: TBlendFunction;
  begin
    tmpBitmap := TBitmap.Create;
    tmpBitmap.Width := ClientRect.Width;
    tmpBitmap.Height := ClientRect.Height;
    tmpBitmap.Canvas.Brush.Color := clHighlight;
    tmpBitmap.Canvas.FillRect(Rect(0, 0, tmpBitmap.Width, tmpBitmap.Height));

    // Blend a foreground image over the top - constant alpha, not per-pixel
    BlendFunc.BlendOp := AC_SRC_OVER;
    BlendFunc.BlendFlags := 0;
    BlendFunc.SourceConstantAlpha := 5;
    BlendFunc.AlphaFormat := 0;
    AlphaBlend(aBitmap.Canvas.Handle, ClientRect.Left, ClientRect.Top,
      tmpBitmap.Width, tmpBitmap.Height, tmpBitmap.Canvas.Handle, 0, 0,
      tmpBitmap.Width, tmpBitmap.Height, BlendFunc);

    tmpBitmap.Free;
  end;

  procedure MouseDownEffectAlpha;
  var
    tmpBitmap: TBitmap;
    BlendFunc: TBlendFunction;
  begin
    tmpBitmap := TBitmap.Create;
    tmpBitmap.Width := ClientRect.Width;
    tmpBitmap.Height := ClientRect.Height;
    tmpBitmap.Canvas.Brush.Color := clHighlight;
    tmpBitmap.Canvas.FillRect(Rect(0, 0, tmpBitmap.Width, tmpBitmap.Height));

    // Blend a foreground image over the top - constant alpha, not per-pixel
    BlendFunc.BlendOp := AC_SRC_OVER;
    BlendFunc.BlendFlags := 0;
    BlendFunc.SourceConstantAlpha := 20;
    BlendFunc.AlphaFormat := 0;
    AlphaBlend(aBitmap.Canvas.Handle, ClientRect.Left, ClientRect.Top,
      tmpBitmap.Width, tmpBitmap.Height, tmpBitmap.Canvas.Handle, 0, 0,
      tmpBitmap.Width, tmpBitmap.Height, BlendFunc);

    tmpBitmap.Free;
  end;
@Namenloser: Brachte keine Besserung (für mich jetzt auch nicht dringend).
Angehängte Dateien
Dateityp: zip Effect.zip (2,61 MB, 20x aufgerufen)
Stahli
http://www.StahliSoft.de
---
"Jetzt muss ich seh´n, dass ich kein Denkfehler mach...!?" Dittsche (2004)
  Mit Zitat antworten Zitat
 


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 01:53 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 by Thomas Breitkreuz