문제

enter image description here

I have an Image object that I'm trying to resize from a picture box via Bitmap.

I have a source to the picture box on my desktop and the code is as follows

Bitmap image = new Bitmap(pictureBox1.Image);
Size newSize = new Size(100,100);

image = new Bitmap( (Image)image, newSize); 
// here I get Parameter not valid, Argument Exception was unhandled

pictureBox1.Image = (Image)image;

Why is that exception being thrown?

도움이 되었습니까?

해결책

First of all, I don't understand why you create 2 bitmap objects? Why do not something like this:

Bitmap image = (Bitmap)pictureBox1.Image;
Size newSize = new Size(100,100);
Bitmap newImage = new Bitmap((Image)image, newSize);
image.Dispose();

However I don't think that exception is caused by shown code. It's possible to read above on screen :

newSize {Width = 128000 Height = 59500}

Have you calculated how big is that picture?

Size x 4 bytes of format = 3.0464^ 10.

I don't think that you have enough memory to allocate this image.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top