如何解决此错误 - “尝试读取或写入受保护的内存”。这通常表明其他内存已损坏。 [英] How to solve this error - "attempted to read or write protected memory. This is often an indication that other memory is corrupt."
本文介绍了如何解决此错误 - “尝试读取或写入受保护的内存”。这通常表明其他内存已损坏。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在图像上应用USM锐化滤镜。我正在使用C#.Net(FrameWork 4.0)和VS 2012.我尝试了这段代码,我也得到了输出图像,但只有1-2秒,之后就出现了这个错误。我测试了一切,但未能解决。任何人都帮助我离开这里。
提前谢谢。
我是什么尝试过:
I am trying to apply "Unsharp Mask" filter on an image. I am using C#.Net(FrameWork 4.0) and VS 2012. I tried this code, I am also getting the output image but only for 1-2 seconds, after that this error is coming. I tested everything but failed to solve.can anyone help me out of here.
Thank you in advance.
What I have tried:
public void unsharp()
{
Oimg = (Bitmap)file.Clone();//input image
for (int x = 0; x < Oimg.Width; x++)
{
for (int y = 0; y < Oimg.Height; y++)
{
Color pixel = Oimg.GetPixel(x, y);
int r = pixel.R;
int g = pixel.G;
int b = pixel.B;
int[] Oarray = new int[] { r, g, b };//input image array
int[] Rarray = new int[Oarray.Length];//resultant image array
newBitmap = (Bitmap)pictureBox1.Image;//filter applied image
for (int m = 0; m < newBitmap.Width; m++)
{
for (int n = 0; n < newBitmap.Height; n++)
{
Color p = newBitmap.GetPixel(m, n);//Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
int r1 = p.R;
int g1 = p.G;
int b1 = p.B;
int[] newarray = new int[] { r1, g1, b1 };//filter applied image array
for (int e = 0; e <= Oarray.Length - 1; e++)
Rarray[e] = Oarray[e] - newarray[e];
//convert array to bitmap
Bitmap Rbmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
int stride = pictureBox1.Width * 4;
unsafe
{
fixed (int* intPtr = &Rarray[Oarray.Length-1])
{
Rbmp = new Bitmap(pictureBox1.Width, pictureBox1.Height, stride, PixelFormat.Format32bppRgb, new IntPtr(intPtr));
}
}
newBitmap = (Bitmap)Rbmp.Clone();
pictureBox1.Image = newBitmap;
}
}
}
}
}
推荐答案
你问了一个相关的问题:如何解决这个问题 指数数组的边界之外。错误? [ ^ ]今天早上,我告诉你要使用调试器。
这是唯一可以告诉你错误的工具:这取决于图片中的数据而我们无法访问它。
所以在该方法的第一行放置一个断点,然后开始研究它,看看发生了什么 - 这是你要解决这个问题的唯一方法!
When you asked a related question: How to solve this " index was outside the bounds of the array." error ?[^] this morning, I told you to use the debugger.
It's the only tool that can tell you what is wrong: this depends on the data in your image and we do not have access to it.
So put a breakpoint on the first line of that method, and start working your way through it, looking at what is going on - it's the only way you are going to solve this!
这篇关于如何解决此错误 - “尝试读取或写入受保护的内存”。这通常表明其他内存已损坏。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文