问题
I'm using ImageMagick (Magick++) in my application but when trying to load an image I get the error:
Unable to open image '??': Invalid argument @ error/blob.c/OpenBlob/2657
From reading other peoples problems online ??
is typically the file trying to be loaded, and I am obviously not passing the file location ??
to the loader - so it appears not to be able to resolve the string I am giving it. Tried using Unicode and Multi-byte. Copied project settings from example(s). File definitely exists and definitely the correct location.
Code:
LawlessFBXTexture* LawlessFBXTextureManager::CreateTexture(std::string pFullFilePath)
{
Magick::Image* img = nullptr;
Magick::Blob blob;
try
{
img = new Magick::Image();
img->read(pFullFilePath);
img->write(&blob, "RGBA");
}
catch (Magick::Error& Err)
{
std::string errstr = Err.what();
std::wstring stemps = std::wstring(errstr.begin(), errstr.end());
LPCWSTR sws = stemps.c_str();
OutputDebugString(L"FBXSDK: ERROR: ");
OutputDebugString(sws);
OutputDebugString(L"\n");
int ImageNotFound = 0; /// Image Not found <---
assert(ImageNotFound);
}
LawlessFBXTexture* tex = new LawlessFBXTexture();
glGenTextures(1, &tex->TextureBuffer);
glBindTexture(GL_TEXTURE_2D, tex->TextureBuffer);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->columns(), img->rows(), 0, GL_RGBA, GL_UNSIGNED_BYTE, blob.data());
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
return tex;
}
being called by :
LawlessFBXTexture* tex = CreateTexture("..\\..\\Asset\\Models\\LawlessCoreAsset\\DEFAULT_DIFFUSE.png");
回答1:
I noticed this works fine in release mode, without making changes. I am pretty sure this is down to a bug so I'll post my findings on the Magick forums.
回答2:
So, after taking the OP's advice and setting my project to release mode, everything worked perfectly. That said, I very quickly realized that there is a VERY good reason for Debug mode to exist. Writing code for a program that doesn't give run-time error messages is an absolute pain in the *** to do. Not to mention all of your favorite conveniences like breakpoints, assertions, and such are gone.
Turns out, despite offering multiple binary distributions for each platform, there are no developer binaries available at all. By which I mean, if you want to be able to debug your program while using the Magick++ libraries, you MUST compile your DLLs from source (using the debug configuration to compile those DLLs). Only then can you use the Debug compilation mode for your projects which link against it.
Here's the thread I found that discusses this. Note that in the thread it says to build static libs, but this is obviously not necessary, and it's probably more convenient to build using the dynamic libraries option.
Anyway, if you follow the steps enumerated in the link I provide, you should finally be able to debug your Magick++ program without pulling your hair out :)
回答3:
For some reason, Magick++ on Visual Studio does not like the /MTd option
Configuration Properties->C++->Code Generation->Runtime Library
Setting
it on /MT should work fine.
来源:https://stackoverflow.com/questions/23684903/imagemagick-error-unable-to-open-image