1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135:
| procedure Rahmen3D(B: TBitmap; TransparentColor: TColor); // nur mit 24Bit Farbtiefe type PRGBEntry = ^TRGBEntry; TRGBEntry = packed record r, g, b: Byte; end; var TransColor: TColorRef; FlippedBitmap: Boolean; Width, Height: Integer; Memory: PByte;
function GetPix(X, Y: Integer): TColorRef; var pB: PRGBEntry; begin if (Cardinal(X) >= Cardinal(Width)) or (Cardinal(Y) >= Cardinal(Height)) then begin Result := TransColor; Exit; end;
pB := PRGBEntry(Memory); // Verkehrtherumliegende Bitmaps beachten if FlippedBitmap then Dec(pB, Y * Width) else Inc(pB, Y * Width); Inc(pB, X); with pB^ do Result := RGB(r, g, b); end;
procedure SetPix(X, Y: Integer; Color: TColorRef); var pB: PRGBEntry; begin if (Cardinal(X) >= Cardinal(Width)) or (Cardinal(Y) >= Cardinal(Height)) then Exit;
pB := PRGBEntry(Memory); // Verkehrtherumliegende Bitmaps beachten if FlippedBitmap then Dec(pB, Y * Width) else Inc(pB, Y * Width); Inc(pB, X); with pB^ do begin r := (Color shr 16) and $ff; g := (Color shr 8) and $ff; b := Color and $ff; end; end;
const cH = $00E2E2E2; cD = clGray; var X, Y, S: Integer; DIB: TDIBSection; begin if B.PixelFormat <> pf24bit then raise Exception.Create('Nur für 24Bit Farbtiefe.'); Width := B.Width; Height := B.Height;
TransColor := ColorToRGB(TransparentColor); if (Height = 0) or (Width = 0) then Exit;
Memory := B.ScanLine[0]; // liegen die Bitmapzeilen verkehrt herum im Speicher? GetObject(B.Handle, SizeOf(DIB), @DIB); FlippedBitmap := DIB.dsBmih.biHeight > 0;
for Y := Height - 1 downto 0 do begin S := -1; for X := 0 to Width - 1 do begin //Ausnahmeabfragen bei den vier Bitmap-Rändern if GetPix(X, Y) <> TransColor then {if not IsTransparent(X, Y) then} begin if (X = 0) then begin SetPix(X, Y, clWhite); SetPix(X + 1, Y, cH); end else if (Y = 0) then begin SetPix(X, Y, clWhite); SetPix(X, Y + 1, cH); end else if (X = Width - 1) then begin SetPix(X, Y, clBlack); SetPix(X - 1, Y, cD); end else if (Y = Height - 1) then begin SetPix(X, Y, clBlack); SetPix(X, Y - 1, cD); end;
//Ausnahmeabfragen bei Region-Rändern - Vertikal if GetPix(X, Y - 1) = TransColor then {if (IsTransparent(X, Y - 1)) then} begin SetPix(X, Y, clWhite); // SetPix(X, Y + 1, cH); end else if GetPix(X, Y + 1) = TransColor then {if (IsTransparent(X, Y + 1)) then} begin SetPix(X, Y, clBlack); SetPix(X, Y - 1, cD); end;
//Normalabfragen bei Region-Rändern - Horizontal (1) if (S <> -1) then begin SetPix(X, Y, clWhite); SetPix(X + 1, Y, cH); S := -1; end;
end // if not IsTransparent(X, Y) else begin //Normalabfragen bei Region-Rändern - Horizontal (2) S := 1; if GetPix(X - 1, Y) <> TransColor then {if not IsTransparent(X - 1, Y) then} begin SetPix(X - 1, Y, clBlack); SetPix(X - 2, Y, cD); end; end; // if not IsTransparent(X, Y) else
end; // for Width
end; // for Height
B.Modified := True; end; |