我希望使HeidiSQL适应高dpi,这包括放大我的一个TImageList,其中有许多alpha-transparent PNG图标。
我已经编写了一个过程来实现它,但它会破坏正常透明度和alpha-transparency,因此图标看起来非常破碎,特别是在边缘处。 这是代码:
我也尝试了一些Žarko Gajić的代码,但那只是从图像中去除了透明度,甚至没有实际缩放。
Paint.net在其图标上进行了良好的缩放,但它是用C#编写的,所以这没有什么帮助。
我已经编写了一个过程来实现它,但它会破坏正常透明度和alpha-transparency,因此图标看起来非常破碎,特别是在边缘处。 这是代码:
procedure ScaleImageList(const ImgList: TImageList; ScaleFactor: Real);
var
i: Integer;
Extracted, Scaled: Graphics.TBitmap;
ImgListCopy: TImageList;
begin
if ScaleFactor = 1 then
Exit;
// Create copy of original image list
ImgListCopy := TImageList.Create(nil);
ImgListCopy.ColorDepth := cd32Bit;
ImgListCopy.DrawingStyle := dsTransparent;
ImgListCopy.Clear;
// Add from source image list
for i := 0 to ImgList.Count-1 do begin
ImgListCopy.AddImage(ImgList, i);
end;
// Set size to match scale factor
ImgList.SetSize(Round(ImgList.Width * ScaleFactor), Round(ImgList.Height * ScaleFactor));
for i:= 0 to ImgListCopy.Count-1 do begin
Extracted := Graphics.TBitmap.Create;
ImgListCopy.GetBitmap(i, Extracted);
Scaled := Graphics.TBitmap.Create;
Scaled.Width := ImgList.Width;
Scaled.Height := ImgList.Height;
Scaled.Canvas.FillRect(Scaled.Canvas.ClipRect);
GraphUtil.ScaleImage(Extracted, Scaled, ScaleFactor);
ImgList.Add(Scaled, Scaled);
end;
ImgListCopy.Free;
end;
我也尝试了一些Žarko Gajić的代码,但那只是从图像中去除了透明度,甚至没有实际缩放。
Paint.net在其图标上进行了良好的缩放,但它是用C#编写的,所以这没有什么帮助。
SmoothResize
过程,他是现在已经停用的PNGDelphi组件的作者。有关整个代码,请参见Github上相关的提交。 - Anse