1

【UE4/C++】读取贴图资源像素颜色值

 1 year ago
source link: https://1keven1.github.io/2021/07/30/%E3%80%90UE4_C-%E3%80%91%E8%AF%BB%E5%8F%96%E8%B4%B4%E5%9B%BE%E8%B5%84%E6%BA%90%E5%83%8F%E7%B4%A0%E9%A2%9C%E8%89%B2%E5%80%BC/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

SuzhiのBlog

【UE4/C++】读取贴图资源像素颜色值

发表于2021-07-30|更新于2023-01-16|技术笔记学习笔记UE4
字数总计:179|阅读时长:1分钟|阅读量:84|评论数:

之前踩的坑,网上都说是对Bulkdata进行操作,但是实操会报错闪退,大概是因为内部的贴图压缩过还存有其他数据,bulkdata里面不只有像素数据。正确的方法是获得source然后使用GetMipData函数直接获取。

void UFunctionLibrary::ReadTexture(UTexture2D* Src)
{
TArray64<uint8> RawData;
if (Src->Source.IsValid() && Src->Source.GetFormat() == TSF_BGRA8)
{
Src->Source.GetMipData(RawData, 0);
}
else
{
UE_LOG(LogTexture, Warning, TEXT("%s: Source Not Available"), *Src->GetName());
return;
}
FColor* SrcColor = reinterpret_cast<FColor*>(RawData.GetData());
}

然后可以处理后传出FColor数组,使用我之前写过的创建贴图资源的函数直接储存贴图,也就是这篇文章


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK