• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Imaging.ImageFormat类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Drawing.Imaging.ImageFormat的典型用法代码示例。如果您正苦于以下问题:C# ImageFormat类的具体用法?C# ImageFormat怎么用?C# ImageFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ImageFormat类属于System.Drawing.Imaging命名空间,在下文中一共展示了ImageFormat类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Save

		/// <summary>
		/// Saves the specified render target as an image with the specified format.
		/// </summary>
		/// <param name="renderTarget">The render target to save.</param>
		/// <param name="stream">The stream to which to save the render target data.</param>
		/// <param name="format">The format with which to save the image.</param>
		private void Save(RenderTarget2D renderTarget, Stream stream, ImageFormat format)
		{
			var data = new Color[renderTarget.Width * renderTarget.Height];
			renderTarget.GetData(data);

			Save(data, renderTarget.Width, renderTarget.Height, stream, format);
		}
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:13,代码来源:OSXSurfaceSaver.cs


示例2: SaveImage

 public void SaveImage(string filename, ImageFormat format)
 {
     if (bitmap != null)
     {
         bitmap.Save(filename, format);
     }
 }
开发者ID:nacker90,项目名称:Open-Source-Automation,代码行数:7,代码来源:Weather.cs


示例3: CompressImage

        public static MemoryStream CompressImage(ImageFormat format, Stream stream, Size size, bool isbig)
        {
            using (var image = Image.FromStream(stream))
            {
                Image bitmap = new Bitmap(size.Width, size.Height);
                Graphics g = Graphics.FromImage(bitmap);
                g.InterpolationMode = InterpolationMode.High;
                g.SmoothingMode = SmoothingMode.HighQuality;
                g.Clear(Color.Transparent);

                //按指定面积缩小
                if (!isbig)
                {
                    g.DrawImage(image,
                                new Rectangle(0, 0, size.Width, size.Height),
                                ImageCutSize(image, size),
                                GraphicsUnit.Pixel);
                }
                //按等比例缩小
                else
                {
                    g.DrawImage(image,
                                new Rectangle(0, 0, size.Width, size.Height),
                                new Rectangle(0, 0, image.Width, image.Height),
                                GraphicsUnit.Pixel);
                }

                var compressedImageStream = new MemoryStream();
                bitmap.Save(compressedImageStream, format);
                g.Dispose();
                bitmap.Dispose();
                return compressedImageStream;
            }
        }
开发者ID:ideayapai,项目名称:docviewer,代码行数:34,代码来源:ImageCompress.cs


示例4: CreateImageFrom

        public static ImageResult CreateImageFrom(byte[] bytes, ImageFormat format)
        {
            byte[] nonIndexedImageBytes;

            using (var memoryStream = new MemoryStream(bytes))
            using (var image = Image.FromStream(memoryStream))
            using (var temporaryBitmap = new Bitmap(image.Width, image.Height))
            {
                using (var graphics = Graphics.FromImage(temporaryBitmap))
                {
                    graphics.DrawImage(image, new Rectangle(0, 0, temporaryBitmap.Width, temporaryBitmap.Height),
                        0, 0, temporaryBitmap.Width, temporaryBitmap.Height, GraphicsUnit.Pixel);
                }

                ImagePropertyItems.Copy(image, temporaryBitmap);

                using (var saveStream = new MemoryStream())
                {
                    temporaryBitmap.Save(saveStream, format);
                    nonIndexedImageBytes = saveStream.ToArray();
                }
            }
            
            return new ImageResult(nonIndexedImageBytes, format);
        }
开发者ID:GorelH,项目名称:FluentImageResizing,代码行数:25,代码来源:Resizer.cs


示例5: ReturnImage

 protected void ReturnImage(HttpContextBase context, string file, ImageFormat imageFormat, string contentType)
 {
     var buffer = GetImage(file, imageFormat);
     context.Response.ContentType = "image/png";
     context.Response.BinaryWrite(buffer);
     context.Response.Flush();
 }
开发者ID:ActiveCommerce,项目名称:sctestrunner,代码行数:7,代码来源:BaseHttpHandler.cs


示例6: frmFondo

 /// <summary>
 /// Constructor por defecto.
 /// </summary>
 public frmFondo(string ruta, ImageFormat formato, bool original, int width, int height)
 {
     InitializeComponent();
     this.original = original;
     this.width = width;
     this.height = height;
     //Establecemos el ancho de la forma a la resolución actual de pantalla
     this.Bounds = Screen.GetBounds(this.ClientRectangle);
     //Inicializamos las variables
     origen = new Point(0, 0);
     destino = new Point(0, 0);
     actual = new Point(0, 0);
     //De momento nuestro gráfico es nulo
     areaSeleccionada = this.CreateGraphics();
     //El estilo de línea del lápiz serán puntos
     lapizActual.DashStyle = DashStyle.Solid;
     //Establecemos falsa la variable que nos indica si el boton presionado fue el boton izquierdo
     BotonIzq = false;
     //Delegados para manejar los eventos del mouse y poder dibujar el rectangulo del área que deseamos copiar
     this.MouseDown += new MouseEventHandler(mouse_Click);
     this.MouseUp += new MouseEventHandler(mouse_Up);
     this.MouseMove += new MouseEventHandler(mouse_Move);
     this.ruta = ruta;
     this.formato = formato;
 }
开发者ID:EduardoOrtiz89,项目名称:ClipSaveImage,代码行数:28,代码来源:frmFondo.cs


示例7: GetResizedImage

        byte[] GetResizedImage(Stream originalStream, ImageFormat imageFormat, int width, int height)
        {
            Bitmap imgIn = new Bitmap(originalStream);
            double y = imgIn.Height;
            double x = imgIn.Width;

            double factor = 1;
            if (width > 0)
            {
                factor = width / x;
            }
            else if (height > 0)
            {
                factor = height / y;
            }
            System.IO.MemoryStream outStream = new System.IO.MemoryStream();
            Bitmap imgOut = new Bitmap((int)(x * factor), (int)(y * factor));

            // Set DPI of image (xDpi, yDpi)
            imgOut.SetResolution(72, 72);

            Graphics g = Graphics.FromImage(imgOut);
            g.Clear(Color.White);
            g.DrawImage(imgIn, new Rectangle(0, 0, (int)(factor * x), (int)(factor * y)),
              new Rectangle(0, 0, (int)x, (int)y), GraphicsUnit.Pixel);

            imgOut.Save(outStream, imageFormat);
            return outStream.ToArray();
        }
开发者ID:ekelman,项目名称:jsflooring,代码行数:29,代码来源:SetImmageFile.cs


示例8: Set

        public static void Set(Uri uri, Style style, ImageFormat format)
        {
            Stream stream = new WebClient().OpenRead(uri.ToString());

            if (stream == null) return;

            Image img = Image.FromStream(stream);
            string tempPath = Path.Combine(Path.GetTempPath(), "img." + format.ToString());
            img.Save(tempPath, format);

            RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
            if (style == Style.Stretched)
            {
                key.SetValue(@"WallpaperStyle", 2.ToString());
                key.SetValue(@"TileWallpaper", 0.ToString());
            }

            if (style == Style.Centered)
            {
                key.SetValue(@"WallpaperStyle", 1.ToString());
                key.SetValue(@"TileWallpaper", 0.ToString());
            }

            if (style == Style.Tiled)
            {
                key.SetValue(@"WallpaperStyle", 1.ToString());
                key.SetValue(@"TileWallpaper", 1.ToString());
            }

            SystemParametersInfo(SpiSetdeskwallpaper,
                0,
                tempPath,
                SpifUpdateinifile | SpifSendwininichange);
        }
开发者ID:ashesxera,项目名称:Unsplasher,代码行数:34,代码来源:Wallpaper.cs


示例9: Save

 public static void Save(Stream imageStream, string fullImagePath, ImageFormat format)
 {
     using (Bitmap ImageBitmap = new Bitmap(imageStream))
     {
         Save(ImageBitmap, fullImagePath, format);
     }
 }
开发者ID:puentesarrin,项目名称:csharp-image-util,代码行数:7,代码来源:Saving.cs


示例10: ResizeImage

        public static Stream ResizeImage(Image image, ImageFormat format, int width, int height, bool preserveAspectRatio = true)
        {
            ImageHelper.ImageRotation(image);
            int newWidth;
            int newHeight;
            if (preserveAspectRatio)
            {
                int originalWidth = image.Width;
                int originalHeight = image.Height;
                float percentWidth = (float)width / (float)originalWidth;
                float percentHeight = (float)height / (float)originalHeight;
                float percent = percentHeight < percentWidth ? percentHeight : percentWidth;
                newWidth = (int)(originalWidth * percent);
                newHeight = (int)(originalHeight * percent);
            }
            else
            {
                newWidth = width;
                newHeight = height;
            }
            Image newImage = new Bitmap(newWidth, newHeight);

            using (Graphics graphicsHandle = Graphics.FromImage(newImage))
            {
                graphicsHandle.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphicsHandle.DrawImage(image, 0, 0, newWidth, newHeight);
            }
            //return newImage;
            var stream = new MemoryStream();
            newImage.Save(stream, format);
            stream.Position = 0;
            return stream;
        }
开发者ID:bitf12m015,项目名称:Tour-Pakistan,代码行数:33,代码来源:Utility.cs


示例11: Save

 public static Stream Save(this Bitmap bitmap, ImageFormat format)
 {
     var stream = new MemoryStream();
     bitmap.Save(stream, format);
     stream.Position = 0;
     return stream;
 }
开发者ID:joshcodes,项目名称:JoshCodes.Core,代码行数:7,代码来源:BitmapExtensions.cs


示例12: ScanImage

         public Image ScanImage(ImageFormat outputFormat, string fileName)
         {
              if (outputFormat == null)
                   throw new ArgumentNullException("outputFormat");

              FileIOPermission filePerm = new FileIOPermission(FileIOPermissionAccess.AllAccess, fileName);
              filePerm.Demand();

              ImageFile imageObject = null;

              try
              {
                   if (WiaManager == null)
                        WiaManager = new CommonDialogClass();

                   imageObject =
                        WiaManager.ShowAcquireImage(WiaDeviceType.ScannerDeviceType,
                             WiaImageIntent.GrayscaleIntent, WiaImageBias.MaximizeQuality, 
                             outputFormat.Guid.ToString("B"), false, true, true);

                   imageObject.SaveFile(fileName);
                   return Image.FromFile(fileName);
              }
              catch (COMException ex)
              {
                   string message = "Error scanning image";
                   throw new WiaOperationException(message, ex);
              }
              finally
              {
                   if (imageObject != null)
                        Marshal.ReleaseComObject(imageObject);
              }
         }
开发者ID:nguyenq,项目名称:VietOCR3.NET,代码行数:34,代码来源:WiaScannerAdapter.cs


示例13: ToBitmapSource

        /// <summary>
        /// To the bitmap source.
        /// </summary>
        /// <param name="bitmap">The bitmap.</param>
        /// <param name="format">The format.</param>
        /// <param name="creationOptions">The creation options.</param>
        /// <param name="cacheOptions">The cache options.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">bitmap</exception>
        public static BitmapSource ToBitmapSource(this Bitmap bitmap, ImageFormat format, BitmapCreateOptions creationOptions = BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption cacheOptions = BitmapCacheOption.OnLoad)
        {
            if (bitmap == null)
                throw new ArgumentNullException("bitmap");

            using (MemoryStream memoryStream = new MemoryStream())
            {
                try
                {
                    // You need to specify the image format to fill the stream.
                    // I'm assuming it is PNG
                    bitmap.Save(memoryStream, format);
                    memoryStream.Seek(0, SeekOrigin.Begin);

                    BitmapDecoder bitmapDecoder = BitmapDecoder.Create(
                        memoryStream,
                        creationOptions,
                        cacheOptions);

                    // This will disconnect the stream from the image completely...
                    WriteableBitmap writable =
            new WriteableBitmap(bitmapDecoder.Frames.Single());
                    writable.Freeze();

                    return writable;
                }
                catch (Exception)
                {
                    return null;
                }
            }
        }
开发者ID:sybold,项目名称:AcExtensionLibrary,代码行数:41,代码来源:BitmapExtensions.cs


示例14: SaveImageAs

 private void SaveImageAs(int bitmap, string fileName, ImageFormat imageFormat)
 {
     Bitmap image = new Bitmap(Image.FromHbitmap(new IntPtr(bitmap)),
         Image.FromHbitmap(new IntPtr(bitmap)).Width,
         Image.FromHbitmap(new IntPtr(bitmap)).Height);
     image.Save(fileName, imageFormat);
 }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:7,代码来源:ScreenCapture.cs


示例15: GenerateImage

 private void GenerateImage(
     HttpResponse response,
     string textToInsert,
     int width,
     int height,
     Color backgroundColor,
     FontFamily fontFamily,
     float emSize,
     Brush brush,
     float x,
     float y,
     string contentType,
     ImageFormat imageFormat)
 {
     using (Bitmap bitmap = new Bitmap(width, height))
     {
         using (Graphics graphics = Graphics.FromImage(bitmap))
         {
             graphics.Clear(backgroundColor);
             graphics.DrawString(textToInsert, new Font(fontFamily, emSize), brush, x, y);
             response.ContentType = contentType;
             bitmap.Save(response.OutputStream, imageFormat);
         }
     }
 }
开发者ID:nikolaynikolov,项目名称:Telerik,代码行数:25,代码来源:Default.aspx.cs


示例16: ConvertWordToImage

        /// <summary>
        /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法:
        /// ConvertPDF2Image("F:\\PdfFile.doc", "F:\\", "ImageFile", 1, 20, ImageFormat.Png, 256);
        /// </summary>
        /// <param name="pdfInputPath">Word文件路径</param>
        /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
        /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
        /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
        /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
        /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
        /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
        public static void ConvertWordToImage(string wordInputPath, string imageOutputPath,
            string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
        {
            try
            {
                // open word file
                Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);

                // validate parameter
                if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
                if (imageOutputPath.Trim().Length == 0) { imageOutputPath = Path.GetDirectoryName(wordInputPath); }
                if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
                if (imageName.Trim().Length == 0) { imageName = Path.GetFileNameWithoutExtension(wordInputPath); }
                if (startPageNum <= 0) { startPageNum = 1; }
                if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
                if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
                if (imageFormat == null) { imageFormat = ImageFormat.Png; }
                if (resolution <= 0) { resolution = 128; }

                ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat));
                imageSaveOptions.Resolution = resolution;

                // start to convert each page
                for (int i = startPageNum; i <= endPageNum; i++)
                {
                    imageSaveOptions.PageIndex = i - 1;
                    doc.Save(Path.Combine(imageOutputPath, imageName) + "_" + i.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
开发者ID:alqadasifathi,项目名称:OfficeTools.Pdf2Image.Word2Image,代码行数:45,代码来源:Program.cs


示例17: GetThumbnail

 public static Bitmap GetThumbnail(int width, int height, string filter, string caption, ImageFormat format, Image b)
 {
     Bitmap source = new Bitmap(b);
     source = new Bitmap(source.GetThumbnailImage(width, height, null, IntPtr.Zero));
     if (format == ImageFormat.Gif)
     {
         source = new OctreeQuantizer(0xff, 8).Quantize(source);
     }
     if ((filter.Length > 0) && filter.ToUpper().StartsWith("SHARPEN"))
     {
         string str = filter.Remove(0, 7).Trim();
         int nWeight = (str.Length > 0) ? Convert.ToInt32(str) : 11;
         BitmapFilter.Sharpen(source, nWeight);
     }
     if (caption.Length <= 0)
     {
         return source;
     }
     using (Graphics graphics = Graphics.FromImage(source))
     {
         StringFormat format2 = new StringFormat();
         format2.Alignment = StringAlignment.Center;
         format2.LineAlignment = StringAlignment.Center;
         using (Font font = new Font("Arial", 12f))
         {
             graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; 
             graphics.FillRectangle(new SolidBrush(Color.FromArgb(150, 0, 0, 0)), 0, source.Height - 20, source.Width, 20);
             graphics.DrawString(caption, font, Brushes.White, 0f, (float)(source.Height - 20));
             return source;
         }
     }
 }
开发者ID:BaoToan94,项目名称:q42.wheels.gimmage,代码行数:32,代码来源:ThumbnailGenerator.cs


示例18: GetImageFormat

        public static ImageFormatTypes GetImageFormat(ImageFormat type)
        {
            if (type == ImageFormat.Bmp)
                return ImageFormatTypes.imgBMP;
            else
                if (type == ImageFormat.Emf)
                    return ImageFormatTypes.imgEMF;
                else
                    if (type == ImageFormat.Exif)
                        return ImageFormatTypes.imgEXIF;
                    else
                        if (type == ImageFormat.Gif)
                            return ImageFormatTypes.imgGIF;
                        else
                            if (type == ImageFormat.Icon)
                                return ImageFormatTypes.imgICON;
                            else
                                if (type == ImageFormat.Jpeg)
                                    return ImageFormatTypes.imgJPEG;
                                else
                                    if (type == ImageFormat.Png)
                                        return ImageFormatTypes.imgPNG;
                                    else
                                        if (type == ImageFormat.Tiff)
                                            return ImageFormatTypes.imgTIFF;
                                        else
                                            if (type == ImageFormat.Wmf)
                                                return ImageFormatTypes.imgWMF;

            return ImageFormatTypes.imgNone;
        }
开发者ID:oo00spy00oo,项目名称:SharedTerminals,代码行数:31,代码来源:ImageFormatHandler.cs


示例19: CreateBitmap

        // Create a bitmap file of the mapDisplay supplied at construction.
        public void CreateBitmap(string fileName, RectangleF rect, ImageFormat imageFormat, float dpi)
        {
            float bitmapWidth, bitmapHeight; // size of the bitmap in pixels.
            int pixelWidth, pixelHeight; // bitmapWidth/Height, rounded up to integer.

            bitmapWidth = (rect.Width / 25.4F) * dpi;
            bitmapHeight = (rect.Height / 25.4F) * dpi;
            pixelWidth = (int)Math.Ceiling(bitmapWidth);
            pixelHeight = (int) Math.Ceiling(bitmapHeight);

            Bitmap bitmap = new Bitmap(pixelWidth, pixelHeight, PixelFormat.Format24bppRgb);
            bitmap.SetResolution(dpi, dpi);

            // Set the transform
            Matrix transform = Geometry.CreateInvertedRectangleTransform(rect, new RectangleF(0, 0, bitmapWidth, bitmapHeight));

            // And draw.
            mapDisplay.Draw(bitmap, transform);

            // JPEG and GIF have special code paths because the default Save method isn't
            // really good enough.
            if (imageFormat == ImageFormat.Jpeg)
                BitmapUtil.SaveJpeg(bitmap, fileName, 80);
            else if (imageFormat == ImageFormat.Gif)
                BitmapUtil.SaveGif(bitmap, fileName);
            else
                bitmap.Save(fileName, imageFormat);

            bitmap.Dispose();
        }
开发者ID:petergolde,项目名称:PurplePen,代码行数:31,代码来源:ExportBitmap.cs


示例20: PdfConvertImageInfo

            /// <summary>
            /// 将Pdf转换成图片存放在指定的文件夹下面并且返回转换了多少张图片(插件:O2S.Components.PDFRender4NETd)
            /// (使用:调用此方法传递参数,最后一个参数为模糊度(参考传递30))
            /// </summary>
            /// <param name="pdfInputPath">源PDF路径</param>
            /// <param name="imageOutpPutPath">PDF转化成图片之后存放的路径</param>
            /// <param name="imageFormat">转换的图片格式</param>
            /// <param name="difinition">传递参数模糊度</param>
            /// <returns>返回转换了多少张图片信息</returns>
            public static int PdfConvertImageInfo(string pdfInputPath, string imageOutpPutPath, ImageFormat imageFormat,
                float difinition)
            {
                try
                {
                    //第一步:判断需要转换的PDF是否存在
                    if (!File.Exists(pdfInputPath))
                    {
                        throw new System.Exception("PDF的路径不存在");
                    }
                    //第二步:判断存放转换后图片的地址是否存在
                    if (!Directory.Exists(imageOutpPutPath))
                    {
                        throw new System.Exception("存放图片的路径不存在");
                    }
                    //第三步:进行转换(使用插件O2S.Components.PDFRender4NET)
                    PDFFile pdfFile = PDFFile.Open(pdfInputPath);
                    int pageCount = pdfFile.PageCount;
                    for (int i = 0; i < pageCount; i++)
                    {
                        Bitmap bitmap = pdfFile.GetPageImage(i, difinition);
                        bitmap.Save(Path.Combine(imageOutpPutPath, i + "." + imageFormat), imageFormat);
                        bitmap.Dispose();
                    }
                    pdfFile.Dispose();
                    //第四步:返回PDF转换了多少张图片的个数
                    return pageCount;
                }
                catch (System.Exception exception)
                {

                    throw new System.Exception("PDF转换图片出现错误了,错误原因:" + exception.Message);
                }
            }
开发者ID:842549829,项目名称:Notify,代码行数:43,代码来源:MSOfficeConvertPdfHelper.cs



注:本文中的System.Drawing.Imaging.ImageFormat类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Imaging.Metafile类代码示例发布时间:2022-05-26
下一篇:
C# Imaging.ImageCodecInfo类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap