参数说明: 源2D纹理图片:UTexture2D* SourceTexture 裁剪区域的左上角:const FVector2D TopLeft 裁剪区域的右下角:const FVector2D BottomRight 返回值是裁剪之后的纹理图片
UTexture2D* APointProjection::CropPicture(UTexture2D* SourceTexture,const FVector2D TopLeft, const FVector2D BottomRight){if (!SourceTexture || !SourceTexture->IsValidLowLevel()){UE_LOG(LogTemp, Error, TEXT("value error"));return SourceTexture;}int32 TextureWidth = BottomRight.X - TopLeft.X;int32 TextureHeight = BottomRight.Y - TopLeft.Y;UE_LOG(LogTemp, Error, TEXT("TextureWidth is %d TextureHeight is %d"), TextureWidth, TextureHeight);const uint8* FormatedImageData = static_cast<const uint8*>(SourceTexture->PlatformData->Mips[0].BulkData.LockReadOnly());TUniquePtr<uint8[]> ClippedTextureData(new uint8[TextureWidth * TextureHeight * 4]);UE_LOG(LogTemp, Error, TEXT("FormatedImageData %p"), FormatedImageData);for (int32 y = TopLeft.Y; y < BottomRight.Y - 1; y++) //减去一是为了防止类型转换而导致越界{for (int32 x = TopLeft.X; x < BottomRight.X - 1; x++){int32 m_x = x - TopLeft.X;int32 m_y = y - TopLeft.Y;int32 curPixelIndex1 = (m_y * TextureWidth + m_x);int32 curPixelIndex2 = (y * SourceTexture->GetSizeX() + x);// 将当前像素颜色添加到像素数组中,注意 BGRA 通道的顺序ClippedTextureData[curPixelIndex1 * 4] = FormatedImageData[curPixelIndex2 * 4];ClippedTextureData[curPixelIndex1 * 4 + 1] = FormatedImageData[curPixelIndex2 * 4 + 1];ClippedTextureData[curPixelIndex1 * 4 + 2] = FormatedImageData[curPixelIndex2 * 4 + 2];ClippedTextureData[curPixelIndex1 * 4 + 3] = FormatedImageData[curPixelIndex2 * 4 + 3];}}// 解锁 MipMapSourceTexture->PlatformData->Mips[0].BulkData.Unlock();写操作UTexture2D* CropTexture = UTexture2D::CreateTransient(TextureWidth, TextureHeight, SourceTexture->GetPixelFormat());void* TextureData = CropTexture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);FMemory::Memcpy(TextureData, ClippedTextureData.Get(), sizeof(uint8) * TextureHeight * TextureWidth * 4);CropTexture->PlatformData->Mips[0].BulkData.Unlock();CropTexture->UpdateResource();return CropTexture;}【UE4虛幻】UTexture2D纹理裁剪函数,g9x(ue4 虚拟纹理)
cpugpu芯片开发光刻机
智能终端演进
13
文件名:【UE4虛幻】UTexture2D纹理裁剪函数,g9x
【UE4虛幻】UTexture2D纹理裁剪函数
同类推荐
-

【PTA-C语言】编程练习3 - 循环结构Ⅱ,国产精品手机网站
查看 -

【Proteus仿真】【51单片机】电蒸锅温度控制系统,酷派9960(51单片机智能电饭锅控制系统)
查看 -

【Qt之QtXlsx模块】安装及使用,ap2496
查看 -

【R3F】0.8drei使用,lg km710
查看 -

【RK3399Pro学习笔记】十五、ROS中launch启动文件的使用方法,quake4(ros 启动)
查看 -

【RUST】HashMap、vector和String,色域网(rust hashmap)
查看 -

【React】React入门,wiseie(react 入门)
查看 -

【Redis7】--3.Redis持久化,华硕a10(redis持久化rdb和aof)
查看 -

【Redis】Lua脚本在Redis中的基本使用及其原子性保证原理,ndsi ll
查看
控制面板
网站分类
搜索
最新留言
文章归档
网站收藏
友情链接