UE SetBrushFromTexture加载图片到控件
原创
©著作权归作者所有:来自51CTO博客作者fengyuzaitu的原创作品,请联系作者获取转载授权,否则将追究法律责任
/**
* Sets the Brush to the specified Texture.
*
* @param Texture Texture to use to set on Brush.
* @param bMatchSize If true, image will change its size to texture size. If false, texture will be stretched to image size.
*/
UFUNCTION(BlueprintCallable, Category="Appearance")
virtual void SetBrushFromTexture(UTexture2D* Texture, bool bMatchSize = false);
void UImage::SetBrushFromTexture(UTexture2D* Texture, bool bMatchSize)
{
CancelImageStreaming();
if(Brush.GetResourceObject() != Texture)
{
Brush.SetResourceObject(Texture);
if (Texture) // Since this texture is used as UI, don't allow it affected by budget.
{
Texture->bForceMiplevelsToBeResident = true;
Texture->bIgnoreStreamingMipBias = true;
}
if (bMatchSize)
{
if (Texture)
{
Brush.ImageSize.X = Texture->GetSizeX();
Brush.ImageSize.Y = Texture->GetSizeY();
}
else
{
Brush.ImageSize = FVector2D(0, 0);
}
}
if (MyImage.IsValid())
{
MyImage->SetImage(&Brush);
}
}
}