111,098
社区成员




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace WindowsApplication182
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
PictureBox PB = new PictureBox();
PB.Parent = this;
PB.Dock = DockStyle.Fill;
PB.Load(@"c:\pic.png");
Bitmap Bmp = new Bitmap(PB.Image);
GraphicsPath GP = new GraphicsPath();
Color C = Color.FromArgb(0, 0, 0, 0);
for (int i = 0; i < Bmp.Width; i++)
for (int j = 0; j < Bmp.Height; j++)
// 这点不透明而且左右上下四点至少有一点是透明的,那这点就是边缘
if (Bmp.GetPixel(i, j) != C
&& (i > 0 && Bmp.GetPixel(i - 1, j) == C
|| i < Bmp.Width - 1 && Bmp.GetPixel(i + 1, j) == C
|| j > 0 && Bmp.GetPixel(i, j - 1) == C
|| j < Bmp.Height - 1 && Bmp.GetPixel(i, j + 1) == C))
GP.AddRectangle(new Rectangle(new Point(i, j), new Size(1, 1)));
using (Graphics G = Graphics.FromImage(Bmp))
G.DrawPath(Pens.Black, GP);
PB.Image = Bmp;
}
}
}