Hello, in this code:
m_eAsposeType = eAsposeType.DwgImages;
m_oDocument = Aspose.CAD.Image.Load(_oInputStream);
//resize fatto qui da poi errore, quindi lo fa nei metodi pubblici
/*
if (((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Width > ((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Height)
{
if (((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Width > 1024)
{
int iWidth = 1024;
int iHeight = (int)((1024.0f / (float)((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Width) * (float)((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Height);
((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Resize(iWidth, iHeight, Aspose.CAD.ResizeType.NearestNeighbourResample);
}
}
else
{
if (((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Height > 1024)
{
int iHeight = 1024;
int iWidth = (int)((1024.0f / (float)((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Height) * (float)((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Width);
((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Resize(iWidth, iHeight, Aspose.CAD.ResizeType.NearestNeighbourResample);
}
}
* */
if (((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Layouts.Count > 0)
{
m_iPageCount = ((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Layouts.Count;
}
else
{
m_iPageCount = 1; // ((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Layers.Count;
}
the parte reguarding the resize is commented and reported in the next code
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = ((Aspose.CAD.Image)m_oDocument).Width;
rasterizationOptions.PageHeight = ((Aspose.CAD.Image)m_oDocument).Height;
//resize fatto qui perchè lo fa nel costruttore
if (((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Width > ((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Height)
{
if (((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Width > 1024)
{
int iWidth = 1024;
int iHeight = (int)((1024.0f / (float)((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Width) * (float)((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Height);
rasterizationOptions.PageWidth = iWidth;
rasterizationOptions.PageHeight = iHeight;
}
}
else
{
if (((Aspose.CAD.Image)m_oDocument).Height > 1024)
{
int iHeight = 1024;
int iWidth = (int)((1024.0f / (float)((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Height) * (float)((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Width);
rasterizationOptions.PageWidth = iWidth;
rasterizationOptions.PageHeight = iHeight;
}
}
//imposto i colori per evitare di usare quelli originali (potrei avere linee uguali allo sfondo)
rasterizationOptions.BackgroundColor = Aspose.CAD.Color.White;
rasterizationOptions.DrawColor = Aspose.CAD.Color.Black;
rasterizationOptions.DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseDrawColor;
rasterizationOptions.CenterDrawing = true;
//layout impostato = al numero di pagina (un immagine per ogni layout)
// se non ci sono layout stampa tutti i livelli (una pagina)
if (((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Layouts.Count > 0)
{
Aspose.CAD.FileFormats.Cad.CadLayoutDictionary layouts = ((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Layouts;
string[] layoutNames = new string[1];
int l = 0;
foreach (Aspose.CAD.FileFormats.Cad.CadObjects.CadLayout layout in layouts.Values)
{
if (l == _iPageIndex)
{
layoutNames[l++] = layout.LayoutName;
}
}
rasterizationOptions.Layouts = layoutNames;
}
if (m_szImgFormat == "jpeg")
{
Aspose.CAD.ImageOptions.JpegOptions OptionsI = new Aspose.CAD.ImageOptions.JpegOptions();
Aspose.CAD.ResolutionSetting oResI = new Aspose.CAD.ResolutionSetting(Convert.ToDouble(m_iResolution), Convert.ToDouble(m_iResolution));
OptionsI.ResolutionSettings = oResI;
OptionsI.VectorRasterizationOptions = rasterizationOptions;
((Aspose.CAD.Image)m_oDocument).Save(_oOutputStream, OptionsI);
}
else
{
Aspose.CAD.ImageOptions.PngOptions OptionsI = new Aspose.CAD.ImageOptions.PngOptions();
OptionsI.ColorType = Aspose.CAD.FileFormats.Png.PngColorType.TruecolorWithAlpha;
//OptionsI.TransparentColor = new Aspose.Imaging.TransparentColorSetting(Aspose.Imaging.Color.Transparent);
Aspose.CAD.ResolutionSetting oResI = new Aspose.CAD.ResolutionSetting(Convert.ToDouble(m_iResolution), Convert.ToDouble(m_iResolution));
OptionsI.ResolutionSettings = oResI;
OptionsI.VectorRasterizationOptions = rasterizationOptions;
((Aspose.CAD.Image)m_oDocument).Save(_oOutputStream, OptionsI);
}
because IF done in constructor piece of code, it generates an exeption on the .Save final row
System.NotImplementedException: The method or operation is not implemented.\r\n at Aspose.CAD.FileFormats.Cad.CadImage.Resize(Int32 newWidth, Int32 newHeight, ResizeType resizeType)\r\n
— Aspose.CAD.CadExceptions.ImageSaveException: Image export failed. —> System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.
commented in constructor and placed in conversion method (to pdf or to png as example) it works! But placed in constructor it’ll be more efficient and not duplicate over the rest of code
Office.dwg.zip (40.3 KB)
I attache a sample dwg
thanks