mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#20644: Working around Azure Websites limitation of not being able to use System.Drawing.Image with .ico files.
WorkItem: 20644
This commit is contained in:
@@ -65,12 +65,36 @@ namespace Orchard.MediaLibrary.Factories {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
using (var image = Image.FromStream(stream)) {
|
using (var image = Image.FromStream(stream)) {
|
||||||
imagePart.Width = image.Width;
|
imagePart.Width = image.Width;
|
||||||
imagePart.Height = image.Height;
|
imagePart.Height = image.Height;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (ArgumentException) {
|
||||||
|
// Still trying to get .ico dimensions when it's blocked in System.Drawing, see: https://orchard.codeplex.com/workitem/20644
|
||||||
|
|
||||||
|
if (mimeType != "image/x-icon" && mimeType != "image/vnd.microsoft.icon") {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
TryFillDimensionsForIco(stream, imagePart);
|
||||||
|
}
|
||||||
|
|
||||||
return part;
|
return part;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void TryFillDimensionsForIco(Stream stream, ImagePart imagePart) {
|
||||||
|
stream.Position = 0;
|
||||||
|
using (var binaryReader = new BinaryReader(stream)) {
|
||||||
|
// Reading out the necessary bytes that indicate the image dimensions. For the file format see:
|
||||||
|
// http://en.wikipedia.org/wiki/ICO_%28file_format%29
|
||||||
|
// Reading out leading bytes containing unneded information.
|
||||||
|
binaryReader.ReadBytes(6);
|
||||||
|
// Reading out dimensions. If there are multiple icons bundled in the same file then this is the first image.
|
||||||
|
imagePart.Width = binaryReader.ReadByte();
|
||||||
|
imagePart.Height = binaryReader.ReadByte();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user