⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvqdrawimage.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    X2 := t;
  end;
  if Y1 > Y2 then
  begin
    t := Y1;
    Y1 := Y2;
    Y2 := t;
  end;
  a := ((X2 - X1) div 2);
  xcenter := X1 + a;
  b := ((Y2 - Y1) div 2);
  ycenter := Y1 + b;
  Color1 := ColorToRGB(Color1);
  R1 := GetRValue(Color1);
  G1 := GetGValue(Color1);
  B1 := GetBValue(Color1);
  Color2 := ColorToRGB(Color2);
  R2 := GetRValue(Color2);
  G2 := GetGValue(Color2);
  B2 := GetBValue(Color2);
  Sphere(Clip, xcenter, a, ycenter, b, R1, G1, B1, R2, G2, B2, True);
  Picture.Bitmap.Assign(Clip);
end;

procedure TJvDrawImage.Column(Bitmap: TBitmap; XOrigin, XFinal, YOrigin, YFinal: Integer; R1, G1, B1, R2, G2, B2: Byte; Smooth: Boolean);
var
  j: Integer;
begin
  for j := YOrigin to YFinal do
    HorGradientLine(Bitmap, XOrigin, XFinal, j, R1, G1, B1, R2, G2, B2, Smooth);
end;

procedure TJvDrawImage.DrawColumn(X1, Y1, X2, Y2: Integer);
var
  t: Integer;
  R1, G1, B1, R2, G2, B2: Byte;
  line: pbytearray;
begin
  Picture.Bitmap.pixelformat := pf24bit;
  Clip.Assign(Picture.Bitmap);
  Clip.PixelFormat := pf24bit;
  if X1 > X2 then
  begin
    t := X1;
    X1 := X2;
    X2 := t;
  end;
  if Y1 > Y2 then
  begin
    t := Y1;
    Y1 := Y2;
    Y2 := t;
  end;
  line := Clip.ScanLine[Y1];
  R1 := line[0];
  G1 := line[1];
  B1 := line[2];
  line := Clip.ScanLine[Y2];
  R2 := line[X2 * 3];
  G2 := line[X2 * 3 + 1];
  B2 := line[X2 * 3 + 2];
  Column(Clip, X1, X2, Y1, Y2, R1, G1, B1, R2, G2, B2, True);
  Picture.Bitmap.Assign(Clip);
end;

procedure TJvDrawImage.InterpolateRect(Bmp: TBitmap; X1, Y1, X2, Y2: Integer);
// Draws rectangle, which will have different Color in each corner and
// will blend from one Color to another
// ( c[0,0]    c[1,0]
//   c[0,1]    c[1,1] )
type
  TFColor = record b, g, r: Byte
  end;
var
  xCount, yCount,
    t, t2, z, iz,
    rp, rp2, gp,
    gp2, bp, bp2,
    xx: Integer;
  pb: PByteArray;
  c00, c10, c01, c11: TFColor;
begin
  t := 0;
  t2 := 0;
  if X2 < X1 then
  begin
    t := X2;
    X2 := X1;
    X1 := t;
  end;
  if Y2 < Y1 then
  begin
    t := Y2;
    Y2 := Y1;
    Y1 := t;
  end;
  if (X1 < 0) or (Y1 < 0) or (X2 > Bmp.Width - 1) or (Y2 > Bmp.Height - 1) then
    Exit;
  z := 0;
  iz := $100000;
  if X2 <> X1 then
    t := $100000 div (X2 - X1);
  if Y2 <> Y1 then
    t2 := $100000 div (Y2 - Y1);
/////  dx := X2 - X1;
  pb := bmp.ScanLine[Y1];
  c00.r := pb[X1 * 3];
  c00.g := pb[X1 * 3 + 1];
  c00.b := pb[X1 * 3 + 2];
  c01.r := pb[X2 * 3];
  c01.g := pb[X2 * 3 + 1];
  c01.b := pb[X2 * 3 + 2];
  pb := bmp.ScanLine[Y2];
  c10.r := pb[X1 * 3];
  c10.g := pb[X1 * 3 + 1];
  c10.b := pb[X1 * 3 + 2];
  c11.r := pb[X2 * 3];
  c11.g := pb[X2 * 3 + 1];
  c11.b := pb[X2 * 3 + 2];
  for yCount := Y1 to Y2 do
  begin
    xx := ((c00.r * iz + c01.r * z) shr 20);
    rp := xx shl 20;
    rp2 := (((c10.r * iz + c11.r * z) shr 20) - xx) * t;
    xx := ((c00.g * iz + c01.g * z) shr 20);
    gp := xx shl 20;
    gp2 := (((c10.g * iz + c11.g * z) shr 20) - xx) * t;
    xx := ((c00.b * iz + c01.b * z) shr 20);
    bp := xx shl 20;
    bp2 := (((c10.b * iz + c11.b * z) shr 20) - xx) * t;
    pb := bmp.ScanLine[ycount];
    //    pb:=@Bmp.Pixels[yCount,X1];
    for xCount := X1 to X2 do
    begin
      pb[xcount * 3 + 2] := bp shr 20;
      Inc(bp, bp2);
      pb[xcount * 3 + 1] := gp shr 20;
      Inc(gp, gp2);
      pb[xcount * 3] := rp shr 20;
      Inc(rp, rp2);
    end;
    Inc(z, t2);
    Dec(iz, t2);
  end;
end;

procedure TJvDrawImage.InterpRect(X1, Y1, X2, Y2: Integer);
begin
  Picture.Bitmap.pixelformat := pf24bit;
  Clip.Assign(Picture.Bitmap);
  Clip.PixelFormat := pf24bit;
  Interpolaterect(Clip, X1, Y1, X2, Y2);
  Picture.Bitmap.Assign(Clip);
end;

procedure TJvDrawImage.DrawBlurLines(X0, Y0, X, Y: Integer);
begin
  DrawTexLines(X0, Y0, X, Y);
  ClipAll;
  Clip.PixelFormat := pf24bit;
  //GaussianBlur(4);
  UserFilter := Blurfilter;
  applyfilter(Clip, UserFilter);
  Picture.Bitmap.Assign(Clip);
end;

procedure TJvDrawImage.DrawBlurRects(X0, Y0, X, Y: Integer);
begin
  DrawTexRects(X0, Y0, X, Y);
  ClipAll;
  Clip.PixelFormat := pf24bit;
  FX.GaussianBlur(Clip, 4);
  UserFilter := Blurfilter;
  applyfilter(Clip, UserFilter);
  Picture.Bitmap.Assign(Clip);
end;

procedure TJvDrawImage.DrawTexRects(X0, Y0, X, Y: Integer);
var
  dx, dy, xr, yr, X1, Y1, X2, Y2, i, w, h, xi, yi: Integer;
  bcolor, pcolor, hcolor, scolor: TColor;
begin
  w := Width;
  h := Height;
  pcolor := Canvas.Pen.Color;
  bcolor := Canvas.Brush.Color;
  Canvas.Brush.Color := pcolor;
  Canvas.Brush.Style := bssolid;
  hcolor := Texhighlight(pcolor);
  scolor := TexShadow(pcolor);
  xr := Abs(Round(Sqrt(Sqr(X - X0) + Sqr(Y - Y0))));
  dx := Abs(X - X0);
  dy := Abs(Y - Y0);
  if dy < 3 then
    dy := 3;
  if dx < 3 then
    dx := 3;
//  tx := w div dx;
//  ty := h div dy;
  yr := Round(dy / dx * xr);
  yi := 0;
  repeat
    xi := 0;
    repeat
      for i := 1 to 3 do
        with Canvas do
        begin
          X1 := xi + random(xr);
          Y1 := yi + random(yr);
          X2 := xi + random(xr);
          Y2 := yi + random(yr);
          Pen.Color := scolor;
          Brush.Color := scolor;
          Rectangle(X1, Y1, X2 + 2, Y2 + 2);
          Pen.Color := hcolor;
          Brush.Color := hcolor;
          Rectangle(X1 - 2, Y1 - 2, X2, Y2);
          Pen.Color := pcolor;
          Brush.Color := pcolor;
          Rectangle(X1, Y1, X2, Y2);
        end;
      inc(xi, dx);
    until xi > w - 1;
    inc(yi, dy);
  until yi > h - 1;
  Canvas.Pen.Color := pcolor;
  Canvas.Brush.Color := bcolor;
end;

procedure TJvDrawImage.DrawBlurPoly(X0, Y0, X, Y: Integer);
begin
  DrawTexPoly(X0, Y0, X, Y);
  ClipAll;
  Clip.PixelFormat := pf24bit;
  //GaussianBlur(4);
  UserFilter := Blurfilter;
  applyfilter(Clip, UserFilter);
  Picture.Bitmap.Assign(Clip);
end;

procedure TJvDrawImage.DrawTexPoly(X0, Y0, X, Y: Integer);
var
  dx, dy, xr, yr, X1, Y1, X2, Y2, i, w, h, xi, yi: Integer;
  pcolor: TColor;
  points: array[0..3] of TPoint;
begin
  w := Width;
  h := Height;
  pcolor := Canvas.Pen.Color;
//  hcolor := Texhighlight(pcolor);
//  scolor := TexShadow(pcolor);
  xr := Abs(Round(Sqrt(Sqr(X - X0) + Sqr(Y - Y0))));
  dx := Abs(X - X0);
  dy := Abs(Y - Y0);
  if dy < 3 then
    dy := 3;
  if dx < 3 then
    dx := 3;
//  tx := w div dx;
//  ty := h div dy;
  yr := Round(dy / dx * xr);
  yi := 0;
  repeat
    xi := 0;
    repeat
      for i := 1 to 10 do
        with Canvas do
        begin
          X1 := xi + random(xr);
          Y1 := yi + random(yr);
          X2 := xi + random(xr);
          Y2 := yi + random(yr);
          points[0] := Point(X1, Y1);
          points[3] := Point(X2, Y2);
          X1 := xi + random(xr);
          Y1 := yi + random(yr);
          X2 := xi + random(xr);
          Y2 := yi + random(yr);
          points[1] := Point(X1, Y1);
          points[2] := Point(X2, Y2);
          Pen.Color := pcolor;
          polyline(points);
        end;
      inc(xi, dx);
    until xi > w - 1;
    inc(yi, dy);
  until yi > h - 1;
  Canvas.Pen.Color := pcolor;
end;

procedure TJvDrawImage.DrawBlurCurves(X0, Y0, X, Y: Integer);
begin
  DrawTexCurves(X0, Y0, X, Y);
  ClipAll;
  Clip.PixelFormat := pf24bit;
  //GaussianBlur(4);
  UserFilter := Blurfilter;
  applyfilter(Clip, UserFilter);
  Picture.Bitmap.Assign(Clip);
end;

procedure TJvDrawImage.DrawTexCurves(X0, Y0, X, Y: Integer);
var
  dx, dy, xr, yr, X1, Y1, X2, Y2, i, w, h, xi, yi: Integer;
  pcolor: TColor;
  points: array[0..3] of TPoint;
begin
  w := Width;
  h := Height;
  pcolor := Canvas.Pen.Color;
//  hcolor := Texhighlight(pcolor);
//  scolor := TexShadow(pcolor);
  xr := Abs(Round(Sqrt(Sqr(X - X0) + Sqr(Y - Y0))));
  dx := Abs(X - X0);
  dy := Abs(Y - Y0);
  if dy < 3 then
    dy := 3;
  if dx < 3 then
    dx := 3;
//  tx := w div dx;
//  ty := h div dy;
  yr := Round(dy / dx * xr);
  yi := 0;
  repeat
    xi := 0;
    repeat
      for i := 1 to 10 do
        with Canvas do
        begin
          X1 := xi + random(xr);
          Y1 := yi + random(yr);
          X2 := xi + random(xr);
          Y2 := yi + random(yr);
          points[0] := Point(X1, Y1);
          points[3] := Point(X2, Y2);
          X1 := xi + random(xr);
          Y1 := yi + random(yr);
          X2 := xi + random(xr);
          Y2 := yi + random(yr);
          points[1] := Point(X1, Y1);
          points[2] := Point(X2, Y2);
          Pen.Color := pcolor;
          PolyBezier(points);
        end;
      inc(xi, dx);
    until xi > w - 1;
    inc(yi, dy);
  until yi > h - 1;
  Canvas.Pen.Color := pcolor;
end;

procedure TJvDrawImage.ApplyFilter(var Dst: TBitmap; DF: TDigitalFilter);
var
  i, j, X, Y, tmpx, tmpy: Integer;
  Sum,
    Red,
    Green,
    Blue: Integer; //total value
  Tmp,
    Color: TFColor;
  Ptmp, Pcolor: pbytearray;
  bm: TBitmap;
  R: TRect;
begin
  bm := TBitmap.Create;
  bm.pixelformat := pf24bit;
  bm.Width := Dst.Width;
  bm.Height := Dst.Height;
  R := Rect(0, 0, bm.Width, bm.Height);
  bm.Canvas.CopyRect(R, Dst.Canvas, R);
  sum := 0;
  for Y := 0 to 4 do
    for X := 0 to 4 do
      sum := sum + DF[X, Y];
  if Sum = 0 then
    Sum := 1;
  for Y := 0 to Dst.Height - 1 do
  begin
    Pcolor := Dst.ScanLine[Y];
    for X := 0 to bm.Width - 1 do
    begin
      Red := 0;
      Green := 0;
      Blue := 0;
      for i := 0 to 4 do
        for j := 0 to 4 do
        begin
          Tmpy := TrimInt(Y + j - 2, 0, bm.Height - 1);
          Tmpx := TrimInt(X + i - 2, 0, bm.Width - 1);
          ptmp := bm.ScanLine[Tmpy];
          Tmp.r := ptmp[tmpx * 3];
          Tmp.g := ptmp[tmpx * 3 + 1];
          Tmp.b := ptmp[tmpx * 3 + 2];
          //          Tmp:=@Dst.Pixels[TrimInt(Y+j-1,0,Dst.Height-1),
          //                           TrimInt(X+i-1,0,Dst.Width-1)];
          Inc(Blue, DF[i, j] * Tmp.b);
          Inc(Green, DF[i, j] * Tmp.g);
          Inc(Red, DF[i, j] * Tmp.r);
        end;
      Color.b := IntToByte(Blue div Sum);
      Color.g := IntToByte(Green div Sum);
      Color.r := IntToByte(Red div Sum);
      PColor[X * 3] := Color.r;
      Pcolor[X * 3 + 1] := Color.g;
      Pcolor[X * 3 + 2] := Color.b;
    end;
  end;
  bm.Free;
end;

procedure TJvDrawImage.DrawBlurOvals(X0, Y0, X, Y: Integer);
begin
  DrawTexOvals(X0, Y0, X, Y);
  ClipAll;
  Clip.PixelFormat := pf24bit;
  FX.GaussianBlur(Clip, 4);
  UserFilter := Blurfilter;
  applyfilter(Clip, UserFilter);
  Picture.Bitmap.Assign(Clip);

end;

procedure TJvDrawImage.DrawTexOvals(X0, Y0, X, Y: Integer);
var
  dx, dy, xr, yr, X1, Y1, X2, Y2, i, w, h, xi, yi: Integer;
  bcolor, pcolor, hcolor, scolor: TColor;
begin
  w := Width;
  h := Height;
  pcolor := Canvas.Pen.Color;
  bcolor := Canvas.Brush.Color;
  Canvas.Brush.Color := pcolor;
  Canvas.Brush.Style := bssolid;
  hcolor := Texhighlight(pcolor);
  scolor := TexShadow(pcolor);
  xr := Abs(Round(Sqrt(Sqr(X - X0) + Sqr(Y - Y0))));
  dx := Abs(X - X0);
  dy := Abs(Y - Y0);
  if dy < 3 then
    dy := 3;
  if dx < 3 then
    dx := 3;
//  tx := w div dx;
//  ty := h div dy;
  yr := Round(dy / dx * xr);
  yi := 0;
  repeat
    xi := 0;
    repeat
      for i := 1 to 3 do
        with Canvas do
        begin
          X1 := xi + random(xr);
          Y1 := yi + random(yr);
          X2 := xi + random(xr);
          Y2 := yi + random(yr);
          Pen.Color := scolor;
          Brush.Color := scolor;
          Ellipse(X1, Y1, X2 + 2, Y2 + 2);
          Pen.Color := hcolor;
          Brush.Color := hcolor;
          Ellipse(X1 - 2, Y1 - 2, X2, Y2);
          Pen.Color := pcolor;
          Brush.Color := pcolor;
          Ellipse(X1, Y1, X2, Y2);
        end;
      inc(xi, dx);
    until xi > w - 1;
    inc(yi, dy);
  until yi > h - 1;
  Canvas.Pen.Color := pcolor;
  Canvas.Brush.Color := bcolor;
end;

function TJvDrawImage.BlendColors(const Color1, Color2: Longint; Opacity: Integer): Longint;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -