大神,如图,如何在半透明pictruebox窗口中开个透明小框框,如何套在另一个pictruebox控件上

cyclss 2018-03-15 08:27:06
大神,如图,如何在半透明pictruebox窗口中开个透明小框框,如何套在另一个pictruebox控件上,请教思路与代码实现
...全文
291 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
guijianchouperfect 2019-02-27
  • 打赏
  • 举报
回复
图像处理与识别,Halcon了解下。
desperaso 2018-03-16
  • 打赏
  • 举报
回复
忘了说明,pictureBox1.BackColor = Color.Transparent; pictureBox1背景要透明
desperaso 2018-03-16
  • 打赏
  • 举报
回复
临时写的,有点繁琐,自己修改。原理就是将图像部分设置为透明

/// <summary>
/// 图像挖洞
/// </summary>
/// <param name="_x">透明位置x</param>
/// <param name="_y">透明位置x</param>
/// <param name="_width">透明宽度</param>
/// <param name="_height">透明高度</param>
/// <param name="src">图像</param>
/// <param name="num">图像整体透明度</param>
/// <param name="trans">挖洞部分透明度</param>
/// <returns></returns>
public Bitmap potholing (int _x,int _y,int _width, int _height, Bitmap src, int num, int trans)
{
try
{
int w = src.Width;
int h = src.Height;
Bitmap dstBitmap = new Bitmap(src.Width, src.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.Imaging.BitmapData srcData = src.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.Imaging.BitmapData dstData = dstBitmap.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
unsafe
{
byte* pIn = (byte*)srcData.Scan0.ToPointer();
byte* pOut = (byte*)dstData.Scan0.ToPointer();
byte* p;
int stride = srcData.Stride;
int r, g, b;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
p = pIn;
b = pIn[0];
g = pIn[1];
r = pIn[2];
pOut[1] = (byte)g;
pOut[2] = (byte)r;

if ((y > _y) && (y < _height) && (x > _x) && (x < _height))
{
pOut[3] = (byte)trans;
} else pOut[3] = (byte)num;

pOut[0] = (byte)b;
pIn += 4;
pOut += 4;
}
pIn += srcData.Stride - w * 4;
pOut += srcData.Stride - w * 4;
}
src.UnlockBits(srcData);
dstBitmap.UnlockBits(dstData);
return dstBitmap;
}
}
catch (Exception e)
{
MessageBox.Show(e.Message.ToString());
return null;
}
}

public Form1()
{
InitializeComponent();
pictureBox1.Parent = pictureBox2;
}

private void button1_Click(object sender, EventArgs e)
{
Bitmap _bmp = new Bitmap(@"e.png");
_bmp = potholing(20,20,190,190,_bmp, 255,0);

pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox1.Image = _bmp;

}
}

xuzuning 2018-03-16
  • 打赏
  • 举报
回复
pictruebox 放到 pictruebox 中,指定里面的 Parent 为外层的 pictruebox 则里面的 pictruebox 对于 外面的 pictruebox 就是透明的 C# 的控件只提供到这一步,如有再多的表现,需要自己写代码实现(比如wpf)
assky124 2018-03-16
  • 打赏
  • 举报
回复
直接绘图不行? 换WPF不行么

110,530

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧