public Image MaSaiKe(Image m_PreImage, int val)
{
Bitmap MyBitmap = new Bitmap(m_PreImage);
if (MyBitmap.Equals(null))
{
return null;
}
int iWidth = MyBitmap.Width;
int iHeight = MyBitmap.Height;
int stdR, stdG, stdB;
stdR = 0;
stdG = 0;
stdB = 0;
BitmapData srcData = MyBitmap.LockBits(new Rectangle(0, 0, iWidth, iHeight),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
unsafe
{
byte* point = (byte*)srcData.Scan0.ToPointer();
for (int i = 0; i < iHeight; i++)
{
for (int j = 0; j < iWidth; j++)
{
if (i % val == 0)
{
if (j % val == 0)
{
stdR = point[2];
stdG = point[1];
stdB = point[0];
}
else
{
point[0] = (byte)stdB;
point[1] = (byte)stdG;
point[2] = (byte)stdR;
}
}
else
{
//复制上一行
byte* pTemp = point - srcData.Stride;
point[0] = (byte)pTemp[0];
point[1] = (byte)pTemp[1];
point[2] = (byte)pTemp[2];
}
point += 3;
}
point += srcData.Stride - iWidth * 3;
}
MyBitmap.UnlockBits(srcData);
}
return MyBitmap;
}错误提示:
错误 1 不安全代码只会在使用 /unsafe 编译的情况下出现
这是怎么回事,我也想试试马赛克的效果哈~~,求大侠们帮助
{
Bitmap MyBitmap = new Bitmap(m_PreImage);
if (MyBitmap.Equals(null))
{
return null;
}
int iWidth = MyBitmap.Width;
int iHeight = MyBitmap.Height;
int stdR, stdG, stdB;
stdR = 0;
stdG = 0;
stdB = 0;
BitmapData srcData = MyBitmap.LockBits(new Rectangle(0, 0, iWidth, iHeight),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
unsafe
{
byte* point = (byte*)srcData.Scan0.ToPointer();
for (int i = 0; i < iHeight; i++)
{
for (int j = 0; j < iWidth; j++)
{
if (i % val == 0)
{
if (j % val == 0)
{
stdR = point[2];
stdG = point[1];
stdB = point[0];
}
else
{
point[0] = (byte)stdB;
point[1] = (byte)stdG;
point[2] = (byte)stdR;
}
}
else
{
//复制上一行
byte* pTemp = point - srcData.Stride;
point[0] = (byte)pTemp[0];
point[1] = (byte)pTemp[1];
point[2] = (byte)pTemp[2];
}
point += 3;
}
point += srcData.Stride - iWidth * 3;
}
MyBitmap.UnlockBits(srcData);
}
return MyBitmap;
}错误提示:
错误 1 不安全代码只会在使用 /unsafe 编译的情况下出现
这是怎么回事,我也想试试马赛克的效果哈~~,求大侠们帮助
解决方案 »
- 简单C问题,求助
- 什么情况下才需要将类函数设计成静态成员,将更多的类成员设计成静态成员有什么坏处和好处?
- 怎么将form内的控件全部"准备好"再把form显示出来?
- 最近关于手机短信,收到后只能抠电池的这事
- 5年的web开发经验,想学winform编程,不知从何下手,望赐教
- 在主窗口里点击“添加“,然后在弹出的新窗口里添加相应的资料,然后确定,提示成功,自动关闭子窗口后,最后怎么让主窗体里信息也刷新成
- winxp工具图标
- 怎样将自已的程序挂到浏览器上如'上网助手'一样?
- 求表达的值
- 初学者问题,数据库插入问题,谢谢!
- 已运行网站,需要添加一个模块,3层结构开发的,但是DLL,Bll,model,都已经是编译为dll文件了,就一个web文件夹了,可以改吗?
- 关于C#项目的数据库函数修改问题
LZ我的代码上面写了这行 ,没看到么?(把错误放到Google一搜)
这段代码使用了不安全代码,用了指针,要运行需要更改VS配置,Google下。看代码和效果:LZ要细心呀~~