Einzelnen Beitrag anzeigen

Benutzerbild von stahli
stahli

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

AW: Bitmap-Ausschnitt einfärben

  Alt 21. Feb 2014, 10:26
Ihr seid Helden und eine Heldin!

Anbei mal meine Versuche und zwei Exen.
Ich werde es erst mal bei DrawTransparentBitmap lassen.
Das ist natürlich nicht performant, aber im Moment stört das nicht.

Mit der Lumi-Variante ist der Text nicht mehr lesbar bzw. bei positiven Werten werden weiße Flächen schwarz.

Da ich kein Verständnis für Farbänderungen habe lasse ich es erst mal dabei.
Für meinen kleinen Test reicht es erst mal.


Delphi-Quellcode:
...
unit Winapi.Windows;
...

  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(Pixel^.rgbRed + Offset, 0, 255);
        Pixel^.rgbGreen := Clamp(Pixel^.rgbGreen + Offset, 0, 255);
        Pixel^.rgbBlue := Clamp(Pixel^.rgbBlue + Offset, 0, 255);

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

  procedure UnderMouseEffect;
  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 MouseDownEffect;
  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;

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

  procedure MouseDownEffectLumi;
  begin
    AdjustLuminance(aBitmap, -5); // Abdunkeln
  end;
Angehängte Dateien
Dateityp: zip Effect.zip (1,74 MB, 8x aufgerufen)
Stahli
http://www.StahliSoft.de
---
"Jetzt muss ich seh´n, dass ich kein Denkfehler mach...!?" Dittsche (2004)

Geändert von stahli (21. Feb 2014 um 10:43 Uhr)
  Mit Zitat antworten Zitat