|
如何读写UTexture2D的像素值?
- void ADynamicTexture::capture()
- {
- cv::Mat img = cv::imread("D:\\img.jpg");
-
- UTexture2D *ut2 = UTexture2D::CreateTransient(img.size().width, img.size().height);
- ut2->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
- ut2->SRGB = 0;
- ut2->AddToRoot();
- ut2->UpdateResource();
- FTexture2DMipMap &mip = ut2->PlatformData->Mips[0];
- void *data = mip.BulkData.Lock(LOCK_READ_WRITE);
- FMemory::Memcpy(data, img.data, img.size().width * img.size().height);
- mip.BulkData.Unlock();
- ut2->UpdateResource();
- matInst->SetTextureParameterValue(FName("DTexture"), ut2);
- mesh->SetMaterial(0, matInst);
- }
应该改为:
- auto stride = (int32)( sizeof(uint8) * 4 ); // for r, g, b, a
- FMemory::Memcpy(data, img.data, img.size().width * img.size().height * stride);
-
|
|