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


C# Bitmap.Dispose方法代码示例

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


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

示例1: createImage

 private void createImage(string checkcode)
 {
     if(checkcode ==null||checkcode.Trim() ==string .Empty)
        return;
        Bitmap image = new Bitmap((int)Math.Ceiling(checkcode.Length * 13.1), 22);
        Graphics grahics = Graphics.FromImage(image);
        grahics.Clear(Color.White);
        Random random=new Random() ;
       for (int i = 0; i < 18; i++)
        {
        int x1 = random.Next(image.Width);
        int x2 = random.Next(image.Width);
        int y1 = random.Next(image.Height);
        int y2 = random.Next(image .Height );
        grahics.DrawLine(new Pen(Color.Silver),x1,y1,x2,y2);
        }
     Font font = new Font("Arial", 11, FontStyle.Bold);
        Brush brush = new SolidBrush(Color.Black);
        grahics.DrawString(checkcode ,font,brush ,3,3);
        for (int i = 0; i < 80; i++)
        {
        int width = random.Next(image.Width );
        int heigth = random.Next(image.Height );
        image.SetPixel(width ,heigth ,Color.Silver );
        }
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
        Response.ClearContent();
        Response.ContentType="image/Jpeg";
        Response.BinaryWrite(ms.ToArray());
        grahics.Dispose();
        image.Dispose();
 }
开发者ID:silverDrops,项目名称:OA,代码行数:33,代码来源:CheckImage.aspx.cs

示例2: CreateCheckCodeImage

 private void CreateCheckCodeImage(string checkCode)
 {
     if ((checkCode != null) && (checkCode.Trim() != string.Empty))
     {
         Bitmap image = new Bitmap((int)Math.Ceiling((double)(checkCode.Length * 11.5)), 20);
         Graphics graphics = Graphics.FromImage(image);
         try
         {
             new Random();
             graphics.Clear(Color.White);
             Font font = new Font("Arial", 13f, FontStyle.Bold);
             LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Black, Color.DarkRed, 1.2f, true);
             graphics.DrawString(checkCode, font, brush, (float)2f, (float)2f);
             graphics.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
             MemoryStream stream = new MemoryStream();
             image.Save(stream, ImageFormat.Gif);
             base.Response.ClearContent();
             base.Response.ContentType = "image/Gif";
             base.Response.BinaryWrite(stream.ToArray());
         }
         finally
         {
             graphics.Dispose();
             image.Dispose();
         }
     }
 }
开发者ID:wangxu627,项目名称:WebBuss,代码行数:27,代码来源:yanzhengma.aspx.cs

示例3: CreateImage

    /// <summary>
    /// ����ͼƬ
    /// </summary>
    /// <param name="checkCode">�����</param>
    private void CreateImage(string checkCode)
    {
        int iwidth = (int)(checkCode.Length * 11.5);//����������趨ͼƬ���
        Bitmap image = new Bitmap(iwidth, 20);//����һ������
        Graphics g = Graphics.FromImage(image);//�ڻ����϶����ͼ��ʵ��
        Font f = new Font("Arial",10,FontStyle.Bold);//���壬��С����ʽ
        Brush b = new SolidBrush(Color.Black);//������ɫ
        //g.FillRectangle(new System.Drawing.SolidBrush(Color.Blue),0,0,image.Width, image.Height);
        g.Clear(Color.White);//������ɫ
        g.DrawString(checkCode, f, b, 3, 3);

        Pen blackPen = new Pen(Color.Black, 0);
        Random rand = new Random();
        /*�����
        for (int i = 0; i < 5; i++)
        {
            int y = rand.Next(image.Height);
            g.DrawLine(blackPen, 0, y, image.Width, y);
        }
        */
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
        Response.ClearContent();
        Response.ContentType = "image/Jpeg";
        Response.BinaryWrite(ms.ToArray());
        g.Dispose();
        image.Dispose();
    }
开发者ID:vtmer,项目名称:NewStudent,代码行数:32,代码来源:checkCode.aspx.cs

示例4: Page_Load

	protected void Page_Load(object sender, System.EventArgs e)
	{
		if ((Request.QueryString["X"] == null) ||
			(Request.QueryString["Y"] == null) ||
			(Request.QueryString["FilePath"] == null))
		{
			// There is missing data, so don't display anything.
			// Other options including choosing reasonable defaults,
			// or returning an image with some static error text.
		}
		else
		{
			int x = Int32.Parse(Request.QueryString["X"]);
			int y = Int32.Parse(Request.QueryString["Y"]);
			string file = Server.UrlDecode(Request.QueryString["FilePath"]);

			// Create the in-memory bitmap where you will draw the image. 
			Bitmap image = new Bitmap(x, y);
			Graphics g = Graphics.FromImage(image);

			// Load the file data.
			System.Drawing.Image thumbnail = System.Drawing.Image.FromFile(file);

			// Draw the thumbnail.
			g.DrawImage(thumbnail, 0, 0, x, y);

			// Render the image.
			image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
			g.Dispose();
			image.Dispose();
		}
	}
开发者ID:Helen1987,项目名称:edu,代码行数:32,代码来源:ThumbnailViewer.aspx.cs

示例5: CreateThumbnail

      public static Bitmap CreateThumbnail(string lcFilename, int width, int height)
      {
          Bitmap loBMP = null;
          Bitmap bmpOut = null;
          try
          {
              loBMP = new Bitmap(lcFilename);
              ImageFormat loFormat = loBMP.RawFormat;
              Size newSize = new Size();
              newSize.Height = height;
              newSize.Width = width;
              bmpOut = new Bitmap(newSize.Width, newSize.Height);
              Graphics canvas = Graphics.FromImage(bmpOut);
              canvas.SmoothingMode = SmoothingMode.AntiAlias;
              canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
              canvas.PixelOffsetMode = PixelOffsetMode.HighQuality;
              canvas.DrawImage(loBMP, new Rectangle(new Point(0, 0), newSize));
          }
          catch (Exception ex)
          {

          }
          finally
          {
              loBMP.Dispose();
          }

          return bmpOut;
      }
开发者ID:mediasoftpro,项目名称:.NET-vFaceWall,代码行数:29,代码来源:Image_Process.cs

示例6: createimage

    public void createimage(string randnum)
    {
        int iwidth = randnum.Length * 13;
        Bitmap image = new Bitmap(iwidth, 23);
        Graphics g = Graphics.FromImage(image);
        g.Clear(Color.White);
        Color[] color = { Color.Green, Color.Red, Color.Black, Color.Blue, Color.Orange };
        string[] font = { "宋体", "黑体", "Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial" };
        Random rand = new Random();
        for (int i = 0; i < 50; i++)
        {
            int x = rand.Next(image.Width);
            int y = rand.Next(image.Height);
            g.DrawRectangle(new Pen(Color.LightGray, 0), x, y, 1, 1);
        }
        for (int i = 0; i < randnum.Length; i++)
        {
            int m = rand.Next(5);
            int n = rand.Next(6);
            Color c = color[m];
            Font f = new Font(font[n], 10, System.Drawing.FontStyle.Bold);
            Brush b = new SolidBrush(color[m]);
            g.DrawString(randnum.Substring(i, 1), f, b, 3 + (i * 12), 0);
        }
        g.DrawRectangle(new Pen(Color.DarkGray, 0), 0, 0, image.Width - 1, image.Height - 1);

        image.Save(@"D:\Visual Studio 2013\WebSites\netsec\12.gif", System.Drawing.Imaging.ImageFormat.Gif);

        g.Dispose();
        image.Dispose();
    }
开发者ID:LoginAndRegister,项目名称:Test,代码行数:31,代码来源:Login.aspx.cs

示例7: ResizeImage

    //Resize image - Med bredde og højde
    public static void ResizeImage(int width, Stream fromStream, Stream toStream)
    {
        //Propertionelt AspectRation
        float originalAspectRatio = (float)Image.FromStream(fromStream).Width / (float)Image.FromStream(fromStream).Height;
        float newWidth, newHeight;
        var image = Image.FromStream(fromStream);

        //Hvis det billede der uploades er mindre end "resize" - bliver det ikke scaleret op.
        //Dette er for ikke at "pixelere" billederne
        if (width < (float)Image.FromStream(fromStream).Width)
        {
            newWidth = width;
            newHeight = (float)width / (float)originalAspectRatio;
        }
        else
        {
            newWidth = (float)Image.FromStream(fromStream).Width;
            newHeight = (float)Image.FromStream(fromStream).Height;
        }

        Debug.Write("ASPECT: = " + newHeight);
        var thumpnailBitmap = new Bitmap((int)newWidth, (int)newHeight);
        var thumpnailGraph = Graphics.FromImage(thumpnailBitmap);
        thumpnailGraph.CompositingQuality = CompositingQuality.HighQuality;
        thumpnailGraph.SmoothingMode = SmoothingMode.HighQuality;
        thumpnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
        var imageRectangle = new Rectangle(0, 0, (int)newWidth, (int)newHeight);
        thumpnailGraph.DrawImage(image, imageRectangle);
        thumpnailBitmap.Save(toStream, image.RawFormat);
        thumpnailGraph.Dispose();
        thumpnailBitmap.Dispose();
        image.Dispose();
    }
开发者ID:sorensindgart,项目名称:Viking,代码行数:34,代码来源:ImageResize.cs

示例8: Page_Load

	protected void Page_Load(object sender, System.EventArgs e)
	{
		// Create the in-memory bitmap where you will draw the image. 
		Bitmap image = new Bitmap(300, 300);
		Graphics g = Graphics.FromImage(image);

		// Paint the background.
		g.FillRectangle(Brushes.White, 0, 0, 300, 300);

		// Create a brush to use.
		LinearGradientBrush myBrush;

		// Create variable to track the coordinates in the image.
		int y = 20;
		int x = 20;

		// Show a rectangle with each type of gradient.
		foreach (LinearGradientMode gradientStyle in System.Enum.GetValues(typeof(LinearGradientMode)))
		{
			myBrush = new LinearGradientBrush(new Rectangle(x, y, 100, 60), Color.Violet, Color.White, gradientStyle);
			g.FillRectangle(myBrush, x, y, 100, 60);
			g.DrawString(gradientStyle.ToString(), new Font("Tahoma", 8), Brushes.Black, 110 + x, y + 20);
			y += 70;
		}

		// Render the image to the HTML output stream.
		image.Save(Response.OutputStream,
			System.Drawing.Imaging.ImageFormat.Jpeg);

		g.Dispose();
		image.Dispose();
	}
开发者ID:Helen1987,项目名称:edu,代码行数:32,代码来源:GradientExamples.aspx.cs

示例9: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        var fcaptcha = MapPath("~/Css/Login-Box/Captcha.bmp");

        var bmpCaptcha = new Bitmap(fcaptcha);
        var g = Graphics.FromImage(bmpCaptcha);
        var code = RandomizeText(5);

        var gray = new SolidBrush(Color.DimGray);
        var rand = new Random();
        var counter = 0;

        for (int i = 0; i < code.Length; i++)
        {
            g.DrawString(code[i].ToString(),
               new Font("Verdena", 10 + rand.Next(20)),
               gray, new PointF(40 + counter, 10));
            counter += 20;
        }

        // Assign Code
        Session["Captcha"] = code;

        // Response
        Response.Clear();
        Response.ContentType = "image/jpeg";

        bmpCaptcha.Save(Response.OutputStream, ImageFormat.Jpeg);
        bmpCaptcha.Dispose();
        g.Dispose();

        Response.End();
    }
开发者ID:anhphamkstn,项目名称:DVMC,代码行数:33,代码来源:ReloadCaptcha.aspx.cs

示例10: getImageValidate

 //生成图像
 private void getImageValidate(string strValue)
 {
     //string str = "OO00"; //前两个为字母O,后两个为数字0
     int width = Convert.ToInt32(strValue.Length * 12);    //计算图像宽度
     Bitmap img = new Bitmap(width, 23);
     Graphics gfc = Graphics.FromImage(img);           //产生Graphics对象,进行画图
     gfc.Clear(Color.White);
     drawLine(gfc, img);
     //写验证码,需要定义Font
     Font font = new Font("arial", 12, FontStyle.Bold);
     System.Drawing.Drawing2D.LinearGradientBrush brush =
         new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.DarkOrchid, Color.Blue, 1.5f, true);
     gfc.DrawString(strValue, font, brush, 3, 2);
     drawPoint(img);
     gfc.DrawRectangle(new Pen(Color.DarkBlue), 0, 0, img.Width - 1, img.Height - 1);
     //将图像添加到页面
     MemoryStream ms = new MemoryStream();
     img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
     //更改Http头
     Response.ClearContent();
     Response.ContentType = "image/gif";
     Response.BinaryWrite(ms.ToArray());
     //Dispose
     gfc.Dispose();
     img.Dispose();
     Response.End();
 }
开发者ID:kooyou,项目名称:TrafficFinesSystem,代码行数:28,代码来源:CreateImg.aspx.cs

示例11: CreateCircleImageStream

    public static Stream CreateCircleImageStream(Stream imgStream, int circleDiameter)
    {
        //convert stream to bitmap
        Bitmap imgBitmap = new Bitmap(imgStream);

        //for debug
        //saveImage(imgBitmap, "3 inputsteam to bitmap.jpg");

        //create squre image with circle drawn
        imgBitmap = CreateSqureImageAndDrawCicle(imgBitmap, circleDiameter * resizeScale);

        //create circle image
        imgBitmap = CropImageToCircle(imgBitmap);

        //for debug
        //saveImage(imgBitmap, "6 circle croped.jpg");

        //reduce size
        System.Drawing.Image resizedImage = imgBitmap.GetThumbnailImage(circleDiameter, circleDiameter, null, System.IntPtr.Zero);

        //debug
        //saveImage(resizedImage, "7 resized.jpg");

        //convert bitmap to stream
        Stream outputStream = new MemoryStream();
        resizedImage.Save(outputStream, System.Drawing.Imaging.ImageFormat.Png);//jpg does not support transparency

        resizedImage.Dispose();
        imgBitmap.Dispose();

        return outputStream;
    }
开发者ID:hkdilan,项目名称:CreateCircleImage,代码行数:32,代码来源:CircleImageCreater.cs

示例12: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        string fName = ConfigurationManager.AppSettings["Code39Barcode.FontFamily"];

        PrivateFontCollection fCollection = new PrivateFontCollection();
        fCollection.AddFontFile(ConfigurationManager.AppSettings["Code39Barcode.FontFile"]);
        FontFamily fFamily = new FontFamily(fName, fCollection);
        Font f = new Font(fFamily, FontSize);

        Bitmap bmp = new Bitmap(Width, Height);
        Graphics g = Graphics.FromImage(bmp);
        g.Clear(Color.White);
        Brush b = new SolidBrush(Color.Black);
        g.DrawString("*" + strPortfolioID + "*", f, b, 0, 0);

        //PNG format has no visible compression artifacts like JPEG or GIF, so use this format, but it needs you to copy the bitmap into a new bitmap inorder to display the image properly.  Weird MS bug.
        Bitmap bm = new Bitmap(bmp);
        System.IO.MemoryStream ms = new System.IO.MemoryStream();

        Response.ContentType = "image/png";
        bm.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        ms.WriteTo(Response.OutputStream);

        b.Dispose();
        bm.Dispose();
        Response.End();
    }
开发者ID:nehawadhwa,项目名称:ccweb,代码行数:27,代码来源:CP_Barcode.ascx.cs

示例13: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        int x, y;
        string strValidation = null;
        rnd = new Random();
        Response.ContentType = "image/jpeg";
        Response.Clear();
        Response.BufferOutput = true;
        strValidation = GenerateString();
        Session["strValidation"] = strValidation;
        Font font = new Font("Arial", (float)rnd.Next(17, 20));

        Bitmap bitmap = new Bitmap(200, 50);
        Graphics gr = Graphics.FromImage(bitmap);
        gr.FillRectangle(Brushes.LightGreen, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
        gr.DrawString(strValidation, font, Brushes.Black, (float)rnd.Next(70), (float)rnd.Next(20));
           // gr.DrawLine(new Pen(Color.White), new Point(0, rnd.Next(50)), new Point(200, rnd.Next(50)));
           // gr.DrawLine(new Pen(Color.White), new Point(0, rnd.Next(50)), new Point(200, rnd.Next(50)));
           // gr.DrawLine(new Pen(Color.White), new Point(0, rnd.Next(50)), new Point(200, rnd.Next(50)));
        for (x = 0; x < bitmap.Width; x++)
            for (y = 0; y < bitmap.Height; y++)
                if (rnd.Next(4) == 1)
                    bitmap.SetPixel(x, y, Color.LightGreen);
        font.Dispose();
        gr.Dispose();
        bitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
        bitmap.Dispose();
    }
开发者ID:CaesaRBur,项目名称:WebProject,代码行数:28,代码来源:ImageValidation.aspx.cs

示例14: LoadTexture

    public static void LoadTexture()
    {
        Bitmap bitmap=null;
        BitmapData bitmapData=null;

        string[] tx={"relojes.bmp","ford1.bmp","benz1.jpg","motor.bmp","acelera.bmp","papel1.jpg","piso.jpg","madera2.jpg","madera3.jpg","papel1.jpg","Focus.jpg","fordrunner.jpg","mbne.jpg","particle.bmp","benz.jpg"};
        Gl.glEnable(Gl.GL_TEXTURE_2D);
        Gl.glEnable(Gl.GL_DEPTH_TEST);
        //		Gl.gl.Gl.glEnable(Gl.gl.Gl.gl_BLEND);
        //		Gl.gl.Gl.glBlendFunc(Gl.gl.Gl.gl_SRC_ALPHA,Gl.gl.Gl.gl_ONE_MINUS_SRC_ALPHA);
        Rectangle rect;
        texture=new int[tx.Length];
        Gl.glGenTextures(tx.Length, texture);
        for(int i=0; i<tx.Length; i++)
        {
            bitmap = new Bitmap(Application.StartupPath + "\\" + "Textures\\"+tx[i]);
            rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            bitmapData =bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly,
                System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture[i]);
            Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, (int) Gl.GL_RGB8, bitmap.Width, bitmap.Height, Gl.GL_BGR_EXT, Gl.GL_UNSIGNED_BYTE, bitmapData.Scan0);
        }

        Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
        Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
        Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
        Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
        Gl.glTexEnvf(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_DECAL);

        Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);

        bitmap.UnlockBits(bitmapData);
        bitmap.Dispose();
    }
开发者ID:jesantana,项目名称:ConcesionarioVirtual,代码行数:34,代码来源:Otros.cs

示例15: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        // Since we are outputting a Jpeg, set the ContentType appropriately
        Response.ContentType = "image/jpeg";    // Create a Bitmap instance that's 468x60, and a Graphics instance
        const int width = 480, height = 270;
        Bitmap objBitmap = new Bitmap(width, height);
        Graphics objGraphics = Graphics.FromImage(objBitmap);

        // Create a white background
        objGraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height);
        objGraphics.DrawRectangle(new Pen(Color.Black, 1), 0, 0, width - 1, height - 1);

        //// Create a LightBlue background
        //objGraphics.FillRectangle(new SolidBrush(Color.LightBlue), 5, 5,
        //    width - 10, height - 10);

        //// Create the advertising pitch
        Font fontBanner = new Font("Verdana", 10, FontStyle.Regular);
        StringFormat stringFormat = new StringFormat();

        //// center align the advertising pitch
        stringFormat.Alignment = StringAlignment.Center;
        stringFormat.LineAlignment = StringAlignment.Center;

        String label = "Chart for: " + PersonInfo.SelectedRecord.Name.ToString();
        objGraphics.DrawString(label, fontBanner, new SolidBrush(Color.Black), new Rectangle(0, 0, width, height/10), stringFormat);

        // Save the image to the OutputStream
        objBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);

        // clean up...
        objGraphics.Dispose();
        objBitmap.Dispose();
    }
开发者ID:miguel69,项目名称:Health-e,代码行数:34,代码来源:GenerateChart.aspx.cs


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