C#中橡皮条 有没有好的方法能够实现在一张图片上画橡皮条(注意,是在图片上,并非空窗体上面)。涉及到背景颜色之类的问题,请高手指点一下!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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); 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> /// <res></res> 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(); }} 简单数据类型转换问题 关于button总是刷新的问题,求助! 注册 COM Interop 失败 如何在类里调用类外部的方法 windown程序中 中如何 选中多个控件 学习数据结构和离散数学 .Net 窗体设计问题很急!!!!!!!!!! 怎么把一个控件插入RichTextBox中??? C#中Textbox如何实现自动滚屏? 大家讨论一下,,c#生成的程序的效率问题,,我感觉很慢。。。。。。。 c#只能读取到结构成员的一部分字符串?? C# 防止SQLServer并发
[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);
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>
/// <res></res>
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();
}
}