Image generated with poor quality

@siriussynoptek

You may achieve better quality :
a) using another font (i.e. Arial)
b) using

TextRenderingHint = Aspose.Imaging.TextRenderingHint.ClearTypeGridFit,

Expected result :test.png (1.0 KB)

Hi Team,

We have made changes of font to Arail and set TextRenderingHint to ClearTypeGridFit but it looks like there is no notable improvement in image quality after and before. Please refer attached image. Please suggest other approach if you have to generate best quality image. Also, our requirement is to generate image using Proxima Nova font so can we know why we can’t get better quality image if we use Proxima Nova font?

Comparison.jpg (42.7 KB)

@siriussynoptek, please take a look at provided example and results. Here used your image and text lines were drawn on it. Think, result looks not pixelated. Also please note, that this is raster format and you are not able to achieve best zoom results than in vectors.

//Create an instance of BmpOptions and set its various properties
            Aspose.Imaging.ImageOptions.PngOptions pngOptions = new Aspose.Imaging.ImageOptions.PngOptions();
            pngOptions.ColorType = PngColorType.TruecolorWithAlpha;

            //Create an instance of FileCreateSource and assign it as Source for the instance of BmpOptions
            //Second Boolean parameter determines if the file to be created IsTemporal or not
            pngOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(@"resultImaging.png", false);

            Font font1 = new Font("Proxima-Nova", 30);
            Font font2 = new Font("Arial", 30);
            //Create an instance of Image and initialize it with instance of BmpOptions by calling Create method
            using (Aspose.Imaging.Image imageNew = Aspose.Imaging.Image.Create(pngOptions, 800, 100))
            {
                using (PngImage header = (PngImage)Image.Load("header.png")
                )
                {
                    //do some image processing
                    Graphics gr = new Graphics(imageNew);
                    gr.DrawImage(header, new Point(0, 0));
                    SizeF size = gr.MeasureString(DrawString, font1, Aspose.Imaging.SizeF.Empty, new StringFormat());
                    Console.WriteLine(size);
                    SizeF size2 = gr.MeasureString(DrawString, font2, Aspose.Imaging.SizeF.Empty, new StringFormat());
                    Console.WriteLine(size2);

                    gr.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                    gr.SmoothingMode = SmoothingMode.HighQuality;
                    gr.DrawString(
                        DrawString,
                        font1,
                        new Aspose.Imaging.Brushes.SolidBrush(Color.Black),
                        new PointF(0, 0));
                    gr.DrawString(
                        DrawString,
                        font2,
                        new Aspose.Imaging.Brushes.SolidBrush(Color.Black),
                        new PointF(0, 50));
                    // save all changes
                    
                    imageNew.Save();
                }
            }

Result: Dropbox - resultImaging.png - Simplify your life

Hi,

We have applied code snippet given by you and observed that no major quality improvement in generated image. Is there any compression take place when we resize image or create image using Aspose.Imaging due to that poor quality image generated?

@siriussynoptek, As wrote before, text is rasterized on raster image. Here are result obtained using Photoshop with Proxima Nova font and Arial Dropbox - resultPhotoshop.png - Simplify your life and here are results using Aspose.Imaging with 0 compression level for png Dropbox - resultImagingNoCompressionLevel.png - Simplify your life As you can see scaling gives worth result in both cases, but results looks similar. Aspose.Imaging provides using of Png compression by CompressionLevel option in PngOptions. It can be from 0 to 9. 0 - no compression. Please provide results that does not pixelate if you can, so that we can investigate more. As wrote below, to avoid pixelation on scaling you can try use vectors with fonts, for example svg.

Hi Team,

It is not possible to use only vector images for the functionality as our client have large amount of images in raster and vector formats. So as per the requirement we need to maintain image quality for both the formats. Please provide your inputs, how to achieve best quality result for above requirement?

Please note that we have a hard requirement for this quality concern. Please consider it and let us know.

@siriussynoptek, You can embed source raster image in svg or pdf. And your text will scale.

Can you please elaborate it in details?

@siriussynoptek,
please, see example:

           //create graphics
           EmfRecorderGraphics2D graphics = new EmfRecorderGraphics2D(new Rectangle(0, 0, 50000, 50000), new Size(5000, 5000), new Size(1000, 1000));
           {
               //Source raster image
               using (Image rasterImage = Image.Load(@"D:\1.png"))
               {
                   graphics.DrawImage(rasterImage as RasterImage, new Point(0,0));
               }

               //font
               Font font = new Font("Arial", 48, FontStyle.Bold | FontStyle.Underline);

               //Text with font, color, position
               graphics.DrawString("Hello world", font, Color.Blue, 150, 200);

               //Generate emf image
               using (EmfImage image = graphics.EndRecording())
               {
                   //image.Save(@"D:\1.emf"); //save to emf format
                   //image.Save(@"D:\1.pdf", new PdfOptions()); //save to pdf format
                   image.Save(@"D:\1.svg", new SvgOptions()); //save to svg format
               }
           }

More details here

Hello Team,

As our requirement is to generate image into raster format(source image extension), we don’t want to save generated image in vector format. Please suggest us how can we achieve best quality image in raster format only?

@siriussynoptek Please write in what way you are not satisfied with the vector format?

Hello Team,

As mentioned earlier, our most of source images are in raster format and our requirement is to generate branded image by adding text and using existing source image and generated branded image format should be same as source image format. so we want to improve quality of generated raster format branded image.

@siriussynoptek,

If you are confused by the quality of the text of raster images in the Jpeg format, change the Jpeg quality to a higher one. (In your example, this is exactly the problem)
As already discussed with you in another thread.

Hello Team,

We have implemented all suggestion provided till now but still we are not stratified quality of generated image. Please refer attached sample application for same. Image with name output.png will be generated in ImagesOutput folder when you run sample application. Please suggest us how can we achieve best quality image in our requirement.

SampleApplication.zip (8.5 MB)

@siriussynoptek
Please review attached quality testing output.quality-test-output.zip (9.1 KB)
If it suits you, we may share further recommendations.

Hi Team,

We have reviewed image that you have shared with us. We have tried to compare it with image generated by sample application that we have shared with you and found that almost both images are same. No quality difference found. Can you please share recommendations with us so that we can apply it in our actual application and check the generated image quality? Also, can we know what quality parameter you have considered when generate this image?

Thanks.

@siriussynoptek
Also, can we know what quality parameter you have considered when generate this image?
We’ve considered

    CompositingQuality = CompositingQuality.HighQuality,
    InterpolationMode = InterpolationMode.HighQualityBicubic

Can you please share recommendations with us so that we can apply it in our actual application and check the generated image quality?
We recommend avoiding raster image zoom after the text output or use not raster image formats, where text kept not rasterized and enjoi zoom quality. All the rest is in your hands.

@siriussynoptek
The fact that you are not satisfied with the display of the font is called ClearType, more details here: ClearType - Wikipedia
This can be turned off, the font will look as expected when zoomed in, but will be angular in normal viewing.
No other has yet been invented…
example:

 using (MemoryStream ms = new MemoryStream())
 using (Image image = Image.Create(new PngOptions(){Source = new StreamSource(ms)}, 500, 500))
 {
     Graphics graphics = new Graphics(image);
     graphics.Clear(Color.White);
     graphics.DrawString("Hello World - 1", new Font("Arial", 36, FontStyle.Regular), new SolidBrush(Color.Black), 0,0);
     graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
     graphics.DrawString("Hello World - 2", new Font("Arial", 36, FontStyle.Regular), new SolidBrush(Color.Black), 0, 100); 
     image.Save(@"D:\1.png");
 }

Hello World - 1 - with ClearType
Hello World - 2 - without ClearType
result: 1.png (2.6 KB)

Perhaps - graphics.TextRenderingHint = TextRenderingHint.AntiAlias; Will be a compromise solution,
result with AntiAlias: AntiAlias.png (3.5 KB)

Hello Team,

Is there any new method or feature invented in latest version to improve generated image quality?

Is there any way to create Font object without specifying font size?

@siriussynoptek, you still can use vector images for better quality of text as we wrote above. We don’t have any other changes and plans related to this. Related to font creation, you can not create font and after that use it without specifying font size.