本文整理匯總了C#中System.Drawing.Imaging.ImageFormat.Check方法的典型用法代碼示例。如果您正苦於以下問題:C# ImageFormat.Check方法的具體用法?C# ImageFormat.Check怎麽用?C# ImageFormat.Check使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Imaging.ImageFormat
的用法示例。
在下文中一共展示了ImageFormat.Check方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ToString
/// <summary>
/// Converts an SwiftBitmap to a base64 string and returns it
/// </summary>
/// <param name="desiredFormat">Desired SwiftBitmap format (defaults to Jpeg)</param>
/// <returns>The SwiftBitmap in base64 string format</returns>
public string ToString(ImageFormat desiredFormat)
{
Contract.Requires<NullReferenceException>(InternalBitmap != null);
desiredFormat = desiredFormat.Check(ImageFormat.Jpeg);
using (MemoryStream Stream = new MemoryStream())
{
InternalBitmap.Save(Stream, desiredFormat);
return Stream.ToArray().ToString(Base64FormattingOptions.None);
}
}
示例2: ToBase64
/// <summary>
/// Converts an image to a base64 string and returns it
/// </summary>
/// <param name="Image">Image to convert</param>
/// <param name="DesiredFormat">Desired image format (defaults to Jpeg)</param>
/// <returns>The image in base64 string format</returns>
public static string ToBase64(this System.Drawing.Image Image, ImageFormat DesiredFormat = null)
{
DesiredFormat = DesiredFormat.Check(ImageFormat.Jpeg);
using (MemoryStream Stream = new MemoryStream())
{
Image.Save(Stream, DesiredFormat);
return Stream.ToArray().ToString(Base64FormattingOptions.None);
}
}