如何将TGPGraphics内容绘制到Canvas上

时间:2016-12-22 00:32:23

标签: delphi canvas gdi+

我正在尝试将以下TGPGraphics的内容复制到Canvas上,但它不起作用。我在这里缺少什么?

    var arrayOfSongs = [
        {"title":"Blue","duration":161.71,"audioUrl":"/assets/music/blue","playing":false,"playedAt":"2016-12-21T22:58:55.203Z"},
        {"title":"Blue","duration":161.71,"audioUrl":"/assets/music/blue","playing":false,"playedAt":"2016-12-21T22:58:55.203Z"},
        {"title":"Blue","duration":161.71,"audioUrl":"/assets/music/blue","playing":false,"playedAt":"2016-12-21T22:58:55.203Z"},
        {"title":"Green","duration":161.71,"audioUrl":"/assets/music/blue","playing":false,"playedAt":"2016-12-21T22:58:55.203Z"}
    ];

    var obj = arrayOfSongs.reduce(function(acc, cv) {
       acc[cv.title] = (acc[cv.title] || 0) + 1;
       return acc;
    }, {});

    // *** added code starts here ***
    var newArrayOfSongs = Object.keys(obj).map(function(title) { 
        return {
            title: title, 
            playCount:obj[title]
        };
    });

    console.log(newArrayOfSongs);

1 个答案:

答案 0 :(得分:2)

您可以使用构造函数

直接将TGPGraphics绘制到Canvas上
TGPGraphics.Create(hdc: HDC)

您也不需要O: TGPBitmap例如:

function DrawGlyph(bm: TObject; Canvas: TCanvas; X, Y: Integer): Integer;
var
  G: TGPGraphics;
begin
  // Result := ???
  if (bm is TGPImage) then
  begin
    Canvas.Lock;
    try
      G := TGPGraphics.Create(Canvas.Handle);
      try
        G.SetCompositingMode(CompositingModeSourceCopy);
        G.SetInterpolationMode(InterpolationModeHighQualityBicubic);
        G.SetPixelOffsetMode(PixelOffsetModeHighQuality);
        G.SetSmoothingMode(SmoothingModeHighQuality);
        G.DrawImage(TGPImage(bm), X, Y, 16, 16);
      finally
        G.Free;
      end;
    finally
      Canvas.Unlock;
    end;
  end;
end;