This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

How add border to a RGB image

Hi friends, I´m new using Graphics Mill, so sorry if my question is repeated.

I´m working with RGB images (TIFF, JPEG), sometimes big images. I would need add a black border (5mm. aprox) to my images.
Does exist any method with Graphics Mill without using System.Drawing.Graphics in C# ??

Thanks in advance...
Hi,

You can add border the following way. It should work perfectly even for very large images.

using Aurigma.GraphicsMill;
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Transforms;

class Program
{
	static void Main(string[] args)
	{
		var borderColor = RgbColor.Blue;
		int borderWidth = 20;

		using (var reader = ImageReader.Create("../../../test.png"))
		using (var generator = new ImageGenerator(reader.Width + borderWidth * 2,  
			reader.Height + borderWidth * 2, reader.PixelFormat, borderColor))
		using (var blender = new Blender())
		using (var writer = ImageWriter.Create("../../../out.png"))
		{
			blender.TopImage = reader;
			blender.X = borderWidth;
			blender.Y = borderWidth;

			(generator + blender + writer).Run();
		}
	}
}
Hi Fedor, it´s works fine for me. The only problems is that I loose the X and Y resolution. The output image is 72 dpi image while the input image is 400 dpi.
I suppose writer will have any option to select the DPI desired.

Thanks anyway, your help was useful for me.

Regards,
Franchi_S5;32556
Hi Fedor, it´s works fine for me. The only problems is that I loose the X and Y resolution. The output image is 72 dpi image while the input image is 400 dpi.
I suppose writer will have any option to select the DPI desired.

Thanks anyway, your help was useful for me.

Regards,


Hi again Fedor, thought I was easiest.
I´m having problem with the output resolution. I´m reading a big TIFF (RGB 400 dpi) cropping, adding border and saving. But when I save the image it always have 72dpi.
What should I do for keeping the original input resolution..?? I´m reading the image with TiffReader and saving with TiffWriter. I don´t know if working with so big images I should use another method.

show you my code (in this code the crop is not implemented):

private void button1_Click(object sender, EventArgs e)
        {
            var borderColor = RgbColor.Black;
            int borderWidth = 20;
            
            using (var reader = new TiffReader("E:/TEST/INTIFF/001.tif")) // big image at 400dpi
            using (var generator = new ImageGenerator(reader.Width + borderWidth * 2, reader.Height + borderWidth * 2, reader.PixelFormat, borderColor))
            using (var blender = new Blender())
            using (var writer = new TiffWriter("E:/TEST/INTIFF/out.tif"))
            
            {
                var exif = reader.Exif;
                writer.Exif = exif;
                blender.TopImage = reader;
                blender.X = borderWidth;
                blender.Y = borderWidth;
                Pipeline.Run(generator + blender + writer);
                //(generator + blender + writer).Run();
            }
        } 
Franchi_S5;32556
Hi Fedor, it´s works fine for me. The only problems is that I loose the X and Y resolution. The output image is 72 dpi image while the input image is 400 dpi.
I suppose writer will have any option to select the DPI desired.

Thanks anyway, your help was useful for me.


Just copy DPI settings from the reader to the generator:

generator.DpiX = reader.DpiX;
generator.DpiY = reader.DpiY;			

blender.TopImage = reader;

Oh my god, it was so easy.....
Works fine.

I'm not used to it. Things in .NET are usually more and more complicated.
Thanks again my friend.