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

Notification

Icon
Error

Options
Go to last post Go to first unread
Don Wiid  
#1 Posted : Monday, September 15, 2014 9:08:04 PM(UTC)
Don Wiid

Rank: Newbie

Groups: Guest
Joined: 9/15/2014(UTC)
Posts: 1

Thanks: 1 times
Hi all

My first post on this forum, and I am a lapsed Delphi developer. Please be gentle.

We are trying to reduce a JPG image to a specific size: The short edge = 5", resolution = 120 DPI, while retaining the aspect ratio. See sample image

We can do this in manually in Irfanview, and it is quick and easy. We have not found a way to do this with GraphicsMill.

Sample code (C#) would be most welcome.

Thanks,

Don

Don Wiid attached the following image(s):
Resize.png
Fedor  
#2 Posted : Tuesday, September 16, 2014 8:46:50 AM(UTC)
Fedor

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 Don,

Here is a code example to achieve your task:

Code:
using System;

class Program
{
	static void Main(string[] args)
	{
		Resize(@"C:\input.jpg", @"c:\output.jpg");
	}


	private static void Resize(string inputPath, string outputPath)
	{
		float dpi = 120f;
		//5 inch * 120 dots per inch
		int size = (int)(5f * dpi);

		using (var bitmap = new Aurigma.GraphicsMill.Bitmap(inputPath))
		{
			if (bitmap.Width < bitmap.Height)
			{
				//Set value of height param to 0, so it is calculated based on width paranm
				bitmap.Transforms.Resize(size, 0, Aurigma.GraphicsMill.Transforms.ResizeInterpolationMode.High);
			}
			else
			{
				//Set value of width param to 0, so it is calculated based on height paranm
				bitmap.Transforms.Resize(0, size, Aurigma.GraphicsMill.Transforms.ResizeInterpolationMode.High);
			}

			//Set dpi
			bitmap.DpiX = dpi;
			bitmap.DpiY = dpi;

			bitmap.Save(outputPath);
		}
	}
}

Edited by user Tuesday, September 16, 2014 8:47:21 AM(UTC)  | Reason: Not specified

Best regards,

Fedor Skvortsov

thanks 1 user thanked Fedor for this useful post.
Don Wiid on 9/16/2014(UTC)
Users browsing this topic
Guest (2)
Similar Topics
Create Multilayer bitmap as image size (Discussions – Graphics Mill)
by Noufal123 4/26/2011 8:24:52 PM(UTC)
Set image size in multilayerViewer (Discussions – Graphics Mill)
by Noufal123 8/19/2010 8:16:39 PM(UTC)
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.