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


C# Bitmap类代码示例

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


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

示例1: Terrain

 public Terrain(Device device, String texture, int pitch, Renderer renderer)
 {
     HeightMap = new System.Drawing.Bitmap(@"Data/Textures/"+texture);
     WaterShader = new WaterShader(device);
     TerrainShader = new TerrainShader(device);
     _width = HeightMap.Width-1;
     _height = HeightMap.Height-1;
     _pitch = pitch;
     _terrainTextures = new ShaderResourceView[4];
     _terrainTextures[0] = new Texture(device, "Sand.png").TextureResource;
     _terrainTextures[1] = new Texture(device, "Grass.png").TextureResource;
     _terrainTextures[2] = new Texture(device, "Ground.png").TextureResource;
     _terrainTextures[3] = new Texture(device, "Rock.png").TextureResource;
     _reflectionClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 0.0f);
     _refractionClippingPlane = new Vector4(0.0f, -1.0f, 0.0f, 0.0f);
     _noClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 10000);
     _reflectionTexture = new RenderTexture(device, renderer.ScreenSize);
     _refractionTexture = new RenderTexture(device, renderer.ScreenSize);
     _renderer = renderer;
     _bitmap = new Bitmap(device,_refractionTexture.ShaderResourceView,renderer.ScreenSize, new Vector2I(100, 100), 0);
     _bitmap.Position = new Vector2I(renderer.ScreenSize.X - 100, 0);
     _bitmap2 = new Bitmap(device, _reflectionTexture.ShaderResourceView, renderer.ScreenSize, new Vector2I(100, 100), 0);
     _bitmap2.Position = new Vector2I(renderer.ScreenSize.X - 100, 120);
     _bumpMap = _renderer.TextureManager.Create("OceanWater.png");
     _skydome = new ObjModel(device, "skydome.obj", renderer.TextureManager.Create("Sky.png"));
     BuildBuffers(device);
     WaveTranslation = new Vector2(0,0);
 }
开发者ID:ndech,项目名称:PlaneSimulator,代码行数:28,代码来源:Terrain.cs

示例2: resizeImage

    private static System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, Size size)
    {
        //int sourceWidth = imgToResize.Width;
        //int sourceHeight = imgToResize.Height;

        //float nPercent = 0;
        //float nPercentW = 0;
        //float nPercentH = 0;

        //nPercentW = ((float)size.Width / (float)sourceWidth);
        //nPercentH = ((float)size.Height / (float)sourceHeight);

        //if (nPercentH < nPercentW)
        //    nPercent = nPercentH;
        //else
        //    nPercent = nPercentW;

        //int destWidth = (int)(sourceWidth * nPercent);
        //int destHeight = (int)(sourceHeight * nPercent);
        int destWidth = size.Width;
        int destHeight = size.Height;

        Bitmap b = new Bitmap(destWidth, destHeight);
        Graphics g = Graphics.FromImage((System.Drawing.Image)b);
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;

        g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
        g.Dispose();

        return (System.Drawing.Image)b;
    }
开发者ID:zachi,项目名称:artyshot,代码行数:31,代码来源:Utils.aspx.cs

示例3: Main

	public static void Main(string[] args)
	{	
		Graphics.DrawImageAbort imageCallback;
		Bitmap outbmp = new Bitmap (300, 300);				
		Bitmap bmp = new Bitmap("../../Test/System.Drawing/bitmaps/almogaver24bits.bmp");
		Graphics dc = Graphics.FromImage (outbmp);        
		
		ImageAttributes imageAttr = new ImageAttributes();
		
		/* Simple image drawing */		
		dc.DrawImage(bmp, 0,0);				
				
		/* Drawing using points */
		PointF ulCorner = new PointF(150.0F, 0.0F);
		PointF urCorner = new PointF(350.0F, 0.0F);
		PointF llCorner = new PointF(200.0F, 150.0F);
		RectangleF srcRect = new Rectangle (0,0,100,100);		
		PointF[] destPara = {ulCorner, urCorner, llCorner};	
		imageCallback =  new Graphics.DrawImageAbort(DrawImageCallback);		
		dc.DrawImage (bmp, destPara, srcRect, GraphicsUnit.Pixel, imageAttr, imageCallback);
	
		/* Using rectangles */	
		RectangleF destRect = new Rectangle (10,200,100,100);
		RectangleF srcRect2 = new Rectangle (50,50,100,100);		
		dc.DrawImage (bmp, destRect, srcRect2, GraphicsUnit.Pixel);		
		
		/* Simple image drawing with with scaling*/		
		dc.DrawImage(bmp, 200,200, 75, 75);				
		
		outbmp.Save("drawimage.bmp", ImageFormat.Bmp);				
		
	}
开发者ID:nlhepler,项目名称:mono,代码行数:32,代码来源:drawimage.cs

示例4: CreateDirectBrush

        private BitmapBrush CreateDirectBrush(
            ImageBrush brush,
            SharpDX.Direct2D1.RenderTarget target,
            Bitmap image, 
            Rect sourceRect, 
            Rect destinationRect)
        {
            var tileMode = brush.TileMode;
            var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size);
            var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale);
            var transform = Matrix.CreateTranslation(-sourceRect.Position) *
                Matrix.CreateScale(scale) *
                Matrix.CreateTranslation(translate);

            var opts = new BrushProperties
            {
                Transform = transform.ToDirect2D(),
                Opacity = (float)brush.Opacity,
            };

            var bitmapOpts = new BitmapBrushProperties
            {
                ExtendModeX = GetExtendModeX(tileMode),
                ExtendModeY = GetExtendModeY(tileMode),                
            };

            return new BitmapBrush(target, image, bitmapOpts, opts);
        }
开发者ID:rdterner,项目名称:Perspex,代码行数:28,代码来源:ImageBrushImpl.cs

示例5: ImageMenu

    public ImageMenu()
    {
        this.Text = "메뉴 선택 표시와 이미지 넣기";

        // 이미지 개체 준비
        Bitmap bmp1 = new Bitmap(GetType(), "ImageMenu.image_1.bmp");
        Bitmap bmp2 = new Bitmap(GetType(), "ImageMenu.image_2.bmp");

        MenuStrip menu = new MenuStrip();
        menu.Parent = this;

        // File 항목
        ToolStripMenuItem file_item = new ToolStripMenuItem();
        file_item.Text = "&File";
        file_item.Image = bmp1;         // 메뉴에 출력할 이미지 지정
        menu.Items.Add(file_item);

        select_item = new ToolStripMenuItem();
        select_item.Text = "&Select";
        select_item.Click += EventProc;
        file_item.DropDownItems.Add(select_item);

        // 메뉴 구분선 넣기
        ToolStripSeparator file_item_sep = new ToolStripSeparator();
        file_item.DropDownItems.Add(file_item_sep);

        ToolStripMenuItem close_item = new ToolStripMenuItem();
        close_item.Text = "&Close";
        close_item.Image = bmp2;
        close_item.ShortcutKeys = Keys.Alt | Keys.F4;
        close_item.Click += EventProc;
        file_item.DropDownItems.Add(close_item);
    }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:33,代码来源:Program.cs

示例6: 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

示例7: ReSizeImage

    public string ReSizeImage(string imagePath, string outputPath, int newWidth)
    {
        System.Drawing.Image bm = System.Drawing.Image.FromFile(imagePath);
            string ext = Path.GetExtension(imagePath);
            string fileN = Path.GetFileName(imagePath);
            var imgFor = GetFormat(ext);
            int NewHeight = (bm.Height*newWidth)/bm.Width;

            Bitmap resized = new Bitmap(newWidth, NewHeight);

            Graphics g = Graphics.FromImage(resized);

            g.DrawImage(bm, new Rectangle(0, 0, resized.Width, resized.Height), 0, 0, bm.Width, bm.Height,
                GraphicsUnit.Pixel);

            g.Dispose();
            bm.Dispose();

            if (imgFor != null)
            {
                resized.Save(outputPath + fileN, imgFor);
                return outputPath + fileN;
            }
            else
            {
                return null;
            }
    }
开发者ID:HenrikObsen,项目名称:MVC_Blog,代码行数:28,代码来源:Uploader.cs

示例8: convertirGris

    //Función que convierte una imagen a escala de grises
    public void convertirGris(string imagefrom, string imageto)
    {
        //create a blank bitmap the same size as original
        Bitmap original = new Bitmap(imagefrom);
        Bitmap newBitmap = new Bitmap(original.Width, original.Height);

        //get a graphics object from the new image
        Graphics g = Graphics.FromImage(newBitmap);

        //create the grayscale ColorMatrix
        ColorMatrix colorMatrix = new ColorMatrix(new float[][]
         {
             new float[] {.30f, .30f, .30f, 0, 0},
             new float[] {.59f, .59f, .59f, 0, 0},
             new float[] {.11f, .11f, .11f, 0, 0},
             new float[] {0, 0, 0, 1, 0},
             new float[] {0, 0, 0, 0, 1}
         });

        //create some image attributes
        ImageAttributes attributes = new ImageAttributes();

        //set the color matrix attribute
        attributes.SetColorMatrix(colorMatrix);

        //draw the original image on the new image
        //using the grayscale color matrix
        g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
           0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);

        //dispose the Graphics object
        g.Dispose();
        newBitmap.Save(imageto);
    }
开发者ID:ClickApp,项目名称:crackcompany,代码行数:35,代码来源:ProcesarImagenes.cs

示例9: Filter

        public static UIImage Filter(UIImage img, int puzzleSize)
        {
            int tileSize = 2;
            int paletteColorsNumber = BasePaletteColorsNumber + (8 * puzzleSize / 64);

            // 1/ Get the main colors
            // So we have a color palette
            Logger.I ("Filter: getting palette...");
            var colorPalette = getColorPalette (img, paletteColorsNumber);

            // 1/ Resize & Load image as readable
            UIImage resizedImg = UIImageEx.ResizeRatio (img, puzzleSize);
            Bitmap bitmap = new Bitmap (resizedImg);

            // 2/ Apply mosaic
            Logger.I ("Filter: applying mosaic...");
            var flippedImage = applyMosaic (tileSize, colorPalette, resizedImg, bitmap);

            // -- Flip because bitmap has inverted coordinates
            Logger.I ("Filter: resizing...");
            UIImage finalImg = new UIImage (flippedImage, 0f, UIImageOrientation.DownMirrored);
            //			UIImage finalImg = new UIImage (flippedImage);

            // -- Resize the final
            //			return ResizeRatio (finalImg, FinalSize);

            Logger.I ("Filter: image ready!");
            return finalImg;
        }
开发者ID:valryon,项目名称:pixpuzzle,代码行数:29,代码来源:ImageFilters.cs

示例10: SetFontBitmap

 /// <summary> Sets the bitmap that contains the bitmapped font characters as an atlas. </summary>
 public void SetFontBitmap( Bitmap bmp )
 {
     FontBitmap = bmp;
     boxSize = FontBitmap.Width / 16;
     fontPixels = new FastBitmap( FontBitmap, true, true );
     CalculateTextWidths();
 }
开发者ID:Chameleonherman,项目名称:ClassicalSharp,代码行数:8,代码来源:IDrawer2D.TextMC.cs

示例11: OnPaint

 protected override void OnPaint(PaintEventArgs e)
 {
     Graphics g = e.Graphics;
     Bitmap bmp = new Bitmap("back.jpg");
     Rectangle r = new Rectangle(0, 0, bmp.Width, bmp.Height);
     g.DrawImage(bmp, r, r, GraphicsUnit.Pixel);
 }
开发者ID:dbremner,项目名称:hycs,代码行数:7,代码来源:helloImage.cs

示例12: generateTicket

    public  Bitmap generateTicket(string ticketType, string start, string destination, string price)
    {
        
       //Orte der verschiedenen Textboxen auf dem Ticket:
        Point StartLine1 = new Point(0,100);
        Point EndLine1 = new Point(960, 100);
        Point StartLine2 = new Point(0, 700);
        Point EndLine2 = new Point(960, 700);
        PointF logoLocation = new PointF(150,20);
        PointF fromLocation = new PointF(40,300);
        PointF toLocation = new PointF(40,500);
        PointF totalLocation = new PointF(40,750);
        PointF ticketTypeLocation = new PointF(40, 150);
        PointF startLocation = new PointF(40, 400);
        PointF destinationLocation = new PointF(40, 600);
        PointF priceLocation = new PointF(500, 750);

        //string imageFilePath = "C:\\Users\\kuehnle\\Documents\\TestWebsite\\NewTestTicket.bmp";

        
        Bitmap tempBmp = new Bitmap(960,900);

        //auf das neu erstellte Bitmap draufzeichnen:
        using (Graphics g = Graphics.FromImage(tempBmp))
        {

            g.Clear(Color.White);
            g.DrawLine(new Pen(Brushes.Black,10), StartLine1, EndLine1);
            g.DrawLine(new Pen(Brushes.Black,10), StartLine2, EndLine2);
            
            using (Font arialFont = new Font("Arial", 40,FontStyle.Bold))
            {

                g.DrawString("Jakarta Commuter Train", arialFont, Brushes.Black, logoLocation);
               
                g.DrawString(ticketType, arialFont, Brushes.Black, ticketTypeLocation);
                

            }
            using (Font arialFont = new Font("Arial", 40, FontStyle.Underline))
            {
                g.DrawString("From:", arialFont, Brushes.Black, fromLocation);
                g.DrawString("To:", arialFont, Brushes.Black, toLocation);
            }
            using (Font arialFont = new Font("Arial", 40, FontStyle.Regular))
            {
                g.DrawString("Total:", arialFont, Brushes.Black, totalLocation);
                g.DrawString(start, arialFont, Brushes.Black, startLocation);
                g.DrawString(destination, arialFont, Brushes.Black, destinationLocation);
                g.DrawString(price, arialFont, Brushes.Black, priceLocation);
            }
        }
        //Farbtiefe auf 1 reduzieren:
        Bitmap ticket = tempBmp.Clone(new Rectangle(0, 0, tempBmp.Width, tempBmp.Height),PixelFormat.Format1bppIndexed);
        
        //ticket.Save(imageFilePath,System.Drawing.Imaging.ImageFormat.Bmp);
        //ticket.Dispose();
        return ticket;

    }
开发者ID:cstrobbe,项目名称:C4A-TVM,代码行数:60,代码来源:Printer.cs

示例13: ProcessRequest

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "image/jpeg";
        string url = context.Request.RawUrl;
        string path = context.Request.MapPath(url);

        using (Image priImg = Image.FromFile(path))
        {
            int width = 660;
            int height = 350;
            if (priImg.Width > priImg.Height)
            {
                height = width * priImg.Height / priImg.Width;
            }
            else
            {
                width = height * priImg.Width / priImg.Height;
            }
            path = context.Request.MapPath("logo.png");
            using (Image logo = Image.FromFile(path))
            {
                using (Bitmap bm = new Bitmap(width, height))
                {
                    using (Graphics g = Graphics.FromImage(bm))
                    {
                        g.DrawImage(priImg, 0, 0, bm.Width, bm.Height);
                        g.DrawImage(logo, bm.Width - logo.Width, bm.Height - logo.Height, logo.Width, logo.Height);
                        bm.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                }
            }
        }
    }
开发者ID:hdkn235,项目名称:MyPhotosNew,代码行数:33,代码来源:WaterMaker.cs

示例14: eval_a

 public decimal eval_a(Bitmap A_0, decimal A_1)
 {
     while (true)
     {
         decimal num = eval_be.eval_a(A_0, eval_i.eval_a);
         int num2 = 4;
         while (true)
         {
             switch (num2)
             {
             case 0:
                 if (true)
                 {
                 }
                 num2 = 7;
                 continue;
             case 1:
                 return A_1;
             case 2:
                 if (num < 0m)
                 {
                     num2 = 1;
                     continue;
                 }
                 return num;
             case 3:
                 num = eval_be.eval_a(A_0, eval_i.eval_b);
                 num2 = 5;
                 continue;
             case 4:
                 if (num < 0m)
                 {
                     num2 = 0;
                     continue;
                 }
                 return num;
             case 5:
                 if (num < A_1)
                 {
                     num2 = 6;
                     continue;
                 }
                 goto IL_5F;
             case 6:
                 return A_1;
             case 7:
                 if (eval_i.eval_b != null)
                 {
                     num2 = 3;
                     continue;
                 }
                 goto IL_5F;
             }
             break;
             IL_5F:
             num2 = 2;
         }
     }
     return A_1;
 }
开发者ID:JABirchall,项目名称:FullAutoHoldem,代码行数:60,代码来源:eval_i.cs

示例15: 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


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