I have this code
DirectX::ScratchImage DSResizedImage;
DirectX::Resize(*tex->DSImage.GetImage(0,0,0), tex->scaleX, tex->scaleY,
DirectX::TEX_FILTER_FLAGS::TEX_FILTER_DEFAULT, DSResizedImage);
DirectX::Image Resized1 = *DSResizedImage.GetImage(0, 0, 0);
which returns an empty Image.
However, it does work when using what should be the equivalent with OpenCV
std::string save = fullSavePath + tex->hash + ".PNG";
tex->tex2Other(fullSavePath + tex->hash + ".dds", "png");
cv::Mat cvIm = cv::imread(save, cv::IMREAD_UNCHANGED);
if (cvIm.empty())
{
printf("Tex not written!");
exit(1);
}
cvIm.copyTo(res(cv::Rect(tex->offsetX, tex->offsetY, tex->scaleX, tex->scaleY)));
The problem with using the OpenCV solution is that sometimes users will get this error when resizing (which I can't get to replicate on my computer in debug):
OpenCV(4.5.3) Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in cv::Mat::Mat, file C:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\matrix.cpp, line 811
For this specific image, it's dimensions (and scaleX/scaleY) are 2048x1024. Any help would be very appreciated! :)
The DirectXTex function Resize was returning a failed HRESULT: E_NOINTERFACE
. This happens when you use DirectXTex methods that use the Windows Imaging Component (WIC) without initializing COM on the calling thread.
Note that for Windows Runtime applications (such as UWP and/or C++/WinRT), COM is initialized as part of the Windows Runtime initialization.
This issue is documented on the DirectXTex wiki.