Rank: Advanced Member
Groups: Guest
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
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
Hi Chris,
Could you post a code sample to reproduce the problem? |
Best regards, Fedor Skvortsov
|
|
|
|
Rank: Advanced Member
Groups: Guest
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
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 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):Pipeline (correct):Bitmap (correct):Edited by user Saturday, May 6, 2017 2:23:07 AM(UTC)
| Reason: Not specified |
Best regards, Fedor Skvortsov
|
1 user thanked Fedor for this useful post.
|
|
|
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.