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

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: Member
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: Member, Administration, Moderator
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
Similar Topics
image size in html5 uploader (Discussions – HTML5/Flash Uploader)
by oza 2/26/2014 6:59:16 AM(UTC)
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)
Individual Image size issue (Discussions – ActiveX/Java Uploader)
by scancafe 4/27/2008 11:49:16 PM(UTC)
is there the ability to choose alternate upload image size (Discussions – ActiveX/Java Uploader)
by rolandk98 11/20/2007 1:00:22 PM(UTC)
Detect Image Size Before Upload? (Image Uploader)
by Bob_J 8/11/2006 9:50:32 AM(UTC)
Maximum image size, dimension and compression (Discussions – ActiveX/Java Uploader)
by flexus 11/1/2005 6:32:13 AM(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.