Delphi10.2中FireMonkey中GDIPlus放大图片的Bug,不知道从哪个版本开始的,还是一直都这样。
新建一个FireMonkey工程,窗口上放一个Image控件,WrapMode设置为Stretch,表示随控件大小缩放。指定一张小图。
默认使用D2D的时候放大没问题
关闭D2D使用GDIPlus渲染
initialization
GlobalUseDirect2D := False;
finalization
end.
再看:
边缘多了一圈渐变。
找到FMX.Canvas.GDIP.pas文件,拷贝到我们工程所在目录中。作如下修改
procedure TCanvasGdiPlus.DoDrawBitmap(const ABitmap: TBitmap; const SrcRect, DstRect: TRectF; const AOpacity: Single; const HighSpeed: Boolean); var CM: TColorMatrix; ImageAttributes: TGPImageAttributes; GPBitmap: TGPBitmap; M: TBitmapData; begin if HighSpeed then FGPGraphics.SetInterpolationMode(InterpolationModeNearestNeighbor) else FGPGraphics.SetInterpolationMode(InterpolationModeHighQuality); if (FPrinter <> nil) and not TCanvasManager.DefaultCanvas.InheritsFrom (TCanvasGdiPlus) then begin // In printer if ABitmap.Map(TMapAccess.Read, M) then try GPBitmap := TGPBitmap.Create(ABitmap.Width, ABitmap.Height, M.Pitch, PixelFormat32bppPARGB, M.Data); try if AOpacity < 1 then begin if SameValue(AOpacity, 0, TEpsilon.Vector) then Exit; if not ABitmap.HandleAllocated then Exit; CM := ImageColorMatrix; CM[3][3] := AOpacity; ImageAttributes := TGPImageAttributes.Create; try ImageAttributes.SetColorMatrix(CM, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap); FGPGraphics.DrawImage(GPBitmap, MakeRect(DstRect.Left, DstRect.Top, DstRect.Right - DstRect.Left, DstRect.Bottom - DstRect.Top), SrcRect.Left, SrcRect.Top, SrcRect.Right - SrcRect.Left, SrcRect.Bottom - SrcRect.Top, UnitPixel, ImageAttributes); finally ImageAttributes.Free; end; end else begin if not ABitmap.HandleAllocated then Exit; FGPGraphics.DrawImage(GPBitmap, MakeRect(DstRect.Left, DstRect.Top, DstRect.Right - DstRect.Left, DstRect.Bottom - DstRect.Top), SrcRect.Left, SrcRect.Top, SrcRect.Right - SrcRect.Left, SrcRect.Bottom - SrcRect.Top, UnitPixel); end; finally GPBitmap.Free; end; finally ABitmap.Unmap(M); end; Exit; end; if AOpacity < 1 then begin if SameValue(AOpacity, 0, TEpsilon.Vector) then Exit; if not ABitmap.HandleAllocated then Exit; CM := ImageColorMatrix; CM[3][3] := AOpacity; ImageAttributes := TGPImageAttributes.Create; try ImageAttributes.SetColorMatrix(CM, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap); FGPGraphics.DrawImage(TGPBitmap(ABitmap.Handle), MakeRect(DstRect.Left, DstRect.Top, DstRect.Right - DstRect.Left, DstRect.Bottom - DstRect.Top), SrcRect.Left, SrcRect.Top, SrcRect.Right - SrcRect.Left, SrcRect.Bottom - SrcRect.Top, UnitPixel, ImageAttributes); finally ImageAttributes.Free; end; end else begin if not ABitmap.HandleAllocated then Exit; ImageAttributes := TGPImageAttributes.Create; try ImageAttributes.SetWrapMode(WrapModeTileFlipXY); FGPGraphics.DrawImage(TGPBitmap(ABitmap.Handle), MakeRect(DstRect.Left, DstRect.Top, DstRect.Right - DstRect.Left, DstRect.Bottom - DstRect.Top), SrcRect.Left, SrcRect.Top, SrcRect.Right - SrcRect.Left, SrcRect.Bottom - SrcRect.Top, UnitPixel, ImageAttributes); finally ImageAttributes.Free; end; end; end;
关键点在于ImageAttributes.SetWrapMode(WrapModeTileFlipXY);
不错。学习了。
Pingback引用通告: Coronavirus real-time updates
Pingback引用通告: PSYCHOSOCIAL
Pingback引用通告: Cherekasi
Pingback引用通告: Film Doktor Liza (2020)
Pingback引用通告: film djoker
Pingback引用通告: viagra
Pingback引用通告: Îíëàéí Ïñèõîëîã
Pingback引用通告: generic viagra
Pingback引用通告: viagra over the counter
Pingback引用通告: buy viagra online
Pingback引用通告: viagra pill
Pingback引用通告: otc viagra
Pingback引用通告: generic cialis
Pingback引用通告: cialis online
Pingback引用通告: cialis price
Pingback引用通告: buy cialis online
Pingback引用通告: bitly.com
Pingback引用通告: Earthlings 2005
Pingback引用通告: viagra 100mg
Pingback引用通告: smotret onlajn v horoshem kachestve hd
Pingback引用通告: movies-unhinged-film
Pingback引用通告: Dom 2
Pingback引用通告: zoom-viber-skype
Pingback引用通告: Cherkassy
Pingback引用通告: chernobyl-hbo-2020-1-sezon-2-sezon
Pingback引用通告: batmanapollo.ru
Pingback引用通告: dom2 ru
Pingback引用通告: psy psy psy psy
Pingback引用通告: krsmi.ru
Pingback引用通告: HD
Pingback引用通告: Human design
Pingback引用通告: 1445
Pingback引用通告: cleantalkorg2.ru
Pingback引用通告: vk login