this slowpoke moves

Calculate Bitmap Negativ

Beispiel 1:
function InvertBmp(SourceBitmap: TBitmap): TBitmap;
var
  iFor, iFor2: LongInt;
  TempBitmap: TBitmap;
  bRed, bGreen, bBlue: Byte;
  PixelColor: LongInt;
begin
  TempBitmap := TBitmap.Create;
  TempBitmap.Width := SourceBitmap.Width;
  TempBitmap.Height := SourceBitmap.Height;
  for iFor := 0 to SourceBitmap.Width -1 do
  begin
    for iFor2 := 0 to SourceBitmap.Height -1 do
    begin
      PixelColor := ColorToRGB(SourceBitmap.Canvas.Pixels[iFor, iFor2]);
      bRed := PixelColor;
      bGreen := PixelColor shr 8;
      bBlue := PixelColor shr 16;
      bRed := 255 -bRed;
      bGreen := 255 -bGreen;
      bBlue := 255 -bBlue;
      TempBitmap.Canvas.Pixels[iFor, iFor2] := (bRed shl 8 +bGreen) shl 8 +bBlue;
    end;
  end;
  Result := TempBitmap;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Image1.Picture.Bitmap.Assign(InvertBmp(Image1.Picture.Bitmap));
end;
Beispiel 2:
procedure TForm1.Button2Click(Sender: TObject);
var
  color,blue,green,red,i,j : integer;
begin
  Screen.Cursor := crHourglass;
  for i:=0 to imgApple.Width-1 do
    for j:=0 to imgApple.Height-1 do begin
      color := imgApple.Canvas.Pixels[i,j];
      red := color and 255;                        // letzte 8 Bit
      green := (color and 65535) shr 8;            // mittl. 8 Bit
      blue := color shr 16;                        // ersten 8 Bit
      red := 255 - red;
      green := 255 - green;
      blue := 255 - blue;
      imgApple.Canvas.Pixels[i,j] := 65536*blue + 256*green + red;
      //imgApple.Canvas.Pixels[i,j] := 16777215 - imgApple.Canvas.Pixels[i,j];
    end;
  Screen.Cursor := crDefault;
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate