Graphics32 TBitmap32.Assign()有什么问题?为什么对于TBitmap32不能保留原始图像的透明度,而对于TBitmap来说一切都很好?这是示例代码:
public class ActivityTwo extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two);
textView = (TextView)findViewById(R.id.tv);
Bundle bundle = getIntent().getExtras();
textView.setText(bundle.getString("value"));
}
}
这是Graphics32库(版本是github上的最新版本)错误吗?还是TWICImage错误?还是Delphi 10.2.3错误?还是我做错了什么?如何解决这个问题?
答案 0 :(得分:1)
我想我已经找到了解决方案。我向GR32
过程的嵌套过程AssignFromGraphic
的{{1}}模块添加了几行:
TCustomBitmap32.Assign
我添加了一些额外的检查,并更改了 procedure AssignFromGraphic(TargetBitmap: TCustomBitmap32; SrcGraphic: TGraphic);
begin
if SrcGraphic is TBitmap then
AssignFromBitmap(TargetBitmap, TBitmap(SrcGraphic))
else if SrcGraphic is TIcon then
AssignFromIcon(TargetBitmap, TIcon(SrcGraphic))
{$IFNDEF PLATFORM_INDEPENDENT}
else if SrcGraphic is TMetaFile then
AssignFromGraphicMasked(TargetBitmap, SrcGraphic)
{$ENDIF}
//--- start fix
else if (SrcGraphic is TWICImage) and (TWICImage(SrcGraphic).ImageFormat = wifPng) then
AssignFromGraphicPlain(TargetBitmap, SrcGraphic, $00FFFFFF, False)
//--- end fix
else
AssignFromGraphicPlain(TargetBitmap, SrcGraphic, clWhite32, True);
end;
的两个参数
使用procedure AssignFromGraphicPlain(TargetBitmap: TCustomBitmap32; Src Graphic: TGraphic; FillColor: TColor32; ResetAlphaAfterDrawing: Boolean);
(带有alpha通道= 0的clWhite32)和FillColor = $00FFFFFF
,现在可以保留原始PNG图像的透明度。它看起来像是个肮脏的把戏,但它有效!
当然,我想听听更权威的意见,所以我不会接受我的回答。可能有另一种方法,而不更改Graphics32库的源代码。