Issues in SVG to TIFF conversion (C# .NET)

Hi There,

I generated image using Aspose.

Below is the code snippet:

		   // we are getting image in SVG base 64 format
		   using (var stream = new MemoryStream(imageRequest.imgFrom))
            {

                using (Aspose.Imaging.FileFormats.Svg.SvgImage svgImg = (Aspose.Imaging.FileFormats.Svg.SvgImage)Image.Load(stream))
                {
                   
                    using (var tiffStream = new MemoryStream())
                    {
                        svgImg.Save(tiffStream, options);
                        retBytes = tiffStream.ToArray();
                    }
                }
            }
			
			var tiffImage = new MemoryStream(retBytes, true);
            using (Image inputImage = Image.Load(tiffImage))
            {
                using (var newtiffStream = new MemoryStream())
                {
                    inputImage.Resize(400, 95);
                    inputImage.Save(newtiffStream);
                    retBytes = newtiffStream.ToArray();
                }
            }

when Jai libraries are try to parse following exception is thrown.

java.lang.ClassCastException: [C cannot be cast to [J
at com.sun.media.jai.codec.TIFFField.getAsLongs(TIFFField.java:217)
at com.sun.media.jai.codecimpl.TIFFImage.(TIFFImage.java:268)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImageDecoder.java:111)
at com.sun.media.jai.codec.ImageDecoderImpl.decodeAsRenderedImage(ImageDecoderImpl.java:148)
at com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:60)
at com.sun.media.jai.opimage.TIFFRIF.create(TIFFRIF.java:53)
at javax.media.jai.OperationRegistry.create(OperationRegistry.java:2956)
at com.sun.media.jai.opimage.StreamRIF.create(StreamRIF.java:92)
at javax.media.jai.OperationRegistry.create(OperationRegistry.java:2956)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:402)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:414)
at javax.media.jai.RenderedOp.getSampleModel(RenderedOp.java:1297)
at javax.media.jai.operator.AndDescriptor.validateSources(AndDescriptor.java:114)
at javax.media.jai.OperationDescriptorImpl.validateArguments(OperationDescriptorImpl.java:505)
at javax.media.jai.JAI.createNS(JAI.java:417)
at javax.media.jai.JAI.create(JAI.java:306)
at javax.media.jai.JAI.create(JAI.java:1318)

@ymallikreddy521,

I have observed the sample code shared by you along with stack trace. I request you to please share the source file reproducing the issue along with Java and Operating system details on your end. I also suggest you to please first try using latest Aspose.Imaging for Java 19.4 on your end as well.

thanks for reply.

I am using dot net libraries to create image. ( please change the attached file extension to .tiff - to tiff format)

For java - the team communicated that they are using latest JAI libraries. it still doesn’t work.

and Java is used by other team to process the image that I generate.a.jpeg (3.1 KB)

@ymallikreddy521,

I have worked with sample code shared by you. The code snippet you have shared includes some undeclared variables so would you please share SSCCE code reproducing the issue so that we may try to reproduce and investigate it in our environment.

unfortunately I don’t have code for Java as it is used by external team.

Below is the code I am using for TIFF generation.

   using (var stream = new MemoryStream(imageRequest.imgFrom))
        {

            using (Aspose.Imaging.FileFormats.Svg.SvgImage svgImg = (Aspose.Imaging.FileFormats.Svg.SvgImage)Image.Load(stream))
            {
               
                using (var tiffStream = new MemoryStream())
                {
                    svgImg.Save(tiffStream, options);
                    retBytes = tiffStream.ToArray();
                }
            }
        }
		
		var tiffImage = new MemoryStream(retBytes, true);
        using (Image inputImage = Image.Load(tiffImage))
        {
            using (var newtiffStream = new MemoryStream())
            {
                inputImage.Resize(400, 95);
                inputImage.Save(newtiffStream);
                retBytes = newtiffStream.ToArray();
            }
        }

could you please let me know if I am doing the right way of generating tiff file.

Also could you please tell me what are “some undeclared variables”

@ymallikreddy521,

As requested earlier, can you please share the source file reproducing the issue.

do you need source file for creating of tiff image or java source file which process.

Unfortunately I don’t have java file.

@ymallikreddy521,

I have requested you to please share source SVG file that has been used to reproduce the issue on your end.

images.zip (2.3 KB)

Thank you for reply. Please find the attached zip file. I have SVG file which is source and tiff file which is output.

Sorry for confusion.

@ymallikreddy521,

Thank you for sharing the files. I have worked using both Aspose.Imaging for .NET 19.4 and Aspose.Imaging for Java 19.4 on my end and have not been able to observe any issue. I also like to highlight that you reported a Java based issue in your first post where as you have provided C# code in subsequent posts. Therefore, I have created both samples and both are working fine on my end.

public static void SVGtoTiff() 
{
    try
    {
        
        byte[] retBytes = null;
        String path = "C:\\Imaging Data\\Images\\images\\";

        com.aspose.imaging.fileformats.svg.SvgImage svgImg = (com.aspose.imaging.fileformats.svg.SvgImage)Image.load(path + "file.svg");
       // OutputStream tiffStream = new  FileOutputStream(path+"SavedTiff.tiff");
        ByteArrayOutputStream tiffStream = new ByteArrayOutputStream();
        svgImg.save(tiffStream, new com.aspose.imaging.imageoptions.TiffOptions(TiffExpectedFormat.Default));
        retBytes = tiffStream.toByteArray();


        InputStream tiffImage = new ByteArrayInputStream(retBytes);
        //using (Image inputImage = Image.Load(tiffImage))
        TiffImage inputImage = (TiffImage)Image.load(tiffImage);

        ByteArrayOutputStream newtiffStream = new ByteArrayOutputStream();

        inputImage.resize(400, 95);
        inputImage.save(newtiffStream);
        inputImage.save(path+"saved2.tiff");

        retBytes = newtiffStream.toByteArray();

    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}

public static void SVGtoTiff()
{
    byte[] retBytes = null;
    String path = @"C:\Imaging Data\Images\images\";
     
    {
        using (Aspose.Imaging.FileFormats.Svg.SvgImage svgImg = (Aspose.Imaging.FileFormats.Svg.SvgImage)Image.Load(path + "file.svg"))
        {

            using (var tiffStream = new MemoryStream())
            {

                svgImg.Save(tiffStream, new Aspose.Imaging.ImageOptions.TiffOptions(TiffExpectedFormat.Default));
                retBytes = tiffStream.ToArray();
            }
        }
    }

    var tiffImage = new MemoryStream(retBytes, true);
    //using (Image inputImage = Image.Load(tiffImage))
    using (TiffImage inputImage = (TiffImage)Image.Load(tiffImage))
    {
        using (var newtiffStream = new MemoryStream())
        {
            inputImage.Resize(400, 95);
            inputImage.Save(newtiffStream);
            inputImage.Save(path+"saved.tiff");
            
            retBytes = newtiffStream.ToArray();
        }
    }
}

I hope the shared information will be helpful.

Thanks lot for your time. I will check and let you know.

Also why the tiff image is blur when converted from SVG. SVG image is smooth but tiff has blur. is it how tiff works.

@ymallikreddy521,

I suggest you to please try using following SVG save option on your end.

svgImg.Save(tiffStream, new Aspose.Imaging.ImageOptions.TiffOptions(TiffExpectedFormat.Default));