C#中橡皮条

nvshenxp 2012-01-06 03:12:58
有没有好的方法能够实现在一张图片上画橡皮条(注意,是在图片上,并非空窗体上面)。涉及到背景颜色之类的问题,请高手指点一下!!
...全文
254 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
dylike 2012-01-11
  • 打赏
  • 举报
回复
不是针对背景图,而是针对一个图,并且可以保存.
nvshenxp 2012-01-11
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 dylike 的回复:]
C# code

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing.Imaging;
publ……
[/Quote]

额,大虾,这个可以直接运行?我是用在图像处理里面的,这样能作为对背景图的修改保存么?
林g 2012-01-11
  • 打赏
  • 举报
回复
楼上厉害!
dylike 2012-01-11
  • 打赏
  • 举报
回复


using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing.Imaging;
public class Form1
{

/// <summary>
/// 获取遮罩层的相对反相
/// </summary>
/// <param name="MaskImage">遮罩层</param>
/// <param name="BackGroundImage">背景层</param>
/// <remarks></remarks>
private void GetInvtImg(ref Bitmap MaskImage, Bitmap BackGroundImage)
{
try {
BitmapData bmpDATA1 = new BitmapData();
BitmapData bmpDATA2 = new BitmapData();
bmpDATA1 = BackGroundImage.LockBits(new Rectangle(0, 0, BackGroundImage.Width, BackGroundImage.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
bmpDATA2 = MaskImage.LockBits(new Rectangle(0, 0, MaskImage.Width, MaskImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
byte[] BTS1 = new byte[bmpDATA1.Stride * bmpDATA1.Height + 1];
byte[] BTS2 = new byte[bmpDATA2.Stride * bmpDATA2.Height + 1];
System.Runtime.InteropServices.Marshal.Copy(bmpDATA1.Scan0, BTS1, 0, BTS1.Length - 1);
System.Runtime.InteropServices.Marshal.Copy(bmpDATA2.Scan0, BTS2, 0, BTS2.Length - 1);
if (BTS1.Length != BTS2.Length) {
throw new Exception("请确保遮罩层与背景层大小一致");
return;
}
for (int I = 0; I <= BTS2.Length - 4; I += 4) {
if (BTS2[I + 3] != 0) {
BTS2[I] = 255 - BTS1[I];
BTS2[I + 1] = 255 - BTS1[I + 1];
BTS2[I + 2] = 255 - BTS1[I + 2];
}
}
System.Runtime.InteropServices.Marshal.Copy(BTS2, 0, bmpDATA2.Scan0, BTS2.Length - 1);
BackGroundImage.UnlockBits(bmpDATA1);
MaskImage.UnlockBits(bmpDATA2);
} catch (Exception ex) {
throw new Exception(ex.Message);
}
}

private void Button1_Click(System.Object sender, System.EventArgs e)
{
//定义一个空图层,大小为背景大小
using (Bitmap B = new Bitmap(this.BackgroundImage.Width, this.BackgroundImage.Height)) {
using (Graphics G = Graphics.FromImage(B)) {
//在该图层上绘制需要的形状,颜色不限
G.DrawEllipse(new Pen(Brushes.Red, 30), new Rectangle(40, 40, 200, 180));
}
//将该图层处理为背景反相
GetInvtImg(ref B, this.BackgroundImage);

using (Graphics G = Graphics.FromImage(this.BackgroundImage)) {
G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias;
//将处理后的反相图绘制到背景
G.DrawImage(B, new Rectangle(0, 0, B.Width, B.Height), new Rectangle(0, 0, B.Width, B.Height), GraphicsUnit.Pixel);
}
}
this.Refresh();
}
}


nvshenxp 2012-01-11
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 dylike 的回复:]
不是针对背景图,而是针对一个图,并且可以保存.
[/Quote]
我再研究研究,谢谢你了哈!
nvshenxp 2012-01-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 happy09li 的回复:]
C#中用“橡皮条”法绘图和重绘

新建一个Graphics对象,使用它的DrawCurve方法可以绘制样条曲线。

有很多种。

绘制经过一组指定的 Point 结构的基数样条。
[C#] public void DrawCurve(Pen, Point[]);

绘制经过一组指定的 PointF 结构的基数样条。
[C#] public void DrawCurve(Pen,……
[/Quote]
帮忙解答一下呗,谢谢了。
nvshenxp 2012-01-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 happy09li 的回复:]
C#中用“橡皮条”法绘图和重绘

新建一个Graphics对象,使用它的DrawCurve方法可以绘制样条曲线。

有很多种。

绘制经过一组指定的 Point 结构的基数样条。
[C#] public void DrawCurve(Pen, Point[]);

绘制经过一组指定的 PointF 结构的基数样条。
[C#] public void DrawCurve(Pen,……
[/Quote]

你给的这个我看过了已经,但是跟我想要的还有很大差别。里面是用白色线来画鼠标移动过程中的椭圆的,我想达到的效果是可以在一张图片上面实现橡皮筋效果,用白色不合适,直接取反我也试过了,没有成功。
nvshenxp 2012-01-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sugarbelle 的回复:]
橡皮条 是椭圆形线条吗?

只要用反相..即线条色就是背景色相反的色..这线条就很明显了
[/Quote]

画直线或者虚线矩形选中框,关键是想要在图像上操作,这样一来就不好取反了。。。
熙风 2012-01-06
  • 打赏
  • 举报
回复
C#中用“橡皮条”法绘图和重绘

新建一个Graphics对象,使用它的DrawCurve方法可以绘制样条曲线。

有很多种。

绘制经过一组指定的 Point 结构的基数样条。
[C#] public void DrawCurve(Pen, Point[]);

绘制经过一组指定的 PointF 结构的基数样条。
[C#] public void DrawCurve(Pen, PointF[]);

使用指定的张力绘制经过一组指定的 Point 结构的基数样条。
[C#] public void DrawCurve(Pen, Point[], float);

使用指定的张力绘制经过一组指定的 PointF 结构的基数样条。
[C#] public void DrawCurve(Pen, PointF[], float);

绘制经过一组指定的 PointF 结构的基数样条。从相对于数组开始位置的偏移量开始绘制。
[C#] public void DrawCurve(Pen, PointF[], int, int);

使用指定的张力绘制经过一组指定的 Point 结构的基数样条。
[C#] public void DrawCurve(Pen, Point[], int, int, float);

使用指定的张力绘制经过一组指定的 PointF 结构的基数样条。从相对于数组开始位置的偏移量开始绘制。
[C#] public void DrawCurve(Pen, PointF[], int, int, float);


sugarbelle 2012-01-06
  • 打赏
  • 举报
回复
橡皮条 是椭圆形线条吗?

只要用反相..即线条色就是背景色相反的色..这线条就很明显了

110,539

社区成员

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

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

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