1
0
Fork 0

Begin implementing error images

This commit is contained in:
Starbeamrainbowlabs 2016-07-10 20:50:29 +01:00
parent dd10edb281
commit 4f1fc0f211
1 changed files with 26 additions and 20 deletions

View File

@ -12,28 +12,34 @@ namespace GalleryShare
{
public static void GenerateThumbnailPng(string imagePath, Size thumbnailBounds, Stream outputStream)
{
using (Bitmap rawImage = new Bitmap(imagePath)) {
float scaleFactor = Math.Min(
thumbnailBounds.Width / (float)rawImage.Width,
thumbnailBounds.Height / (float)rawImage.Height
);
Size thumbnailSize = new Size(
(int)(rawImage.Width * scaleFactor),
(int)(rawImage.Height * scaleFactor)
);
using (Bitmap smallImage = new Bitmap(thumbnailSize.Width, thumbnailSize.Height))
using (Graphics context = Graphics.FromImage(smallImage)) {
context.CompositingMode = CompositingMode.SourceCopy;
context.InterpolationMode = InterpolationMode.HighQualityBicubic;
context.DrawImage(rawImage, new Rectangle(
Point.Empty,
thumbnailSize
));
smallImage.Save(outputStream, ImageFormat.Png);
try {
using (Bitmap rawImage = new Bitmap(imagePath)) {
float scaleFactor = Math.Min(
thumbnailBounds.Width / (float)rawImage.Width,
thumbnailBounds.Height / (float)rawImage.Height
);
Size thumbnailSize = new Size(
(int)(rawImage.Width * scaleFactor),
(int)(rawImage.Height * scaleFactor)
);
using (Bitmap smallImage = new Bitmap(thumbnailSize.Width, thumbnailSize.Height))
using (Graphics context = Graphics.FromImage(smallImage)) {
context.CompositingMode = CompositingMode.SourceCopy;
context.InterpolationMode = InterpolationMode.HighQualityBicubic;
context.DrawImage(rawImage, new Rectangle(
Point.Empty,
thumbnailSize
));
smallImage.Save(outputStream, ImageFormat.Png);
}
}
}
catch (Exception error)
{
throw new NotImplementedException("Error images haven't been implemented yet.", error);
}
}
}
}