mirror of
https://gitlab.com/sbrl/GalleryShare.git
synced 2018-06-12 22:45:16 +00:00
Begin implementing error images
This commit is contained in:
parent
dd10edb281
commit
4f1fc0f211
1 changed files with 26 additions and 20 deletions
|
@ -12,28 +12,34 @@ namespace GalleryShare
|
||||||
{
|
{
|
||||||
public static void GenerateThumbnailPng(string imagePath, Size thumbnailBounds, Stream outputStream)
|
public static void GenerateThumbnailPng(string imagePath, Size thumbnailBounds, Stream outputStream)
|
||||||
{
|
{
|
||||||
using (Bitmap rawImage = new Bitmap(imagePath)) {
|
try {
|
||||||
float scaleFactor = Math.Min(
|
using (Bitmap rawImage = new Bitmap(imagePath)) {
|
||||||
thumbnailBounds.Width / (float)rawImage.Width,
|
float scaleFactor = Math.Min(
|
||||||
thumbnailBounds.Height / (float)rawImage.Height
|
thumbnailBounds.Width / (float)rawImage.Width,
|
||||||
);
|
thumbnailBounds.Height / (float)rawImage.Height
|
||||||
Size thumbnailSize = new Size(
|
);
|
||||||
(int)(rawImage.Width * scaleFactor),
|
Size thumbnailSize = new Size(
|
||||||
(int)(rawImage.Height * scaleFactor)
|
(int)(rawImage.Width * scaleFactor),
|
||||||
);
|
(int)(rawImage.Height * scaleFactor)
|
||||||
|
);
|
||||||
|
|
||||||
using (Bitmap smallImage = new Bitmap(thumbnailSize.Width, thumbnailSize.Height))
|
using (Bitmap smallImage = new Bitmap(thumbnailSize.Width, thumbnailSize.Height))
|
||||||
using (Graphics context = Graphics.FromImage(smallImage)) {
|
using (Graphics context = Graphics.FromImage(smallImage)) {
|
||||||
context.CompositingMode = CompositingMode.SourceCopy;
|
context.CompositingMode = CompositingMode.SourceCopy;
|
||||||
context.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
context.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
context.DrawImage(rawImage, new Rectangle(
|
context.DrawImage(rawImage, new Rectangle(
|
||||||
Point.Empty,
|
Point.Empty,
|
||||||
thumbnailSize
|
thumbnailSize
|
||||||
));
|
));
|
||||||
|
|
||||||
smallImage.Save(outputStream, ImageFormat.Png);
|
smallImage.Save(outputStream, ImageFormat.Png);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception error)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException("Error images haven't been implemented yet.", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue