当前位置: 首页>>代码示例>>C#>>正文


C# Imaging.ImageFormat类代码示例

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


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


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