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


C# System.Drawing.Bitmap.Dispose方法代码示例

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


在下文中一共展示了System.Drawing.Bitmap.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateCursor

    public static Cursor CreateCursor(UIElement element, int xHotSpot, 
        int yHotSpot)
    {
      element.Measure(new Size(double.PositiveInfinity, 
        double.PositiveInfinity));
      element.Arrange(new Rect(0, 0, element.DesiredSize.Width, 
        element.DesiredSize.Height));

      RenderTargetBitmap rtb = 
        new RenderTargetBitmap((int)element.DesiredSize.Width, 
          (int)element.DesiredSize.Height, 96, 96, PixelFormats.Pbgra32);
      rtb.Render(element);

      PngBitmapEncoder encoder = new PngBitmapEncoder();
      encoder.Frames.Add(BitmapFrame.Create(rtb));

      MemoryStream ms = new MemoryStream();
      encoder.Save(ms);

      System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);

      ms.Close();
      ms.Dispose();     

      Cursor cur = InternalCreateCursor(bmp, xHotSpot, yHotSpot);

      bmp.Dispose();

      return cur;
    }
开发者ID:heinzsack,项目名称:DEV,代码行数:30,代码来源:CursorHelper.cs

示例2: Expand

        /// <summary>
        /// Expands the given image to with a transparent boarder of size determined in this class
        /// </summary>
        /// <param name="shred">the image to expand</param>
        /// <returns>an expanded image</returns>
        public static System.Drawing.Bitmap Expand(System.Drawing.Bitmap shred)
        {
            //read all images into memory
            System.Drawing.Bitmap finalImage = null;

            try
            {

                //create a bitmap to hold the stretched image (20px on each border
                finalImage = new System.Drawing.Bitmap(shred.Width + 2 * border, shred.Height + 2 * border);

                //get a graphics object from the image so we can draw on it
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
                {
                    //set background color, make it clear
                    g.Clear(System.Drawing.Color.Transparent);

                    g.DrawImage(shred, new System.Drawing.Rectangle(border, border, shred.Width, shred.Height));
                }

                return finalImage;
            }
            catch (Exception ex)
            {
                if (finalImage != null)
                    finalImage.Dispose();

                throw ex;
            }
            finally
            {
                //clean up memory
                shred.Dispose();
            }
        }
开发者ID:Algorithmix,项目名称:Papyrus,代码行数:40,代码来源:Expander.cs

示例3: DrawBinaryImage

        //BinaryWrite方法将一个二进制字符串写入HTTP输出流
        //public void BinaryWrite(byte[] buffer)
        public void DrawBinaryImage()
        {
            //要绘制的字符串
            string word = "5142";

            //设定画布大小,Math.Ceiling向上取整
            int width = int.Parse(Math.Ceiling(word.Length * 20.5).ToString());
            int height = 22;

            //创建一个指定大小的画布
            System.Drawing.Bitmap image = new System.Drawing.Bitmap(width, height);
            //创建一个指定的GDI+绘图图面
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
            try
            {
                //用白色填充图面
                g.Clear(System.Drawing.Color.White);

                //绘制背景噪音线
                Random r = new Random();
                int x1, x2, y1, y2;
                for (int i = 0; i < 2; i++)
                {
                    x1 = r.Next(image.Width);
                    x2 = r.Next(image.Width);
                    y1 = r.Next(image.Height);
                    y2 = r.Next(image.Height);
                    g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Black), x1, y1, x2, y2);
                }

                //绘制文字
                System.Drawing.Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold));
                System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush
                                                        (new System.Drawing.Rectangle(0, 0, image.Width, image.Height),
                                                        System.Drawing.Color.Blue, System.Drawing.Color.DarkRed, 5.2f, true);
                g.DrawString(word, font, brush, 2, 2);

                //绘制前景噪点
                int x, y;
                for (int i = 0; i < 100; i++)
                {
                    x = r.Next(image.Width);
                    y = r.Next(image.Height);
                    image.SetPixel(x, y, System.Drawing.Color.FromArgb(r.Next()));
                }

                //绘制边框
                g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
                System.IO.MemoryStream ms = new MemoryStream();
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                Response.ClearContent();
                Response.ContentType = "image/Gif";
                Response.BinaryWrite(ms.ToArray());
            }
            catch (Exception)
            {
                g.Dispose();
                image.Dispose();
            }
        }
开发者ID:ZhuangChen,项目名称:CSharpBasicTraining,代码行数:62,代码来源:04Built-in_Object.aspx.cs

示例4: convert

 public static BitmapSource convert(System.Drawing.Bitmap imageToConvert)
 {
     var bitmap = new System.Drawing.Bitmap(imageToConvert);
     BitmapSource convertedImage = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
     bitmap.Dispose();
     return convertedImage;
 }
开发者ID:punker76,项目名称:Musick,代码行数:7,代码来源:ImageConvert.cs

示例5: ProcessRequestAsync

 public override async Task ProcessRequestAsync(HttpContext context)
 {
     System.Drawing.Bitmap myBitmap = null;
     MemoryStream objMemoryStream = null;
     try
     {
         var strImageFileName = context.Request.QueryString["ImageUrl"].ToString();
         var height = context.Request.QueryString["height"];
         var width = context.Request.QueryString["width"];
         //create callback handler
         var myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
         //creat BitMap object from image path passed in querystring
         myBitmap =
            new System.Drawing.Bitmap(
                context.Server.MapPath("~/Images/Users/" + strImageFileName));
         //create unit object for height and width. This is to convert parameter passed in differen unit like pixel, inch into generic unit.
         var widthUnit = System.Web.UI.WebControls.Unit.Parse(width);
         var heightUnit = System.Web.UI.WebControls.Unit.Parse(height);
         //Resize actual image using width and height paramters passed in querystring
         var myThumbnail = myBitmap.GetThumbnailImage(Convert.ToInt16(widthUnit.Value),
             Convert.ToInt16(heightUnit.Value), myCallback, IntPtr.Zero);
         //Create memory stream and save resized image into memory stream
         objMemoryStream = new System.IO.MemoryStream();
         myThumbnail.Save(objMemoryStream, System.Drawing.Imaging.ImageFormat.Png);
         //Declare byte array of size memory stream and read memory stream data into array
         var imageData = new byte[objMemoryStream.Length];
         objMemoryStream.Position = 0;
         await objMemoryStream.ReadAsync(imageData, 0, (int)objMemoryStream.Length);
         //send contents of byte array as response to client (browser)
         context.Response.BinaryWrite(imageData);
         myBitmap.Dispose();
     }
     catch
     {
         context.Response.End();
     }
     finally
     {
         if (objMemoryStream != null)
             objMemoryStream.Dispose();
         if (myBitmap != null)
             myBitmap.Dispose();
     }
 }
开发者ID:rabbal,项目名称:AspNetWebForms-Forum,代码行数:44,代码来源:ImageHandler.ashx.cs

示例6: ToBitmapSource

        /// <summary>
        /// Converts a <see cref="System.Drawing.Image"/> into a WPF <see cref="BitmapSource"/>.
        /// </summary>
        /// <param name="source">The source image.</param>
        /// <returns>A BitmapSource</returns>
        public static BitmapSource ToBitmapSource(this System.Drawing.Image source)
        {
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(source);

            var bitSrc = ImageExtensions.ToBitmapSource(bitmap);

            bitmap.Dispose();
            bitmap = null;

            return bitSrc;
        }
开发者ID:Dig-Doug,项目名称:BU_KinectShowcase,代码行数:16,代码来源:ImageExtensions.cs

示例7: InitializeProfileOnGUI

 private void InitializeProfileOnGUI(Player profilePlayer)
 {
     if (File.Exists(@"GUI\Images\CustomVikings\" + profilePlayer.Name + ".png"))
     {
         System.Drawing.Image img = System.Drawing.Image.FromFile(@"GUI\Images\CustomVikings\" + profilePlayer.Name + ".png");
         System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img);
         BitmapSource bmpSrc = Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(),
             IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
         bmp.Dispose();
         VikingImage.Source = bmpSrc;
     }
 }
开发者ID:Bang-Bang-Studios,项目名称:Big-Sunday,代码行数:12,代码来源:MapWindow.xaml.cs

示例8: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            // System.Drawing.Image thumbnail_image = null;//缩略图

            System.Drawing.Image original_image = null;//原图
            System.Drawing.Bitmap final_image = null;//最终图片
            System.Drawing.Graphics graphic = null;
            MemoryStream ms = null;
            try
            {
                // Get the data
                HttpPostedFile jpeg_image_upload = Request.Files["Filedata"];

                // Retrieve the uploaded image
                original_image = System.Drawing.Image.FromStream(jpeg_image_upload.InputStream);
                int width = original_image.Width;
                int height = original_image.Height;
                final_image = new System.Drawing.Bitmap(original_image);
                graphic = System.Drawing.Graphics.FromImage(final_image);
                graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                graphic.DrawImage(original_image, 0, 0, width, height);
                ms = new MemoryStream();
                final_image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                string thumbnail_id = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                Thumbnail thumb = new Thumbnail(thumbnail_id, ms.GetBuffer());
                List<Thumbnail> thumbnails = Session["file_info"] as List<Thumbnail>;
                if (thumbnails == null)
                {
                    thumbnails = new List<Thumbnail>();
                    Session["file_info"] = thumbnails;
                }
                thumbnails.Add(thumb);

                Response.StatusCode = 200;
                Response.Write(thumbnail_id);

            }
            catch (Exception ex)
            {
                Response.StatusCode = 500;
                Response.Write("An error occured");
                Response.End();
            }
            finally
            {
                // Clean up
                if (final_image != null) final_image.Dispose();
                if (graphic != null) graphic.Dispose();
                if (ms != null) ms.Close();
                Response.End();
            }
        }
开发者ID:uwitec,项目名称:dx-shopsys,代码行数:52,代码来源:upload2.aspx.cs

示例9: UpdateTexture

        internal void UpdateTexture(string filename)
        {
            // This is the texture that the compute program will write into
            var bitmap = new System.Drawing.Bitmap(filename);
            var texture = new Texture(TextureTarget.Texture2D, bitmap, new SamplerParameters());
            texture.Initialize();
            bitmap.Dispose();
            Texture old = this.spriteTexture;
            this.spriteTexture = texture;
            this.SetUniform("sprite_texture", texture);

            old.Dispose();
        }
开发者ID:bitzhuwei,项目名称:CSharpGL,代码行数:13,代码来源:PointSpriteRenderer.cs

示例10: DoInitialize

 protected override void DoInitialize()
 {
     {
         // This is the texture that the compute program will write into
         var bitmap = new System.Drawing.Bitmap(@"Textures\PointSprite.png");
         var texture = new Texture(TextureTarget.Texture2D, bitmap, new SamplerParameters());
         texture.Initialize();
         bitmap.Dispose();
         this.spriteTexture = texture;
     }
     base.DoInitialize();
     this.SetUniform("spriteTexture", this.spriteTexture);
     this.SetUniform("factor", 50.0f);
 }
开发者ID:bitzhuwei,项目名称:CSharpGL,代码行数:14,代码来源:PointSpriteRenderer.cs

示例11: BitmapFormat

 void BitmapFormat(string path)
 {
     System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(path);
     if (bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)
         return;
     System.Drawing.Bitmap newBitmap = new System.Drawing.Bitmap(bitmap.Width, bitmap.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
     for (int y = 0; y < newBitmap.Height; y++)
         for (int x = 0; x < newBitmap.Width; x++)
             newBitmap.SetPixel(x, y, bitmap.GetPixel(x, y));
     bitmap.Dispose();
     if (File.Exists(path))
         File.Delete(path);
     newBitmap.Save(path, System.Drawing.Imaging.ImageFormat.Bmp);
     newBitmap.Dispose();
 }
开发者ID:bitnick1000,项目名称:ConvertPictureFormats,代码行数:15,代码来源:MainWindow.xaml.cs

示例12: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(100, 30);
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            g.Clear(System.Drawing.Color.Navy);
            string randomString = GetCaptchaString(6);
            context.HttpContext.Session["captchastring"] = randomString;
            #region
            //add noise , if dont want any noisy , then make it false.
            bool noisy = false;
            if (noisy)
            {
                var rand = new Random((int)DateTime.Now.Ticks);
                int i, r, x, y;
                var pen = new System.Drawing.Pen(System.Drawing.Color.Yellow);
                for (i = 1; i < 10; i++)
                {
                    pen.Color = System.Drawing.Color.FromArgb(
                    (rand.Next(0, 255)),
                    (rand.Next(0, 255)),
                    (rand.Next(0, 255)));

                    r = rand.Next(0, (130 / 3));
                    x = rand.Next(0, 130);
                    y = rand.Next(0, 30);

                    int m = x - r;
                    int n = y - r;
                    g.DrawEllipse(pen, m, n, r, r);
                }
            }
            //end noise
            #endregion
            g.DrawString(randomString, new System.Drawing.Font("Courier", 16), new System.Drawing.SolidBrush(System.Drawing.Color.WhiteSmoke), 2, 2);
            System.Web.HttpResponseBase response = context.HttpContext.Response;
            response.ContentType = "image/jpeg";
            bmp.Save(response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            bmp.Dispose();
        }
开发者ID:anicao,项目名称:Aguila,代码行数:39,代码来源:CotizaExpressModel.cs

示例13: GetMaskIPictureDispFromBitmap

 public static stdole.IPictureDisp GetMaskIPictureDispFromBitmap(System.Drawing.Bitmap bmp)
 {
     System.Drawing.Bitmap mask = new System.Drawing.Bitmap(bmp);
     try
     {
         for (int x = 0; x < mask.Width; x++)
         {
             for (int y = 0; y < mask.Height; y++)
             {
                 if (mask.GetPixel(x, y).A == 0)
                     mask.SetPixel(x, y, System.Drawing.Color.White);
                 else
                     mask.SetPixel(x, y, System.Drawing.Color.Black);
             }
         }
         return GetIPictureDispFromImage(mask);
     }
     finally
     {
         mask.Dispose();
     }
 }
开发者ID:japj,项目名称:bidshelper,代码行数:22,代码来源:ImageToPictureDispConverter.cs

示例14: generateSnapshot

        public void generateSnapshot(string folderIssue)
        {
            try
              {
            string snapshot = Path.Combine(folderIssue, "snapshot.png");

            // get the state of COM
            ComApi.InwOpState10 oState = ComBridge.State;
            // get the IO plugin for image
            ComApi.InwOaPropertyVec options = oState.GetIOPluginOptions("lcodpimage");

            //export the viewpoint to the image
            oState.DriveIOPlugin("lcodpimage", snapshot, options);
            System.Drawing.Bitmap oBitmap = new System.Drawing.Bitmap(snapshot);
            System.IO.MemoryStream ImageStream = new System.IO.MemoryStream();
            oBitmap.Save(ImageStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            oBitmap.Dispose();

              }
              catch (System.Exception ex1)
              {
            MessageBox.Show("exception: " + ex1);
              }
        }
开发者ID:WeConnect,项目名称:issue-tracker,代码行数:24,代码来源:NavisWindow.xaml.cs

示例15: FromStreamShouldWorkTest

        public void FromStreamShouldWorkTest(string filename)
        {
            using (System.IO.StreamReader reader = new System.IO.StreamReader(filename))
            {
                Assert.DoesNotThrow(() => _texture = Texture2D.FromStream(_game.GraphicsDevice, reader.BaseStream));
            }
            Assert.NotNull(_texture);
            try
            {

                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(filename);
                System.Drawing.GraphicsUnit gu = System.Drawing.GraphicsUnit.Pixel;
                System.Drawing.RectangleF rf = bitmap.GetBounds(ref gu);
                Rectangle rt = _texture.Bounds;
                Assert.AreEqual((int) rf.Bottom, rt.Bottom);
                Assert.AreEqual((int) rf.Left, rt.Left);
                Assert.AreEqual((int) rf.Right, rt.Right);
                Assert.AreEqual((int) rf.Top, rt.Top);
                bitmap.Dispose();
            }//The dds file test case can't be checked with System.Drawing because it does not understand this format
            catch { }
            _texture.Dispose();
            _texture = null;
        }
开发者ID:Zodge,项目名称:MonoGame,代码行数:24,代码来源:Texture2DNonVisualTest.cs


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