【发布时间】:2014-12-17 16:37:16
【问题描述】:
问题: 我有白色背景上的物体图片。 我需要确实具有这些对象的确切形状的 PictureBox,但我不知道这些对象的先验外观。
【问题讨论】:
标签: c# winforms picturebox shape
问题: 我有白色背景上的物体图片。 我需要确实具有这些对象的确切形状的 PictureBox,但我不知道这些对象的先验外观。
【问题讨论】:
标签: c# winforms picturebox shape
我对此的解决方案是一个新课程:
class ShapedPictureBox : PictureBox
{
public ShapedPictureBox()
{
}
public Color transparentColor = Color.White;
public void updateShape()
{
if(this.Image = null) return;
Bitmap bitmap = new Bitmap(this.Image);
System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
for(int x = 0; x < this.Image.Width; x++)
for(int y = 0; y < this.Image.Height; y++)
if(transparentColor != bitmap.GetPixel(x, y))
graphicsPath.AddRectangle(new Rectangle(new Point(x, y), new Size(1, 1)));
this.Region = new Region(graphicsPath);
}
}
每当您使对象无效时,都会重新创建形状。我知道这个解决方案根本无效,但这是我发现的唯一一个..我希望它可以帮助某人..
如果您有更好/更有效的想法,请告诉我。
【讨论】:
GetPixel(),每次您将其无效作为解决方案都是荒谬的! 1x1 矩形使情况变得更糟。