[Magick-bugs] About Imagemagik++ Problem
Anu Singla
anu.aquevix at gmail.com
Mon Jun 29 05:58:43 PDT 2009
Hello,
We are running into a problem and we are wondering if you have solution for
this.
We have used Imagemagik++ in our application. We are using it in Asp.Net.
We wrote a wrapper in c++/CLR so that we can use this in our web
application.
To calculate pixel count (By Image Magik) we are using the code snippet as
below:
double ImageMagikWrapper::MagicHelper::WhiteRatio(System::String^ str)
{
// Atomic locked increment for initialization of this library.
if(System::Threading::Interlocked::Increment(init__) == 1)
{
Magick::InitializeMagick(NULL);
}
double retVal = 0.0;
std::string filename;
MagicHelper::MarshalString(str, filename);
Magick::Image img;
HistogramMap histogram;
try {
img.read(filename);
filename = filename.replace(filename.rfind(".pdf",
filename.length()),4,".gif");
Magick::Blob gifFile;
img.magick("GIF");
img.write(&gifFile);
Image gifImg;
gifImg.read(gifFile);
colorHistogram(&histogram, gifImg);
}
catch(...)
{
return ErrorValue;
}
// Code here.
unsigned long nonWhiteCount = 0;
unsigned long whiteCount = 0;
double div = 0;
double whitePercentage = 0;
for(HistogramMap::iterator iter = histogram.begin(); iter !=
histogram.end(); ++iter)
{
Quantum qRed = iter->first.redQuantum();
Quantum qGreen = iter->first.greenQuantum();
Quantum qBlue = iter->first.blueQuantum();
if(whiteCount==0 && qRed == 65535 && qGreen==65535 && qBlue==65535)
whiteCount=(unsigned long)iter->second;
else
nonWhiteCount+=(unsigned long)iter->second;
}
unsigned long total=whiteCount+nonWhiteCount;
div=(double)whiteCount/(double)total;
retVal=div*100;
return retVal;
}
// Helper to convert C# string to C++ std::string
void ImageMagikWrapper::MagicHelper::MarshalString (System::String ^ s,
std::string& os )
{
using namespace System::Runtime::InteropServices;
const char* chars = (const
char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
os = chars;
Marshal::FreeHGlobal(System::IntPtr((void*)chars));
}
It is working fine when we are running it on one web application. But When
we try to run it on two web application simultaneously it is giving an error
as:
System.TypeInitializationException: The type initializer for '<Module>'
threw an exception. --->
System.TypeInitializationException: The type initializer for '<Module>'
threw an exception. ---> <CrtImplementationDetails>.ModuleLoadException:
The C++ module failed to load. --->
<CrtImplementationDetails>.OpenMPWithMultipleAppdomainsException: Exception
of type '<CrtImplementationDetails>.OpenMPWithMultipleAppdomainsException'
was thrown.
at <CrtImplementationDetails>.DoDllLanguageSupportValidation()
at
<CrtImplementationDetails>.LanguageSupport._Initialize(LanguageSupport* )
at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport*
)
--- End of inner exception stack trace ---
at <CrtImplementationDetails>.ThrowModuleLoadException(String
errorMessage, Exception innerException)
at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport*
)
at .cctor()
--- End of inner exception stack trace ---
at <CrtImplementationDetails>.ThrowModuleLoadException(String , Exception
)
at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport*
)
at .cctor()
--- End of inner exception stack trace ---
at
JustPrintCWI.SourceCode.Controller.WhiteRatioPercentage.CalculateWhitePercentage(String
filename)
at app_UploadFile.doUploadPDF(Decimal toUploadFileSize, String filename,
String filepath, String savefilename, Decimal foldersize)
at app_UploadFile.btnUpload_Click(Object sender, ImageClickEventArgs e)
at System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
at System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String
eventArgument)
at
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Please give us the workaround for this problem. We are into mid of the
project.
Thanks a lot in advance.
Thanks & Regards
Anu Singla
S/W Developer
Aquevix Solutions Pvt.Ltd.
More information about the Magick-bugs
mailing list