diff options
| author | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-09-06 12:00:36 -0400 |
|---|---|---|
| committer | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-09-06 12:00:36 -0400 |
| commit | 8775498732a05bd9aa3a48354fb0522acd8a1515 (patch) | |
| tree | 90601285d3d901a1d28b7c9685cb1d0f95cccf88 /MediaBrowser.Api/ImageProcessor.cs | |
| parent | 94c8332e264bbbf1de570b8bc7c5da8c532e5975 (diff) | |
Fixed image processing on images with indexed pixel formats
Diffstat (limited to 'MediaBrowser.Api/ImageProcessor.cs')
| -rw-r--r-- | MediaBrowser.Api/ImageProcessor.cs | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/MediaBrowser.Api/ImageProcessor.cs b/MediaBrowser.Api/ImageProcessor.cs index 32c7e05a2..723ea1bdd 100644 --- a/MediaBrowser.Api/ImageProcessor.cs +++ b/MediaBrowser.Api/ImageProcessor.cs @@ -23,10 +23,22 @@ namespace MediaBrowser.Api Size newSize = DrawingUtils.Resize(originalImage.Size, width, height, maxWidth, maxHeight);
- Bitmap thumbnail = new Bitmap(newSize.Width, newSize.Height, originalImage.PixelFormat);
+ Bitmap thumbnail;
+
+ // Graphics.FromImage will throw an exception if the PixelFormat is Indexed, so we need to handle that here
+ if (originalImage.PixelFormat.HasFlag(PixelFormat.Indexed))
+ {
+ thumbnail = new Bitmap(originalImage, newSize.Width, newSize.Height);
+ }
+ else
+ {
+ thumbnail = new Bitmap(newSize.Width, newSize.Height, originalImage.PixelFormat);
+ }
+
thumbnail.SetResolution(originalImage.HorizontalResolution, originalImage.VerticalResolution);
Graphics thumbnailGraph = Graphics.FromImage(thumbnail);
+
thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
@@ -41,7 +53,27 @@ namespace MediaBrowser.Api thumbnail.Dispose();
originalImage.Dispose();
}
-
+
+ private static Graphics GetThumbnailGraphics(Image originalImage, Bitmap thumbnail)
+ {
+ thumbnail = new Bitmap(originalImage);
+ return Graphics.FromImage(thumbnail);
+ /*try
+ {
+ return Graphics.FromImage(thumbnail);
+ }
+ catch
+ {
+ Bitmap tmp = new Bitmap(thumbnail.Width, thumbnail.Height);
+ tmp.c
+
+ Graphics graphics = Graphics.FromImage(tmp);
+ graphics.DrawImage(thumbnail, new Rectangle(0, 0, tmp.Width, tmp.Height), 0, 0, tmp.Width, tmp.Height, GraphicsUnit.Pixel);
+
+ return graphics;
+ }*/
+ }
+
private static void Write(Image originalImage, Image newImage, Stream toStream, int? quality)
{
// Use special save methods for jpeg and png that will result in a much higher quality image
|
