IsSupportedMimeType( BitmapSource bitmapSource ) { BitmapCodecInfo codecInfo = null; string imageMimeType = ""; if (bitmapSource is BitmapFrame) { // // This code gets the encoder based on the decoder that was // used for this specific BitmapSource. // BitmapFrame bitmapFrame = bitmapSource as BitmapFrame; if (bitmapFrame != null && bitmapFrame.Decoder != null) { codecInfo = bitmapFrame.Decoder.CodecInfo; } } if (codecInfo != null) { (new RegistryPermission(PermissionState.Unrestricted)).Assert(); try { imageMimeType = codecInfo.MimeTypes; } finally { RegistryPermission.RevertAssert(); } } int start = 0; int comma = imageMimeType.IndexOf(',', start); bool foundType = false; // // Test all strings before commas // if (comma != -1) { while (comma != -1 && !foundType) { string subString = imageMimeType.Substring(start, comma); foundType = XpsManager.SupportedImageType(new ContentType(subString)); start = comma + 1; comma = imageMimeType.IndexOf(',', start); } } // // If we still have not found a supported type // Test the remainder of the string // if (!foundType) { foundType = XpsManager.SupportedImageType(new ContentType(imageMimeType.Substring(start))); } return(foundType); }