Esempio n. 1
0
	void screenshot(const string& name)
	{
#ifndef WINSTORE_SUPPORT
		CreateDirectoryA("screenshots", 0);
		time_t t = std::time(nullptr);
		struct tm time_info;
		localtime_s(&time_info, &t);
		stringstream ss("");
		if (name.length() <= 0)
			ss << "screenshots/sc_" << std::put_time(&time_info, "%d-%m-%Y %H-%M-%S") << ".png";
		else
			ss << name;
		wstringstream wss(L"");
		wss << ss.str().c_str();
		ID3D11Resource* res = nullptr;
		wiRenderer::renderTargetView->GetResource(&res);
		HRESULT h = SaveWICTextureToFile(wiRenderer::immediateContext, res, GUID_ContainerFormatPng, wss.str().c_str());
		if (FAILED(h))
			wiBackLog::post("Screenshot failed");
		else
		{
			ss << " Saved successfully!";
			wiBackLog::post(ss.str().c_str());
		}
		res->Release();
#endif
	}
Esempio n. 2
0
//===============================================================================================================================
void TextureManager::WritePNGToFile(LPCWSTR filename, ID3D11ShaderResourceView* textureSRV)
{
    ID3D11Texture2D *textureInterface = 0;
    ID3D11Resource *textureResource;
    textureSRV->GetResource(&textureResource);
    textureResource->QueryInterface<ID3D11Texture2D>(&textureInterface);

    HRESULT result;
    result = SaveWICTextureToFile(mD3DSystem->GetDeviceContext(), textureInterface, GUID_ContainerFormatPng, filename);

    if (FAILED(result))
    {
        ScratchImage image;
        result = CaptureTexture(mD3DSystem->GetDevice11(), mD3DSystem->GetDeviceContext(), textureInterface, image);

        if (SUCCEEDED(result))
        {
            result = SaveToWICFile(image.GetImages(), image.GetImageCount(), WIC_FLAGS_NONE, GUID_ContainerFormatPng, filename);

            if (FAILED(result))
            {
                ZShadeMessageCenter::MsgBoxError(NULL, "Failed to save PNG texture !!");
            }
        }
    }

    SAFE_RELEASE(textureInterface);
    SAFE_RELEASE(textureResource);
}