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):
|
|
|
|
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
|
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.