Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#6

AW: Farbtöne (mit Tollerenz) in einem Bild ersetzen

  Alt 28. Jan 2019, 19:13
erstelle eine Colormatrix
https://docs.microsoft.com/en-us/win...ngle-color-use
https://www.c-sharpcorner.com/upload...uranindia/941/

Delphi-Quellcode:
  ColorMatrixFlags = (
    ColorMatrixFlagsDefault,
    ColorMatrixFlagsSkipGrays,
    ColorMatrixFlagsAltGray
  );
  TColorMatrixFlags = ColorMatrixFlags;

  ColorMatrix = packed array[0..4, 0..4] of Single;
  TColorMatrix = ColorMatrix;
  PColorMatrix = ^TColorMatrix;
übergebe die Farbwerte.. r, g, b
Sample.
Delphi-Quellcode:
      
      if (nRed <> 0) or (nGreen <> 0) or (nBlue <> 0) then
      begin
        if (nRed <> 0) then
          sR := (nRed / 128.0)
        else
        sR := 1.0;

        if (nGreen <> 0) then
          sG := (nGreen / 128.0)
        else
        sG := 1.0;

        if (nBlue <> 0) then
          sB := (nBlue / 128.0)
        else
        sB := 1.0;

        sN := 0.0001;
        // Farb Matrix füllen
        // Red Green Blue Alpha W
        c2[0][0] := sR; c2[1][0] := 0.0; c2[2][0] := 0.0; c2[3][0] := 0.0; c2[4][0] := 0.0; // Red
        c2[0][1] := 0.0; c2[1][1] := sG; c2[2][1] := 0.0; c2[3][1] := 0.0; c2[4][1] := 0.0; // Green
        c2[0][2] := 0.0; c2[1][2] := 0.0; c2[2][2] := sB; c2[3][2] := 0.0; c2[4][2] := 0.0; // Blue
        c2[0][3] := 0.0; c2[1][3] := 0.0; c2[2][3] := 0.0; c2[3][3] := 1.0; c2[4][3] := 0.0; // Alpha
        c2[0][4] := sN; c2[1][4] := sN; c2[2][4] := sN; c2[3][4] := 0.0; c2[4][4] := 1.0; // W

        if cMdone then
        begin
          MoveMemory(@c1, @cM, 100);
          cM := MatMultiply(c1, c2);
        end else
        begin
          MoveMemory(@cM, @c2, 100);
          cMdone := true;
        end;
      end;

      if cMdone then
      begin
        GdipCreateImageAttributes(imgAttr);
        GdipSetImageAttributesColorMatrix(imgAttr, ColorAdjustTypeDefault, true,
          @cM, @gM, ColorMatrixFlagsDefault);
      end;

      GdipSetInterpolationMode(graphics, ObjItem.quality);
      GdipDrawImageRectRectI(graphics, img, PosX, PosY, wD, hD, xS, yS, wS, hS, 2, imgAttr, ImgAbort, nil);
Du benötigst zum setzen der Farb Attribute

API's
GdipCreateImageAttributes
GdipSetImageAttributesColorMatrix
GdipDisposeImageAttributes

zum zeichnen
Ein Image vom Bitmap-Source über GdipCreateBitmapFromScan0 erstellen das du in der Farbe verändern willst.

API's
GdipCreateBitmapFromScan0
GdipCreateFromHDC
GdipSetInterpolationMode
GdipDrawImageRectRectI
GdipDeleteGraphics
GdipDisposeImage

Willst du nun noch den Alpha Wert verändern dann musst du auch hier das jeweilige Byte im Array ändern.
Siehe..
Delphi-Quellcode:
      
      if (Alpha < 255) then
      begin
        sT := (min(254, Alpha) / 255.0);
        // Farb Matrix füllen
        // Siehe Transparenz! in row 4, column 4
        c2[0][0] := 1.0; c2[1][0] := 0.0; c2[2][0] := 0.0; c2[3][0] := 0.0; c2[4][0] := 0.0;
        c2[0][1] := 0.0; c2[1][1] := 1.0; c2[2][1] := 0.0; c2[3][1] := 0.0; c2[4][1] := 0.0;
        c2[0][2] := 0.0; c2[1][2] := 0.0; c2[2][2] := 1.0; c2[3][2] := 0.0; c2[4][2] := 0.0;
        c2[0][3] := 0.0; c2[1][3] := 0.0; c2[2][3] := 0.0; c2[3][3] := sT; c2[4][3] := 0.0;
        c2[0][4] := 0.0; c2[1][4] := 0.0; c2[2][4] := 0.0; c2[3][4] := 0.0; c2[4][4] := 1.0;
        if cMdone then
        begin
          MoveMemory(@c1, @cM, 100);
          cM := MatMultiply(c1, c2);
        end else
        begin
          MoveMemory(@cM, @c2, 100);
          cMdone := true;
        end;
      end;
Zitat:
mit dem Ziel, dass die Operation von der GPU durchgeführt wird.
Das kannst du dir abschminken. GDI, GDI+ rendern nicht über die GPU! da musst du dich schon mit OpenGL, DIRECTX(Direct3D\Direct2D) beschäftigen.

gruss

Geändert von EWeiss (29. Jan 2019 um 09:00 Uhr)
  Mit Zitat antworten Zitat