Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
Chris Jones  
#1 Posted : Thursday, May 4, 2017 7:15:43 AM(UTC)
Chris Jones

Rank: Advanced Member

Groups: Member
Joined: 6/9/2016(UTC)
Posts: 34

Thanks: 22 times
I'm currently using graphicsmill v9.1.3, rendering a few paths using the pipeline api.
I use ImageGenerator to create an image that is 4cm x 4cm (944x944 pixels at 600 dpi).
Then use the Drawer to draw the shapes and finally output a jpg image to disk.

This works well at 600dpi. If i increase it i start getting rendering issues, for example at 1200dpi i get my shapes 4 times, smaller and cut off. I've attached an example image to show whats happening at 600dpi and 1200dpi.

Any ideas why this is happening? is it something i've done/not done or is it a bug? We're approaching release in a few months and this is worrying.

I can try to make a cut down sample if you need it, just let me know.

Thanks

1200dpi.jpg600dpi.jpg
Fedor  
#2 Posted : Thursday, May 4, 2017 8:52:47 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,558

Thanks: 5 times
Was thanked: 62 time(s) in 61 post(s)
Hi Chris,

Could you post a code sample to reproduce the problem?
Best regards,
Fedor Skvortsov
Chris Jones  
#3 Posted : Thursday, May 4, 2017 11:13:32 PM(UTC)
Chris Jones

Rank: Advanced Member

Groups: Member
Joined: 6/9/2016(UTC)
Posts: 34

Thanks: 22 times
I've attached the code for completeness but I've realised what the problem was. It was my fault in end. i didn't realise that the graphics transform has the position set for each chunk, so as you see in my code below, i'm overwriting it rather than transforming it.

EDIT: I've removed my question as i realised i don't need to do anything other than clone the existing graphics transform, modify it and put it back.

Thanks!

Code:

      public void Run()
      {
         var dpi = 1200f;
         var widthMm = 40;
         var heightMm = 40;

         var widthPx = UnitConverter.ConvertUnitsToPixels(dpi, widthMm, Unit.Mm);
         var heightPx = UnitConverter.ConvertUnitsToPixels(dpi, heightMm, Unit.Mm);

         var outputFilename = $@"E:\Temp\Labels\issue-{dpi}dpi.jpg";


         using (var generator = CreateImageGenerator(widthPx, heightPx, dpi))
         using (var drawer = CreateDrawer(widthPx, heightPx))
         using (var writer = ImageWriter.Create(outputFilename))
         {
            Pipeline.Run(generator + drawer + writer);
         }
      }

      private Drawer CreateDrawer(float width, float height)
      {
         var drawer = new Drawer();

         drawer.Draw += (sender, args) =>
         {
            var graphics = args.Graphics;

            var matrix2 = new System.Drawing.Drawing2D.Matrix();
            graphics.Transform = matrix2;
            
            var brush = new SolidBrush(RgbColor.Green);
            graphics.FillRectangle(brush, 0, 0, 200, 200);
         };

         return drawer;
      }

      private ImageGenerator CreateImageGenerator(int width, int height, float dpi)
      {
         return new ImageGenerator(width, height, PixelFormat.Format24bppRgb, new RgbColor(255, 255, 255))
         {
            DpiX = dpi,
            DpiY = dpi
         };
      }

Edited by user Thursday, May 4, 2017 11:48:24 PM(UTC)  | Reason: Not specified

Fedor  
#4 Posted : Friday, May 5, 2017 10:03:18 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,558

Thanks: 5 times
Was thanked: 62 time(s) in 61 post(s)
Hi Chris,

You discovered a reason of the problem correctly. Even though, if you need to apply a matrix transformation in the Pipeline mode you should just multiple matrices:

Code:
var transform = CreateTransform();
transform.Multiply(graphics.Transform, MatrixOrder.Append);


Code:
using Aurigma.GraphicsMill;
using Aurigma.GraphicsMill.AdvancedDrawing;
using Aurigma.GraphicsMill.Codecs;
using System;
using System.Drawing.Drawing2D;

class Forum_15147
{
    private static float dpi = 1200f;
    private static float widthMm = 40f;
    private static float heightMm = 40f;

    private static int widthPx;
    private static int heightPx;

    static void Main(string[] args)
    {
        widthPx = UnitConverter.ConvertUnitsToPixels(dpi, widthMm, Unit.Mm);
        heightPx = UnitConverter.ConvertUnitsToPixels(dpi, heightMm, Unit.Mm);

        RunBitmap();
        RunPipeline();       
    }

    public static void RunBitmap()
    {
        var outputFilename = $@"../../../bitmap-{dpi}dpi.jpg";

        using (var bitmap = new Bitmap(widthPx, heightPx, PixelFormat.Format24bppRgb, new RgbColor(255, 255, 255)))
        {
            bitmap.DpiX = dpi;
            bitmap.DpiY = dpi;

            var graphics = bitmap.GetAdvancedGraphics();

            graphics.Transform = CreateTransform();

            DrawGraphics(graphics);

            bitmap.Save(outputFilename);
        }    
    }

    public static void RunPipeline()
    {
        var outputFilename = $@"../../../pipilene-{dpi}dpi.jpg";

        using (var generator = new ImageGenerator(widthPx, heightPx, PixelFormat.Format24bppRgb, new RgbColor(255, 255, 255)))
        using (var drawer = new Drawer())
        using (var writer = ImageWriter.Create(outputFilename))
        {
            generator.DpiX = dpi;
            generator.DpiY = dpi;

            drawer.Draw += (sender, args) =>
            {
                var graphics = args.Graphics;

                var transform = CreateTransform();
                transform.Multiply(graphics.Transform, MatrixOrder.Append);

                graphics.Transform = transform;

                DrawGraphics(graphics);
            };

            Pipeline.Run(generator + drawer + writer);
        }
    }

    public static void DrawGraphics(Graphics graphics)
    {
        var brush = new SolidBrush(RgbColor.Green);
        graphics.FillRectangle(brush, 0, 0, 700, 700);
    }

    public static System.Drawing.Drawing2D.Matrix CreateTransform()
    {
        var transform = new System.Drawing.Drawing2D.Matrix();

        transform.Translate(400f, 100f);
        transform.Rotate(15f);

        return transform;
    }
}


Pipeline (incorrect):
pipilene-1200dpi-wrong.jpg

Pipeline (correct):
bitmap-1200dpi.jpg

Bitmap (correct):
pipilene-1200dpi-correct.jpg

Edited by user Saturday, May 6, 2017 2:23:07 AM(UTC)  | Reason: Not specified

Best regards,
Fedor Skvortsov
thanks 1 user thanked Fedor for this useful post.
Chris Jones on 5/7/2017(UTC)
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.