2009-05-16 4 views
3
이 코드 조각을 실행하고 싶습니다. 코드를 실행하면이 줄에서 예외가 발생합니다. grayImage.SetPixel (x, y, grau); 다음은 예외 정보입니다. System.Runtime.InteropServices.ExternalException wurde nicht behandelt. Message = "GDI +에서 일반 오류가 발생했습니다." 원본 : "System.Drawing" ErrorCode = -2147467259 StackTrace : System.Drawing.Bitmap.SetPixel에서 (Int32 x, Int32 y, 색상 색상) at Metalldetektor.Bild.ArrToPic (Int32 [,] arr, Image D : \ Documents \ Visual Studio 2008 \ Projects \ WindowsFormsApplication1 \ WindowsFormsApplication1 \ Bild.cs에서 다음을 수행하십시오. D : \ Documents \ Visual Studio 2008 \ Projects \에있는 Metalldetektor.Form1.button2_Click (Object Sender, EventArgs e) WindowsFormsApplication1 \ WindowsFormsApplication1 \ Form1.cs : System.Windows.Forms.Control.OnClick (EventArgs e) at System.Windows.Forms.Button.OnMouseUp (MouseEventArgs mevent) at System.Windows.Forms.Control. WmMouseUp (Message m, MouseButtons 단추, Int32 클릭) System.Windows.Forms.Control.WndProc (Message m)에서 System.Windows.Forms.ButtonBase.WndProc (m 메시지) System.Windows에서 . Forms.Button.WndProc (Message m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc (M System.Windows.Forms.NativeWindow.DebuggableCallback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)의 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW (MSG msg)의 System.Windows의 . Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (Int32 dwComponentID, Int32 이유, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Int32 이유, ApplicationContext 컨텍스트) at System .Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32 이유, ApplicationContext 컨텍스트) D : \ Documents \ Visual Studio 2008 \ Projects \ WindowsFormsApplication1 \ WindowsFormsApplication1 \ Program.cs의 Metalldetektor.Program.Main()에서 : 줄 19 at System.Threading.ExecutionContext.Run에서 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 의 System.AppDomain._nExecuteAssembly (어셈블리 어셈블리, String [] args) (Exe cutionContext executionContext, ContextCallback 콜백, 객체 상태) System.Threading.ThreadHelper.ThreadStart()에서 InnerException : 무엇을 해야할지 모르겠다.

답변

2

복제 된 비트 맵에 인공물이있는 비슷한 문제가있었습니다. 잠시 동안이 문제를 연구 한 후에 도움을 얻은 this thread을 발견했습니다.

하면이와 클론()

Bitmap grayImage = (Bitmap)img.Clone(); 

를 교체하십시오 :

Bitmap grayImage = new Bitmap(img); 
+0

덕분에 지금 잘 작동 –

0

버그에 대해 모르겠지만 LockBits의 경우 일 수 있습니다. 예를 들어 보겠습니다.

은 여기 ARGB 비트 맵 데이터의 배열을 작성하는 간단한 예이다 :

// fake data 
    int[,] data = new int[100, 150]; 
    int width = data.GetLength(0), height= data.GetLength(1); 
    for (int x = 0; x < width; x++) 
     for (int y = 0; y < height; y++) 
      data[x, y] = x + y; 

    // process it into a Bitmap 
    Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb); 
    BitmapData bd = bmp.LockBits(new Rectangle(0, 0, width, height), 
     ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); 
    unsafe { 
     byte* root = (byte*)bd.Scan0; 
     for (int y = 0; y < height; y++) { 
      byte* pixel = root; 
      for (int x = 0; x < width; x++) { 
       byte col = (byte)data[x, y]; 
       pixel[0] = col; 
       pixel[1] = col; 
       pixel[2] = col; 
       pixel[3] = 255; 
       pixel += 4; 
      } 
      root += bd.Stride; 
     } 
    } 
    bmp.UnlockBits(bd); 
    bmp.Save("foo.bmp"); // or show on screen, etc 

이 접근법은 SetPixel보다 많이 빠를 것이다.

0

오래 전 내 팀원 시스템에서 이미지 (SQL 서버에서 바이너리 데이터를 읽음으로써 이미지 생성)를 처리 할 때 약간의 오류가있었습니다.동일한 코드가 다른 컴퓨터에서도 잘 작동했습니다. 그래픽 드라이버 업데이트를 설치했는데 문제가 발생했다.

0

모든 것을 겹쳐 쓰는 경우 (또는 왼쪽 상단 사각형) 다른 이미지를 복제하는 이유는 무엇입니까?