读取UTexture2D的像素值

void AMyRenderTarget::setMyRenderTarget(UTextureRenderTarget2D* textureRenderTarget)
{
	m_textureRenderTarget = textureRenderTarget;
	m_Texture = textureRenderTarget->ConstructTexture2D(this, FString("Snapshot"), EObjectFlags::RF_NoFlags);
}

void AMyRenderTarget::GrabMyRenderTarget()
{
	TextureCompressionSettings OldCompressionSettings = m_Texture->CompressionSettings; 
	//TextureMipGenSettings OldMipGenSettings = m_Texture->MipGenSettings; 
	bool OldSRGB = m_Texture->SRGB;

	m_Texture->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
	//m_Texture->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
	m_Texture->SRGB = false;
	m_Texture->UpdateResource();

	FColor* FormatedImageData = static_cast<FColor*>(m_Texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_ONLY));
	int j = 0;
	for (int32 y = 0; y < m_Texture->PlatformData->Mips[0].SizeY; y++)
	{
		for (int32 x = 0; x < m_Texture->PlatformData->Mips[0].SizeX; x++)
		{
			int32 curPixelIndex = (y * m_Texture->PlatformData->Mips[0].SizeX) + x;
			FColor pixel = FormatedImageData[curPixelIndex];
			m_buf[j++] = pixel.B;
			m_buf[j++] = pixel.G;
			m_buf[j++] = pixel.R;
		}
	}
	m_Texture->PlatformData->Mips[0].BulkData.Unlock();

	m_Texture->CompressionSettings = OldCompressionSettings;
	//m_Texture->MipGenSettings = OldMipGenSettings;
	m_Texture->SRGB = OldSRGB;
	m_Texture->UpdateResource();

	grabBmp(m_Texture->PlatformData->Mips[0].SizeX, m_Texture->PlatformData->Mips[0].SizeY, 0, m_buf);

	GEngine->AddOnScreenDebugMessage((uint64)-1, 2.0f, FColor::Emerald, FString::Printf(TEXT("width = %d height = %d num = %d"), m_Texture->PlatformData->Mips[0].SizeX, m_Texture->PlatformData->Mips[0].SizeY));
}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值