나는 소수 픽셀 데이터 (16 비트 회색조 값)의 배열을 가지고 있으며 jpeg 이미지로 저장하려고합니다. 그러나 내 코드 "GDI +에서 일반 오류가 발생했습니다"저장 명령을 충돌하는 것입니다. 이 문제를 해결하는 방법을 알 수 없습니다. 내가 저장하고있는 디렉토리는 내 응용 프로그램에 의해 만들어지며 다른 파일을이 디렉토리에 씁니다. 그래서 나는 권한 문제가 아니라는 것을 안다. 어쩌면 데이터 손상 문제일까요? Bitmap 객체에 ushort 데이터를 가져 오는 단계에서 뭔가 잘못하고 있습니까? 내가 ushort 데이터를 가지고 있기 때문에 Bitmap 객체로 가져 오는 방법을 파악하는 데 약간의 노력이 필요하다는 것을 알았습니다.Bitmap 개체를 jpeg로 저장할 때 "일반 오류가 GDI +에서 발생했습니다"C#
Bitmap img = new Bitmap(width, height, PixelFormat.Format16bppGrayScale);
Rectangle rect = new Rectangle(0,0, width, height);
BitmapData picData = img.LockBits(rect, ImageLockMode.ReadWrite, img.PixelFormat);
IntPtr pixelStartAddress = picData.Scan0;
WriteableBitmap pic = new WriteableBitmap(width, height, 96.0, 96.0, System.Windows.Media.PixelFormats.Gray16, null);
int stride = (thumb.XSize * pic.Format.BitsPerPixel + 7)/8;
pic.WritePixels(new System.Windows.Int32Rect(0, 0, width, height), dataArray, stride, 0);
pic.CopyPixels(new System.Windows.Int32Rect(0,0,thumb.XSize, thumb.YSize),pixelStartAddress, dataArray.Length * sizeof(ushort), stride);
img.UnlockBits(picData);
img.Save(path, ImageFormat.Jpeg);
것은이 모든 일이 매우 실망되었다 :
여기 내 코드입니다. 도와주세요?!
별도의 스레드에서 실행하고 있습니까? – jjxtra
그래, 나는이 스레드를 별도의 스레드에서 실행한다. 그게 문제라고 생각하니? –