public string LoadImageFromFile(string graphicfilename)
{
Image image = null;
try
{
image = Image.FromFile(graphicfilename);
}
catch (OutOfMemoryException e)
{
throw new AODLGraphicException(string.Format(
"file '{0}' contains an unrecognized image", graphicfilename), e);
}
Graphics graphics = null;
try
{
graphics = Graphics.FromImage(image);
}
catch (Exception e)
{
throw new AODLGraphicException(string.Format(
"file '{0}' contains an unrecognized image. I could not" +
" create graphics object from image {1}", graphicfilename, image), e);
}
this._widthInPixel = image.Width;
this._heightInPixel = image.Height;
this._dPI_X = (int)graphics.DpiX;
this._dPI_Y = (int)graphics.DpiY;
this._measurementFormat = "cm";
this._width = AODL.Document.Helper.SizeConverter.GetWidthInCm(image.Width, this._dPI_X);
this._height = AODL.Document.Helper.SizeConverter.GetHeightInCm(image.Height, this._dPI_Y);
if (this.SvgHeight == null && this.SvgWidth == null)
{
this.SvgHeight = this._height.ToString("F3")+ this._measurementFormat;
if (this.SvgHeight.IndexOf(",", 0) > -1)
this.SvgHeight = this.SvgHeight.Replace(",",".");
this.SvgWidth = this._width.ToString("F3")+ this._measurementFormat;
if (this.SvgWidth.IndexOf(",", 0) > -1)
this.SvgWidth = this.SvgWidth.Replace(",",".");
}
else
{
// This should only reached, if the file is loading by a importer.
if (AODL.Document.Helper.SizeConverter.IsCm(this.SvgWidth))
{
this._measurementFormat = "cm";
}
else
{
this._measurementFormat = "in";
}
}
graphics.Dispose();
image.Dispose();
return new FileInfo(graphicfilename).Name;
}