Draw border around bitmap

后端 未结 3 1467
天涯浪人
天涯浪人 2021-01-12 21:10

I have got a System.Drawing.Bitmap in my code.

The width is fix, the height varies.

What I want to do, is to add a white border around the bitma

3条回答
  •  Happy的楠姐
    2021-01-12 21:38

    You can use 'SetPixel' method of a Bitmap class, to set nesessary pixels with the color. But more convenient is to use 'Graphics' class, as shown below:

    bmp = new Bitmap(FileName);
    //bmp = new Bitmap(bmp, new System.Drawing.Size(40, 40));
    
    System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp);
    
    gr.DrawLine(new Pen(Brushes.White, 20), new Point(0, 0), new Point(0, 40));
    gr.DrawLine(new Pen(Brushes.White, 20), new Point(0, 0), new Point(40, 0));
    gr.DrawLine(new Pen(Brushes.White, 20), new Point(0, 40), new Point(40, 40));
    gr.DrawLine(new Pen(Brushes.White, 20), new Point(40, 0), new Point(40, 40));
    

提交回复
热议问题