I want to run this piece of code
Bitmap grayImage = (Bitmap)img.Clone();
for (int x = 0; x < arr.GetLength(0); x++)
{
for (int y = 0; y < arr.GetLength(1); y++)
{
int col = arr[x, y];
Color grau = Color.FromArgb(col, col, col);
grayImage.SetPixel(x, y, grau);
}
}
If I run the code, I get an exception in this line: grayImage.SetPixel (x, y, grau);
Here is the exception information:
System.Runtime.InteropServices.ExternalException wurde nicht behandelt. Message = "A general error occurred in GDI +." Source = "System.Drawing" ErrorCode = -2147467259 Stack traces: in System.Drawing.Bitmap.SetPixel (Int32 x, Int32 y, Color color) in Metalldetektor.Bild.ArrToPic (Int32 [,] arr, Image img) in D : \ Documents \ Visual Studio 2008 \ Projects \ WindowsFormsApplication1 \ WindowsFormsApplication1 \ Bild.cs: line 44 in Metalldetektor.Form1.button2_Click (object sender, EventArgs e) in D: \ Documents \ Visual Studio 2008 \ Projects \ WindowsFormsApplication1 \ WindowsFormsApplication1 \ Form1 .cs: line 58 in System.Windows.Forms.Control.OnClick (EventArgs e) in System.Windows.Forms.Button.OnMouseUp (MouseEventArgs mevent) in System.Windows.Forms.Control.WmMouseUp (Message & m, MouseButtons button ,clicks Int32) in System.Windows.Forms.Control.WndProc (Message & m) in System.Windows.Forms.ButtonBase.WndProc (Message & m) in System.Windows.Forms.Button.WndProc (Message & m) in System .Windows.Forms.Control.ControlNativeWindow.WndProc (Message & m) in System.Windows.Forms.NativeWindow.DebuggableCallback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) in System.Windows.Forms.UnsafeNativeMethod.Disp & msg) in System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (Int32 dwComponentID, reason Int32, Int32 pvLoopData) in System.Windows.Forms.ApplicationRop.Thread , ApplicationContext context) in System.Windows.Forms.Application.ThreadContext.RunMessageLoop (reason Int32, ApplicationContext context) in Metalldetektor.Program.Main () in D: \ Documents \ Visual Studio 2008 \ Projects \ WindowsFormsApplication1 \ WindowsFormsApplication1 \ Program.cs: line 19 in System.AppDomain._nExecuteAssembly (assembly assembly, String [ ] args) in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly () in System.Threading.ExecutionContext.Run (ExecutionContext executeContext, ContextCallback callback, object state) in System.Threading.ThreadHelper.ThreadStart () InnerException:HostProc.RunUsersAssembly () in System.Threading.ExecutionContext.Run (ExecutionContext executeContext, ContextCallback callback, object state) in System.Threading.ThreadHelper.ThreadStart () InnerException:HostProc.RunUsersAssembly () in System.Threading.ExecutionContext.Run (ExecutionContext executeContext, ContextCallback callback, object state) in System.Threading.ThreadHelper.ThreadStart () InnerException:
, , , !
Jenny