|
9 | 9 | using System.Collections; |
10 | 10 | using System.Collections.Generic; |
11 | 11 | using System.Drawing; |
| 12 | +using System.Drawing.Imaging; |
12 | 13 | using System.IO; |
13 | 14 | using System.Linq; |
14 | 15 | using System.Resources; |
@@ -173,18 +174,43 @@ private static ResourceKind GetResourceKind( |
173 | 174 | } |
174 | 175 |
|
175 | 176 | // Check if the data is a bitmap, failure just means it is not. |
| 177 | + // First 4 bytes of the resource data is the length |
| 178 | + byte[] subset = new byte[resourceData.Length - 4]; |
| 179 | + Array.Copy(resourceData, 4, subset, 0, subset.Length); |
| 180 | + MemoryStream ms = new MemoryStream(subset); |
| 181 | + |
176 | 182 | try |
177 | 183 | { |
178 | | - byte[] subset = new byte[resourceData.Length - 4]; |
179 | | - Array.Copy(resourceData, 4,subset, 0,subset.Length); |
180 | | - MemoryStream ms = new MemoryStream(subset); |
181 | | - |
182 | | - Bitmap bitmapImage = Image.FromStream(ms) as Bitmap; |
183 | | - return ResourceKind.Bitmap; |
| 184 | + // Check for supported bitmap type |
| 185 | + Image img = Image.FromStream(ms); |
| 186 | + if (Guid.Equals(img.RawFormat,ImageFormat.Bmp)) |
| 187 | + { |
| 188 | + return ResourceKind.Bitmap; |
| 189 | + } |
| 190 | + else if (Guid.Equals(img.RawFormat, ImageFormat.Jpeg)) |
| 191 | + { |
| 192 | + return ResourceKind.Bitmap; |
| 193 | + } |
| 194 | + else if (Guid.Equals(img.RawFormat, ImageFormat.Gif)) |
| 195 | + { |
| 196 | + return ResourceKind.Bitmap; |
| 197 | + } |
| 198 | + else if (Guid.Equals(img.RawFormat,ImageFormat.Icon) |
| 199 | + || Guid.Equals(img.RawFormat,ImageFormat.Emf) |
| 200 | + || Guid.Equals(img.RawFormat,ImageFormat.Exif) |
| 201 | + || Guid.Equals(img.RawFormat,ImageFormat.MemoryBmp) |
| 202 | + || Guid.Equals(img.RawFormat,ImageFormat.Png) |
| 203 | + || Guid.Equals(img.RawFormat,ImageFormat.Tiff) |
| 204 | + || Guid.Equals(img.RawFormat, ImageFormat.Wmf) ) |
| 205 | + { |
| 206 | + // Any future support for other image types to be handled here |
| 207 | + // Currently, fall through and pass data as a byte array |
| 208 | + } |
184 | 209 | } |
185 | 210 | catch |
186 | 211 | { |
187 | | - // Ignore error if not a bitmap |
| 212 | + // Not an error |
| 213 | + // The data is not an image, fall through and treat as a binary array |
188 | 214 | } |
189 | 215 |
|
190 | 216 | // None of the above, assume binary |
|
0 commit comments