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

Notification

Icon
Error

Options
Go to last post Go to first unread
Franchi_S5  
#1 Posted : Monday, March 12, 2018 6:22:01 AM(UTC)
Franchi_S5

Rank: Advanced Member

Groups: Member
Joined: 3/8/2018(UTC)
Posts: 45

Thanks: 21 times
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...
Fedor  
#2 Posted : Monday, March 12, 2018 6:37:01 AM(UTC)
Fedor

Rank: Advanced Member

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

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Hi,

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

Code:
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();
		}
	}
}

Edited by user Monday, March 12, 2018 6:38:06 AM(UTC)  | Reason: Not specified

Best regards,
Fedor Skvortsov
thanks 1 user thanked Fedor for this useful post.
Franchi_S5 on 3/12/2018(UTC)
Franchi_S5  
#3 Posted : Monday, March 12, 2018 7:58:22 AM(UTC)
Franchi_S5

Rank: Advanced Member

Groups: Member
Joined: 3/8/2018(UTC)
Posts: 45

Thanks: 21 times
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  
#4 Posted : Monday, March 12, 2018 9:06:43 AM(UTC)
Franchi_S5

Rank: Advanced Member

Groups: Member
Joined: 3/8/2018(UTC)
Posts: 45

Thanks: 21 times
Originally Posted by: Franchi_S5 Go to Quoted Post
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):

Code:
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();
            }
        } 
Fedor  
#5 Posted : Monday, March 12, 2018 9:15:28 AM(UTC)
Fedor

Rank: Advanced Member

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

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Originally Posted by: Franchi_S5 Go to Quoted Post
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:

Code:
generator.DpiX = reader.DpiX;
generator.DpiY = reader.DpiY;			

blender.TopImage = reader;

Best regards,
Fedor Skvortsov
thanks 1 user thanked Fedor for this useful post.
Franchi_S5 on 3/12/2018(UTC)
Franchi_S5  
#6 Posted : Monday, March 12, 2018 9:23:47 AM(UTC)
Franchi_S5

Rank: Advanced Member

Groups: Member
Joined: 3/8/2018(UTC)
Posts: 45

Thanks: 21 times
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.
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.