Support for resizing DWG using Aspose.Imaging for .NET

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

@BooleServer,

I have observed the sample code shared you and have not been able to understand it properly as there are many formatted and unformatted pieces of codes which are contiguous as well. Can you please provide the details of issue separately with separate working piece of code that we test on our end to reproduce along with issue description. Secondly, I also suggest you to please try using Aspose.CAD for .NET 17.9 as well before sharing information with us.

Sure, and can we suggest more attention on your part and not let for customers the role of your tester team?
the method resize goes into exeption if used on the instantiate of object
so if you use a code like this:

myConvert obj = new myConvert( oMstream);

and in the instance code:

m_oDocument = Aspose.CAD.Image.Load(_oInputStream);
_((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Resize(iWidth, iHeight, Aspose.CAD.ResizeType.NearestNeighbourResample);

the resize method goes into exeption, as we said.

instead if you use a code like this:

myConvert obj = new myConvert( oMstream);

and in the instance code

m_oDocument = Aspose.CAD.Image.Load(_oInputStream);

and finally use a method to (e.g.) convert to png

obj.convert();

and in the method code

((Aspose.CAD.FileFormats.Cad.CadImage)m_oDocument).Resize(iWidth, iHeight, Aspose.CAD.ResizeType.NearestNeighbourResample);_

does NOT go into exeption…

Hope now is clear, and obviously we are using (testing) last version of your dll 17.9
Maybe are we using code in a wrong way? as previously said, using resize method in the constructor would be much more effective and would avoid duplicates.

@BooleServer,

Thank you for sharing the clarification and I am sorry for your inconvenience. Actually, earlier owing to formatting problem the things were not getting clear. I have observed the and reproduce the exception, NotImplemented exception on calling Resize() method. The exception being thrown is valid and self explanatory that the requested support is not available. I have requested our product team to share their feedback in this regard whether this is valid implementation or not. An issue with ID CADNET-455 has been added as investigation in our issue tracking system to further investigate the issue. We will share the feedback with you as soon as it will be shared by our product team.

Please share us some news about CADNET-455
We didn’t receive any notice from October 2017!

@BooleServer,

I have observed your comments. I like to share that this issue is going to be resolved tentatively in Aspose.CAD 18.1. We will share good news with you soon.

Tried with 18.4 but… the resolution is an exeption “method not implemented” if used resize in the constructor code?

@BooleServer,

The issue is presently unresolved and is likely to get resolved in Aspose.CAD 18.6 tentatively. We shall share good news with you as soon as the issue will be fixed.

TRied with 18.8 version and again the same!

@BooleServer,

We have implemented the issue in a way by adding attribute EditorBrowsable(EditorBrowsableState.Never) for all of methods, which throw NotImplementedException, so users can not see its methods in Intellisense helper. Secondly, we are going to remove the Resize() methods in coming releases and going to implement the new approach for resizing CAD files.

Let us know when and how change our methods

@BooleServer,

We will inform you soon.