어떻게 덮어쓰기는 원본 이미지로 자른 버전이 이미지의 c#데스크탑 응용 프로그램

0

질문

내가 건축 c#contact 관리자는 바탕 화면 응용 프로그램을 선택할 수 있는 아바타에서 이미지 파일 이후 작물니다. 원본 이미지가 제대로 표시된 후 자르기,대체 원래 하나입니다. 그러나 나중에는 그에 따라 등록하려고 시도는 계정의 이미지가 나타나 Null 이 될 수 있기와 같은 오류가 표시됩니다.

시스템입니다.ArgumentNullException:"값은 null 이 될 수 없습니다. (매개변수 'encoder')"

는 방법에 대한 이미지를 업로드 등록 페이지:

        private void button_browse_Click(object sender, EventArgs e)
        {
            // select and display image in the picturebox
            OpenFileDialog opf = new OpenFileDialog();
            opf.Filter = "Select Image(*.jpg;*.png;*.gif)|*.jpg;*.png;*.gif";
            

            if(opf.ShowDialog() == DialogResult.OK)
            {
                pictureBoxProfileImage.Image = Image.FromFile(opf.FileName);
                setImage(pictureBoxProfileImage.Image);
            }
        }

는 방법에 대한 이미지가 잘:

private void button_Select_Cropped_Area_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.Default;

            Bitmap bitmap2 = new Bitmap(pictureBoxProfileImage.Width, pictureBoxProfileImage.Height);
            pictureBoxProfileImage.DrawToBitmap(bitmap2, pictureBoxProfileImage.ClientRectangle);

            Bitmap croppedImage = new Bitmap(rectW, rectH);
            for (int x = 0; x < rectW; x++)
            {
                for (int y = 0; y < rectH; y++)
                {
                    Color pxlColor = bitmap2.GetPixel(cropX + x, cropY + y);
                    croppedImage.SetPixel(x, y, pxlColor);
                }
            }
            pictureBoxProfileImage.Image.Dispose();
            pictureBoxProfileImage.Image = (Image)croppedImage;
            pictureBoxProfileImage.SizeMode = PictureBoxSizeMode.StretchImage;
        }

여기에 라인에 오류가 발생하고 이미지를 저장할 때:

MemoryStream picture = new MemoryStream();
pictureBoxProfileImage.Image.Save(picture, pictureBoxProfileImage.Image.RawFormat);

그것은 언급 할 가치가있는 등록이 제대로 작동하는 경우 원본 이미지는 허용되지 않습니다. 어야 나는 그들을 대체 어떻게 든(덮어 원래 하나로 자른 하나는)?

c# crop
2021-11-15 11:20:12
1

최고의 응답

1

내 생각은 실패로 인해 발생하는 pictureBoxProfileImage.Image.RawFormat. 당신은 단지 대체 pictureBoxProfileImage.Image지만,무엇 rawFormat 가 new Bitmap(...) 가? 안을 찾을 수 없습니다 모든 문서,그것에 대해 내가 생각했던 것과하지 않는 모든 유효한 rawFormat 다.

그래서 나는 것을 시도를 바꾸거나 그것은 무언가 ImageFormat.Png또는 저장 rawFormat 에서 원래의 비트 맵을 사용할 때 절약입니다.

2021-11-15 13:51:04

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................