ue4读取外部数据_UE4读取处理PNG像素数据

这篇博客详细介绍了如何在UE4中读取PNG文件的二进制数据,利用ImageWrapper模块将数据转化为UncompressedBGRA格式,然后进行图像数据处理,通过旋转和平移坐标绘制出曲线。
摘要由CSDN通过智能技术生成

const FString ImagePath = TEXT("D:\\1670.png");

if (!FPlatformFileManager::Get().GetPlatformFile().FileExists(*ImagePath)) {

return;

}

TArrayRawFileData;

if (!FFileHelper::LoadFileToArray(RawFileData, *ImagePath)) {

return;

}

IImageWrapperModule& ImageWrapperModule =

FModuleManager::LoadModuleChecked(FName("ImageWrapper"));

IImageWrapperPtr ImageWrapper =

ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);

if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(RawFileData.GetData(),

RawFileData.Num()))

{

const TArray*UncompressedBGRA=NULL;

if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedBGRA))

{

Width = ImageWrapper->GetWidth();

Height = ImageWrapper->GetHeight();

}

}

1、将PNG文件二进制数据读入到 RawFileData;

2、用ImageWrapper模块将RawFileData转换成UncompressedBGRA图像数据。

FVector Location = GetActorLocation();

FRotator Rotator = GetActorRotation();

ULineBatchComponent*LineBatcher = GetWorld()->PersistentLineBatcher;

if (LineBatcher != NULL) {

float offset = 0.0f;

for (int32 j = 0; j < Width; j++) {

offset = j * (XScale * 256 + 0.1);

TArrayLines;

FBatchedLine Line1, Line2;

for (int32 i = 0; i < Height - 2; i += 2) {

Line1.Start = Rotator.RotateVector(FVector(((*UncompressedBGRA)[(i *Width + j) * 4] - 128)*XScale + offset, 0.0f, i *ZScale) + Location);

Line1.End = Rotator.RotateVector(FVector(((*UncompressedBGRA)[((i + 1)*Width + j) * 4] - 128)*XScale + offset, 0.0f, (i + 1)*ZScale) + Location);

Line2.Start = Rotator.RotateVector(FVector(((*UncompressedBGRA)[((i + 1)*Width + j) * 4] - 128)*XScale + offset, 0.0f, (i + 1) *ZScale) + Location);

Line2.End = Rotator.RotateVector(FVector(((*UncompressedBGRA)[((i + 2)*Width + j) * 4] - 128)*XScale + offset, 0.0f, (i + 2) *ZScale) + Location);

Lines.Add(Line1);

Lines.Add(Line2);

}

LineBatcher->DrawLines(Lines);

}

}

3、按列处理图像数据,并绘制曲线

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值