public static string GetContentTypeByImageFormat(ImageFormat format) { string ctype = "image/x-unknown"; if (format.Equals(ImageFormat.Gif)) { ctype = "image/gif"; } else if (format.Equals(ImageFormat.Jpeg)) { ctype = "image/jpeg"; } else if (format.Equals(ImageFormat.Png)) { ctype = "image/png"; } else if (format.Equals(ImageFormat.Bmp) || format.Equals(ImageFormat.MemoryBmp)) { ctype = "image/bmp"; } else if (format.Equals(ImageFormat.Icon)) { ctype = "image/x-icon"; } else if (format.Equals(ImageFormat.Tiff)) { ctype = "image/tiff"; } return(ctype); }
/// <summary> /// Gets the image type representation for a mimetype /// </summary> /// <param name="format">Content mimetype</param> /// <returns>Image type</returns> private ImagePartType GetImagePartType(ImageFormat format) { if (format.Equals(ImageFormat.Jpeg)) { return(ImagePartType.Jpeg); } else if (format.Equals(ImageFormat.Emf)) { return(ImagePartType.Emf); } else if (format.Equals(ImageFormat.Gif)) { return(ImagePartType.Gif); } else if (format.Equals(ImageFormat.Icon)) { return(ImagePartType.Icon); } else if (format.Equals(ImageFormat.Png)) { return(ImagePartType.Png); } else if (format.Equals(ImageFormat.Tiff)) { return(ImagePartType.Tiff); } else if (format.Equals(ImageFormat.Wmf)) { return(ImagePartType.Wmf); } else { return(ImagePartType.Bmp); } }
/// <summary> /// /// </summary> /// <param name="imageFormat"></param> /// <returns></returns> private string GetContentType(ImageFormat imageFormat) { if (imageFormat.Equals(ImageFormat.Gif)) { return("image/gif"); } else if (imageFormat.Equals(ImageFormat.Jpeg)) { return("image/jpeg"); } else if (imageFormat.Equals(ImageFormat.Png)) { return("image/png"); } else if (imageFormat.Equals(ImageFormat.Bmp)) { return("image/bmp"); } else if (imageFormat.Equals(ImageFormat.Tiff)) { return("image/tiff"); } else if (imageFormat.Equals(ImageFormat.Icon)) { return("image/vnd.microsoft.icon"); } else if (imageFormat.Equals(ImageFormat.Wmf)) { return("image/wmf"); } else { return(string.Empty); } }
public static string GetImgFormatName(ImageFormat format) { if (format.Equals(ImageFormat.Bmp)) { return("bmp"); } if (format.Equals(ImageFormat.Emf)) { return("emf"); } if (format.Equals(ImageFormat.Exif)) { return("exif"); } if (format.Equals(ImageFormat.Gif)) { return("gif"); } if (format.Equals(ImageFormat.Icon)) { return("icon"); } if (format.Equals(ImageFormat.Jpeg)) { return("jpeg"); } if (format.Equals(ImageFormat.MemoryBmp)) { return("MemoryBMP"); } if (format.Equals(ImageFormat.Png)) { return("png"); } if (format.Equals(ImageFormat.Tiff)) { return("tiff"); } if (format.Equals(ImageFormat.Wmf)) { return("wmf"); } return("jpg"); }
/// <summary> /// Загрузить изображение из его данных. /// </summary> private void LoadImage() { if (Image == null || Image.Data == null) { source = null; } else if (IsSvg) { using (MemoryStream memStream = new MemoryStream(Image.Data)) { SvgDocument svgDocument = SvgDocument.Open <SvgDocument>(memStream); source = svgDocument.Draw(); DataSize = (int)memStream.Length; } ImageSize = new Size(source.Width, source.Height); Format = "Svg"; } else { // using не используется, т.к. поток memStream должен существовать одновременно с изображением MemoryStream memStream = new MemoryStream(Image.Data); source = System.Drawing.Image.FromStream(memStream); DataSize = (int)memStream.Length; ImageSize = new Size(source.Width, source.Height); ImageFormat imageFormat = source.RawFormat; if (imageFormat.Equals(ImageFormat.Gif)) { Format = "Gif"; } else if (imageFormat.Equals(ImageFormat.Jpeg)) { Format = "Jpeg"; } else if (imageFormat.Equals(ImageFormat.Png)) { Format = "Png"; } else { Format = ""; } } }
internal static string GetImageMimeType(ImageFormat format) { string mimeType = "image/x-unknown"; if (format.Equals(ImageFormat.Gif)) { mimeType = "image/gif"; } else if (format.Equals(ImageFormat.Jpeg)) { mimeType = "image/jpeg"; } else if (format.Equals(ImageFormat.Png)) { mimeType = "image/png"; } else if (format.Equals(ImageFormat.Bmp) || format.Equals(ImageFormat.MemoryBmp)) { mimeType = "image/bmp"; } else if (format.Equals(ImageFormat.Tiff)) { mimeType = "image/tiff"; } else if (format.Equals(ImageFormat.Icon)) { mimeType = "image/x-icon"; } return mimeType; }
/// <summary> /// Based on the raw format of the bitmap object, return the extension that best fits. /// </summary> /// <param name="bitmap">Bitmap object to be examined.</param> /// <returns>Returns extention based on raw format.</returns> public static string GetFileExtension(Bitmap bitmap) { if (bitmap == null) { throw new ArgumentNullException("bitmap cannot be null."); } ImageFormat Format = GetImageFormat(bitmap); if (Format.Equals(ImageFormat.Jpeg)) { return("jpg"); } else if (Format.Equals(ImageFormat.Bmp)) { return("bmp"); } else if (Format.Equals(ImageFormat.Emf)) { return("emf"); } else if (Format.Equals(ImageFormat.Exif)) { return("exf"); } else if (Format.Equals(ImageFormat.Gif)) { return("gif"); } else if (Format.Equals(ImageFormat.MemoryBmp)) { return("mbmp"); } else if (Format.Equals(ImageFormat.Png)) { return("png"); } else if (Format.Equals(ImageFormat.Tiff)) { return("tif"); } else if (Format.Equals(ImageFormat.Wmf)) { return("wmf"); } else { return(string.Empty); } }
public static MediaTypeHeaderValue ConvertFromImageFormat(ImageFormat imageFormat) { if (imageFormat.Equals(ImageFormat.Png)) { return(new MediaTypeHeaderValue("image/png")); } throw new ArgumentException("Unsupported ImageFormat."); }
/// <summary> /// コンストラクタ。 /// </summary> public ScreenShot() { _dir = Option.Instance().SaveDirectory; _fileFmt = Option.Instance().FileNameFormat; _imgFmt = Option.Instance().ImageFormat; // 拡張子を設定する。Jpegの場合は"jpg"、それ以外は名称をそのままに小文字に変換している。 _ext = _imgFmt.Equals(ImageFormat.Jpeg) ? "jpg" : _imgFmt.ToString().ToLower(); _matches = Rx.Matches(_fileFmt); }
public void TestEquals() { Assert.IsTrue(BmpImageFormat.Equals(BmpImageFormat), "Bmp-Bmp"); Assert.IsTrue(EmfImageFormat.Equals(EmfImageFormat), "Emf-Emf"); Assert.IsTrue(ExifImageFormat.Equals(ExifImageFormat), "Exif-Exif"); Assert.IsTrue(GifImageFormat.Equals(GifImageFormat), "Gif-Gif"); Assert.IsTrue(TiffImageFormat.Equals(TiffImageFormat), "Tiff-Tiff"); Assert.IsTrue(PngImageFormat.Equals(PngImageFormat), "Png-Png"); Assert.IsTrue(MemoryBmpImageFormat.Equals(MemoryBmpImageFormat), "MemoryBmp-MemoryBmp"); Assert.IsTrue(IconImageFormat.Equals(IconImageFormat), "Icon-Icon"); Assert.IsTrue(JpegImageFormat.Equals(JpegImageFormat), "Jpeg-Jpeg"); Assert.IsTrue(WmfImageFormat.Equals(WmfImageFormat), "Wmf-Wmf"); Assert.IsTrue(CustomImageFormat.Equals(CustomImageFormat), "Custom-Custom"); Assert.IsFalse(BmpImageFormat.Equals(EmfImageFormat), "Bmp-Emf"); Assert.IsFalse(BmpImageFormat.Equals("Bmp"), "Bmp-String-1"); Assert.IsFalse(BmpImageFormat.Equals(BmpImageFormat.ToString()), "Bmp-String-2"); }
/// <summary> /// Get the format of the image. /// </summary> /// <param name="format">Format of the image.</param> /// <returns> /// A string with the name of the format - compression. /// </returns> private static string GetEncoderInfo(ImageFormat format) { while (true) { if (format.Equals(ImageFormat.Jpeg)) { return("JPEG"); } else if (format.Equals(ImageFormat.Png)) { return("PNG"); } else if (format.Equals(ImageFormat.Bmp)) { return("BMP"); } } }
public void Save(Bitmap Image, ImageFormat Format, string FileName, TextLocalizer Status, RecentViewModel Recents) { using (Image) Image.WriteToClipboard(Format.Equals(ImageFormat.Png)); Status.LocalizationKey = nameof(LanguageManager.ImgSavedClipboard); LanguageManager.Instance.LanguageChanged += L => RaisePropertyChanged(nameof(Display)); }
public static string GetExtensionFromImageFormat(ImageFormat img) { if (img.Equals(ImageFormat.Jpeg)) { return("jpg"); } else if (img.Equals(ImageFormat.Png)) { return("png"); } else if (img.Equals(ImageFormat.Gif)) { return("gif"); } else if (img.Equals(ImageFormat.Bmp)) { return("bmp"); } else if (img.Equals(ImageFormat.Tiff)) { return("tif"); } else if (img.Equals(ImageFormat.Icon)) { return("ico"); } else if (img.Equals(ImageFormat.Emf)) { return("emf"); } else if (img.Equals(ImageFormat.Wmf)) { return("wmf"); } else if (img.Equals(ImageFormat.Exif)) { return("exif"); } else if (img.Equals(ImageFormat.MemoryBmp)) { return("bmp"); } return("unknown"); }
// Taken from http://www.java2s.com/Code/CSharp/File-Stream/ImageFormattoExtension.htm // And modified. public static string ImageFormatToExtension(ImageFormat imageFormat) { if (imageFormat.Equals(ImageFormat.Bmp)) { return("BMP"); } else if (imageFormat.Equals(ImageFormat.MemoryBmp)) { return("BMP"); } else if (imageFormat.Equals(ImageFormat.Wmf)) { return("EMF"); } else if (imageFormat.Equals(ImageFormat.Wmf)) { return("WMF"); } else if (imageFormat.Equals(ImageFormat.Gif)) { return("GIF"); } else if (imageFormat.Equals(ImageFormat.Jpeg)) { return("JPG"); } else if (imageFormat.Equals(ImageFormat.Png)) { return("PNG"); } else if (imageFormat.Equals(ImageFormat.Tiff)) { return("TIF"); } else if (imageFormat.Equals(ImageFormat.Exif)) { return("EXF"); } else if (imageFormat.Equals(ImageFormat.Icon)) { return("ICO"); } return(""); }
public override Task ExecuteResultAsync(ActionContext context) { // verify properties if (EncodedImageBytes == null) { if (Image == null) { throw new ArgumentNullException("Image"); } } if (ImageFormat == null) { throw new ArgumentNullException("ImageFormat"); } // output context.HttpContext.Response.Clear(); if (ImageFormat.Equals(ImageFormat.Bmp)) { context.HttpContext.Response.ContentType = "image/bmp"; } if (ImageFormat.Equals(ImageFormat.Gif)) { context.HttpContext.Response.ContentType = "image/gif"; } if (ImageFormat.Equals(ImageFormat.Icon)) { context.HttpContext.Response.ContentType = "image/vnd.microsoft.icon"; } if (ImageFormat.Equals(ImageFormat.Jpeg)) { context.HttpContext.Response.ContentType = "image/jpeg"; } if (ImageFormat.Equals(ImageFormat.Png)) { context.HttpContext.Response.ContentType = "image/png"; } if (ImageFormat.Equals(ImageFormat.Tiff)) { context.HttpContext.Response.ContentType = "image/tiff"; } if (ImageFormat.Equals(ImageFormat.Wmf)) { context.HttpContext.Response.ContentType = "image/wmf"; } // output stream Stream outputStream = context.HttpContext.Response.Body; if (EncodedImageBytes != null) { outputStream.WriteAsync(EncodedImageBytes, 0, EncodedImageBytes.Length); } return(base.ExecuteResultAsync(context)); }
static void SaveImage(Bitmap image, string targetFileName) { if (exportFormat.Equals(ImageFormat.Jpeg)) { EncoderParameters encoderParams = new EncoderParameters(); encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, jpegQuality); image.Save(targetFileName, imageEncoder, encoderParams); } else if (exportFormat.Equals(ImageFormat.Gif)) { OctreeQuantizer q = new OctreeQuantizer(255, 8); image = q.Quantize(image); image.Save(targetFileName, exportFormat); } else { image.Save(targetFileName, exportFormat); } }
/// <summary> /// Convert Image to Byte[] /// </summary> /// <param name="image"></param> /// <returns></returns> public static byte[] ImageToBytes(Image image) { ImageFormat format = image.RawFormat; using (MemoryStream ms = new MemoryStream()) { if (format.Equals(ImageFormat.Jpeg)) { EncoderParameters ep = new EncoderParameters(1); ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)90); ImageCodecInfo ici = ImageCodecInfo.GetImageEncoders().FirstOrDefault(a => a.MimeType == "image/jpeg"); image.Save(ms, ici, ep); } else if (format.Equals(ImageFormat.Png)) { image.Save(ms, ImageFormat.Png); } else if (format.Equals(ImageFormat.Bmp)) { image.Save(ms, ImageFormat.Bmp); } else if (format.Equals(ImageFormat.Gif)) { image.Save(ms, ImageFormat.Gif); } else if (format.Equals(ImageFormat.Icon)) { image.Save(ms, ImageFormat.Icon); } else { EncoderParameters ep = new EncoderParameters(1); ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)90); ImageCodecInfo ici = ImageCodecInfo.GetImageEncoders().FirstOrDefault(a => a.MimeType == "image/jpeg"); image.Save(ms, ici, ep); } byte[] buffer = new byte[ms.Length]; //Image.Save()会改变MemoryStream的Position,需要重新Seek到Begin ms.Seek(0, SeekOrigin.Begin); ms.Read(buffer, 0, buffer.Length); return(buffer); } }
/// <summary> /// Gets the exif. /// </summary> /// <param name="bytes">The bytes.</param> /// <param name="format">The format.</param> /// <returns>System.Byte[][].</returns> public byte[] SetOrientation(byte[] bytes, ImageFormat format) { if (format.Equals(ImageFormat.Jpeg)) { var orientation = new ImageOrientation(bytes); bytes = orientation.OrientImage(); } return(bytes); }
public static string ConvertToContentType(ImageFormat format) { string imageFormatString = ConvertToString(format); if (format.Equals(ImageFormat.Icon)) { imageFormatString = "vnd.microsoft.icon"; } return(string.Concat("image/", imageFormatString)); }
public static void SaveBitmap(Bitmap bitmap, string fileName, ImageFormat imageFormat) { if (imageFormat.Equals(ImageFormat.Gif)) { SaveGif(bitmap, fileName); } else if (imageFormat.Equals(ImageFormat.Tiff)) { SaveTIFF(bitmap, fileName); } else if (imageFormat.Equals(ImageFormat.Jpeg)) { SaveJpeg(bitmap, fileName, 80); } else { bitmap.Save(fileName, imageFormat); } }
/// <summary> /// 图片转化为byte /// </summary> /// <param name="image"></param> /// <returns></returns> public static byte[] ImageToBytes(Image image) { ImageFormat format = image.RawFormat; byte[] buffer = null; try { using (MemoryStream ms = new MemoryStream()) { if (format.Equals(ImageFormat.Jpeg)) { Bitmap t = new Bitmap(image); t.Save(ms, ImageFormat.Jpeg); } else if (format.Equals(ImageFormat.Png)) { image.Save(ms, ImageFormat.Png); } else if (format.Equals(ImageFormat.Bmp)) { image.Save(ms, ImageFormat.Bmp); } else if (format.Equals(ImageFormat.Gif)) { image.Save(ms, ImageFormat.Gif); } else if (format.Equals(ImageFormat.Icon)) { image.Save(ms, ImageFormat.Icon); } buffer = new byte[ms.Length]; //Image.Save()会改变MemoryStream的Position,需要重新Seek到Begin ms.Seek(0, SeekOrigin.Begin); ms.Read(buffer, 0, buffer.Length); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(buffer); }
public bool UpdateProductDefatulePictureSize(int pictureId) { var picture = GetPictureById(pictureId); byte[] binary = LoadPictureBinary(picture); MemoryStream ms1 = new MemoryStream(binary); Image image = System.Drawing.Image.FromStream(ms1); if (image.Width != 550 || image.Height == 360) { Bitmap newImg = new Bitmap(image, 550, 360); ImageFormat format = image.RawFormat; using (MemoryStream ms = new MemoryStream()) { if (format.Equals(ImageFormat.Jpeg)) { newImg.Save(ms, ImageFormat.Jpeg); } else if (format.Equals(ImageFormat.Png)) { newImg.Save(ms, ImageFormat.Png); } else if (format.Equals(ImageFormat.Bmp)) { newImg.Save(ms, ImageFormat.Bmp); } else if (format.Equals(ImageFormat.Gif)) { newImg.Save(ms, ImageFormat.Gif); } else if (format.Equals(ImageFormat.Icon)) { newImg.Save(ms, ImageFormat.Icon); } byte[] buffer = new byte[ms.Length]; ms.Seek(0, SeekOrigin.Begin); ms.Read(buffer, 0, buffer.Length); UpdatePicture(picture.Id, buffer, picture.MimeType, picture.SeoFilename, picture.AltAttribute, picture.TitleAttribute); return(true); } } return(false); }
public Task Save(Bitmap Image, ImageFormat Format, string FileName, RecentViewModel Recents) { Image.WriteToClipboard(Format.Equals(ImageFormat.Png)); _systemTray.ShowMessage(LanguageManager.Instance.ImgSavedClipboard); LanguageManager.Instance.LanguageChanged += L => RaisePropertyChanged(nameof(Display)); return(Task.CompletedTask); }
public override void Save(Stream stream, ImageFormat format) { if (!format.Equals(ImageFormat.Jpeg)) { throw new ArgumentOutOfRangeException("format", format, "Only JPEG format supported"); } var wbm = (WriteableBitmap)this; wbm.SaveJpeg(stream, _width, _height, 0, 100); }
/// <summary> /// Gets the correct mime-type for the given <see cref="T:System.Drawing.Imaging.ImageFormat" />. /// </summary> /// <param name="imageFormat">The <see cref="T:System.Drawing.Imaging.ImageFormat" />.</param> /// <returns>The correct mime-type for the given <see cref="T:System.Drawing.Imaging.ImageFormat" />.</returns> public static string GetMimeType(this ImageFormat imageFormat) { if (imageFormat.Equals(ImageFormat.Icon)) { return("image/x-icon"); } ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); return(codecs.First(codec => codec.FormatID == imageFormat.Guid).MimeType); }
public static byte[] getQRcode(string qrcode) { QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; qrCodeEncoder.QRCodeScale = 4; qrCodeEncoder.QRCodeVersion = 3; qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; System.Drawing.Image image = qrCodeEncoder.Encode(qrcode); ImageFormat format = image.RawFormat; using (MemoryStream ms = new MemoryStream()) { if (format.Equals(ImageFormat.Jpeg)) { image.Save(ms, ImageFormat.Jpeg); } else if (format.Equals(ImageFormat.Png)) { image.Save(ms, ImageFormat.Png); } else if (format.Equals(ImageFormat.Bmp)) { image.Save(ms, ImageFormat.Bmp); } else if (format.Equals(ImageFormat.Gif)) { image.Save(ms, ImageFormat.Gif); } else if (format.Equals(ImageFormat.Icon)) { image.Save(ms, ImageFormat.Icon); } else { image.Save(ms, ImageFormat.Png); } byte[] buffer = new byte[ms.Length]; ms.Seek(0, SeekOrigin.Begin); ms.Read(buffer, 0, buffer.Length); return(buffer); } }
public static byte[] getLogoFile(string LogoFile) { if (!File.Exists(LogoFile)) { return(null); } using (System.Drawing.Image img = Bitmap.FromFile(LogoFile)) { ImageFormat format = img.RawFormat; using (MemoryStream ms = new MemoryStream()) { if (format.Equals(ImageFormat.Jpeg)) { img.Save(ms, ImageFormat.Jpeg); } else if (format.Equals(ImageFormat.Png)) { img.Save(ms, ImageFormat.Png); } else if (format.Equals(ImageFormat.Bmp)) { img.Save(ms, ImageFormat.Bmp); } else if (format.Equals(ImageFormat.Gif)) { img.Save(ms, ImageFormat.Gif); } else if (format.Equals(ImageFormat.Icon)) { img.Save(ms, ImageFormat.Icon); } else { img.Save(ms, ImageFormat.Png); } byte[] buffer = new byte[ms.Length]; ms.Seek(0, SeekOrigin.Begin); ms.Read(buffer, 0, buffer.Length); return(buffer); } } }
/// <summary> /// Convert Image to Byte[] /// </summary> /// <param name="image"></param> /// <returns></returns> public static byte[] ImageToBytes(Image image) { byte[] buffer = null; try { //ImageFormat format = image.RawFormat; ImageFormat format = ImageFormat.Bmp; using (MemoryStream ms = new MemoryStream()) { if (format.Equals(ImageFormat.Jpeg)) { image.Save(ms, ImageFormat.Jpeg); } else if (format.Equals(ImageFormat.Png)) { image.Save(ms, ImageFormat.Png); } else if (format.Equals(ImageFormat.Bmp)) { image.Save(ms, ImageFormat.Bmp); } else if (format.Equals(ImageFormat.Gif)) { image.Save(ms, ImageFormat.Gif); } else if (format.Equals(ImageFormat.Icon)) { image.Save(ms, ImageFormat.Icon); } buffer = new byte[ms.Length]; //Image.Save()会改变MemoryStream的Position,需要重新Seek到Begin ms.Seek(0, SeekOrigin.Begin); ms.Read(buffer, 0, buffer.Length); return(buffer); } } catch (Exception ex) { LogHelper.AppLoger.Error(ex); } return(buffer); }
public byte[] SaveBmp(Bitmap bmp, Image img) { MemoryStream ms = new MemoryStream(); ImageFormat imgFormat = img.RawFormat; if (imgFormat.Equals(ImageFormat.Png) || imgFormat.Equals(ImageFormat.Gif)) { bmp.Save(ms, ImageFormat.Png); } else { bmp.Save(ms, ImageFormat.Jpeg); } var result = ms.ToArray(); ms.Dispose(); return(result); }
/// <summary> /// Convert Image to Byte[] /// </summary> /// <param name="image"></param> /// <returns></returns> public static byte[] ImageToBytes(Bitmap image) { if (image == null) { return(new byte[0]); } ImageFormat format = image.RawFormat; using (MemoryStream ms = new MemoryStream()) { if (format.Equals(ImageFormat.Jpeg)) { image.Save(ms, ImageFormat.Jpeg); } else if (format.Equals(ImageFormat.Png)) { image.Save(ms, ImageFormat.Png); } else if (format.Equals(ImageFormat.Bmp)) { image.Save(ms, ImageFormat.Bmp); } else if (format.Equals(ImageFormat.Gif)) { image.Save(ms, ImageFormat.Gif); } else if (format.Equals(ImageFormat.Icon)) { image.Save(ms, ImageFormat.Icon); } else { image.Save(ms, ImageFormat.Bmp); } byte[] buffer = new byte[ms.Length]; //Image.Save()会改变MemoryStream的Position,需要重新Seek到Begin ms.Seek(0, SeekOrigin.Begin); ms.Read(buffer, 0, buffer.Length); return(buffer); } }