Click here to Skip to main content
15,915,611 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting following error while compressing the dcm file on following line.

ImageReader reader = new ImageReader();

Error:

The type initializer for 'gdcm.gdcmPINVOKE' threw an exception.

How to resolve this Error?

I am using gdcm-sharp.dll for compressing the file.

What I have tried:

I am using gdcm-sharp.dll for compressing the file.

I am posting my Code here:
private void button1_Click(object sender, EventArgs e)
{
string inputFileNamepath = @"G:\Test\Test_07_06_2016\Source\BU001015MN-166-CL-001V01_2005101414120923_1_1.dcm";
string outputFileNamepath =@"G:\Test\Test_07_06_2016\Source1\GDCMBU001015MN-166-CL-001V01_2005101414120923_1_1.dcm";

//FileInfo file = new FileInfo(@"G:\Test\Test_07_06_2016\Source\BU001015MN-166-CL-001V01_2005101414120923_1_1.dcm");

string extension = Path.GetExtension(inputFileNamepath);
inputFileNamepath = Path.GetFileName(inputFileNamepath);

outputFileName = Path.GetFileName(outputFileNamepath);

try
{
ImageReader reader = new ImageReader();//getting error on this file
reader.SetFileName(inputFileName);

if (!reader.Read())
{
MessageBox.Show("Cannot Read the file:-" + inputFileName);
return;
}

gdcm.File file = reader.GetFile();

gdcm.DataSet ds = file.GetDataSet();
gdcm.Image image = reader.GetImage();

ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();
TransferSyntax targets = new TransferSyntax(TransferSyntax.TSType.JPEGBaselineProcess1);
change.SetTransferSyntax(targets);

JPEGCodec codec = new JPEGCodec();

if(!codec.CanCode(targets))
{
MessageBox.Show("WrongData");
return;
}
codec.SetLossless(false);
codec.SetQuality(50);
change.SetUserCodec(codec);
change.SetInput(image);

bool b = change.Change();

if (!b)
{
MessageBox.Show("Can not change Ttansfer Syntax");
return;
}

ImageWriter writer = new ImageWriter();
writer.SetImage((gdcm.Image)change.GetOutput());
writer.SetFile(reader.GetFile());
writer.SetFileName(outputFileName);

if (!writer.Write())
{
MessageBox.Show("Could not write");
}




}
catch (Exception ex)
{

}


}
Posted
Comments
BillWoodruff 18-Jun-16 3:45am    
You need to post more detail on the specific error message you are receiving.

Why don't use the GDCM support mailing list facility to ask your question:

https://sourceforge.net/projects/gdcm/support

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900