Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#73

AW: Circular spectrum visualizer

  Alt 4. Apr 2019, 13:26
Wie komme ich an die X und y Position von BitmapData? bzw. RGBQuad
Muss ich ersetzen.

GDIP_BitmapGetPixel(imgSpectrum, Integer(Col) + dx, Integer(Row) + dy, Color);

Die Farbe muss ich über die Position erfragen.

Delphi-Quellcode:
    1:
      begin
        d := round(FFade * 10);

        if GDIP_BitmapLockBits(imgSpectrum, nil, ImageLockModeRead or ImageLockModeWrite,
          PixelFormat32bppARGB, @BitmapData) = OK then
        begin
          for Row := 0 to BitmapData.Height - 1 do
          begin
            RGBQuad := Scanline(BitmapData, Row);

            for Col := 0 to BitmapData.Width - 1 do
            begin
              Pixel := RGBQuad^;

              if (Col > 0) and (Row > 0) and (Col < BitmapData.Width - 1) and
                (Row < BitmapData.Height) then
              begin
                red := 0;
                green := 0;
                blue := 0;
                alpha := 0;

                for dy := -1 to 1 do
                begin
                  for dx := -1 to 1 do
                  begin
                    GDIP_BitmapGetPixel(imgSpectrum, Integer(Col) + dx, Integer(Row) + dy, Color);

                    alpha := alpha + ( Color and $ff000000 ) shr 24;
                    red := red + ( Color and $00ff0000 ) shr 16;
                    green := green + ( Color and $0000ff00 ) shr 8;
                    blue := blue + ( Color and $000000ff );
                  end;
                end;

                red := red div 9;
                green := green div 9;
                blue := blue div 9;
                alpha := alpha div 9;

                if alpha >= d then
                  Pixel.rgbReserved := alpha - d
                else
                Pixel.rgbReserved := 0;

                Color := blue or (green shl 8) or (red shl 16);
                GDIP_BitmapSetPixel(imgSpectrum, Col, Row, Color or (alpha shl 24));
              end else
                GDIP_BitmapSetPixel(imgSpectrum, Col, Row, 0);
            end;
            GDIP_BitmapUnlockBits(imgSpectrum, @BitmapData);
          end;
        end;
      end;
Get und Set Pixel ist noch nicht ersetzt.

Das RGBQuad hole ich mir hier drüber.
Delphi-Quellcode:
  function Scanline(BitmapData : TBitmapData; Stride: integer): PRGBQuad;
  begin
    result := BitmapData.Scan0;
    inc(PByte(result), Stride * bitmapData.stride);
  end;
EDIT:

Argghh..
Ich sehe gerade in der GDIObject.pas, die machen das auch nicht anders wie ich.
Aber genau das will ich nicht.

Delphi-Quellcode:
  function TGPBitmap.GetPixel(x, y: Integer; out color: TGPColor): TStatus;
  begin
    result := SetStatus(GdipBitmapGetPixel(GpBitmap(nativeImage), x, y, color));
  end;
Welchen sinn macht das? Dann kann ich mir GDIP_BitmapLockBits sparen macht so keinen sinn.
Ich hole mir alle Pixel in einem Rutsch und muss dann doch wieder die Position des Pixel mit GdipBitmapGetPixel einholen?
Was für ein Blödsinn. Oder?

EDIT2:
Ok die Lösung ist zurück zum Array.

gruss

Geändert von EWeiss ( 4. Apr 2019 um 15:26 Uhr)
  Mit Zitat antworten Zitat