Registriert seit: 26. Nov 2003
Ort: Halle/Saale
4.343 Beiträge
Delphi 11 Alexandria
|
AW: Bitmap-Ausschnitt einfärben
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).
|