Files
Ryan Durand 9ef3748747 Updating copyrights for Engine Programs.
#rnx
#rb none
#jira none

#ROBOMERGE-OWNER: ryan.durand
#ROBOMERGE-AUTHOR: ryan.durand
#ROBOMERGE-SOURCE: CL 10869242 in //Fortnite/Release-12.00/... via CL 10869536
#ROBOMERGE-BOT: FORTNITE (Main -> Dev-EngineMerge) (v613-10869866)

[CL 10870955 by Ryan Durand in Main branch]
2019-12-26 23:01:54 -05:00

51 lines
1.8 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
namespace AutomationTool
{
public static class ImageUtils
{
/// <summary>
/// Resave an image file as a .jpg file, with the specified quality and scale.
/// </summary>
public static void ResaveImageAsJpgWithScaleAndQuality(string SrcImagePath, string DstImagePath, float Scale, int JpgQuality)
{
// Find the built-in jpg encoder
var Codec = ImageCodecInfo.GetImageDecoders().Where(d => d.FormatID == ImageFormat.Jpeg.Guid).First();
using (var SrcImage = Image.FromFile(SrcImagePath))
{
// Create a resized destination bitmap
var DstRect = new Rectangle(0, 0, (int)(SrcImage.Width * Scale), (int)(SrcImage.Height * Scale));
using (var DstImage = new Bitmap(DstRect.Width, DstRect.Height))
{
DstImage.SetResolution(SrcImage.HorizontalResolution, SrcImage.VerticalResolution);
// Draw and scale the original image into the new bitmap.
using (var Grfx = Graphics.FromImage(DstImage))
using (var ImageAttrs = new ImageAttributes())
{
Grfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
Grfx.CompositingQuality = CompositingQuality.HighQuality;
Grfx.CompositingMode = CompositingMode.SourceCopy;
Grfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
Grfx.SmoothingMode = SmoothingMode.HighQuality;
ImageAttrs.SetWrapMode(WrapMode.TileFlipXY);
Grfx.DrawImage(SrcImage, DstRect, 0, 0, SrcImage.Width, SrcImage.Height, GraphicsUnit.Pixel, ImageAttrs);
}
// Save using the Jpg encoder and a custom quality level.
var EncParams = new EncoderParameters(1);
EncParams.Param[0] = new EncoderParameter(Encoder.Quality, JpgQuality);
DstImage.Save(DstImagePath, Codec, EncParams);
}
}
}
}
}