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、按列处理图像数据,并绘制曲线