Chaima Soltani
Chaima Soltani

Reputation: 47

Getting unhandled exception in using Graphics

I get unhandled exception when I run this code:

using (Graphics g = Graphics.FromImage(target))
 {
   g.DrawImage(imageInput, new Rectangle(0, 0, target.Width, target.Height),
               rect, GraphicsUnit.Pixel);
 }

It says :

System.ArgumentNullException : 'The value can not be null. Parameter name: image

Any suggestion?

Upvotes: 0

Views: 141

Answers (2)

John H
John H

Reputation: 14655

This is because imageInput is null. Parameter name: image is the important part. If you take a look at the documentation for DrawImage, you'll see it takes an image parameter. This is the first argument passed to DrawImage, which corresponds with imageInput.

Therefore, you need to initialise imageInput.

Upvotes: 1

Billy
Billy

Reputation: 320

You need to supply a source image; imageInput can't be null.

Upvotes: 0

Related Questions