Serpwidgets
New member
I've tried searching and none of the answers here make any sense to me.
I'm moving up from VB5 (and doing graphics with the API) to .net and trying to get a grip on the graphics system. I'm simply trying to load a picture, resize it, and save it as a jpeg at a specific quality.
My test app uses the following to load and draw the graphic, which works fine:
...but when I try to save it tells me that the Image = Nothing. (NullreferenceException was unhandled, IOW the "image" doesn't exist.)
I've read several other threads, and the answers are always in generalities, no code... what exactly (in code) do I need to do in order to put what is in the picturebox into a file?
Also, I have not been able to figure out what reference is used to set/get the "quality/compression" level used when saving a jpeg. Can this be set to any integer between 1-100 or it is only a couple of predefined "quality" settings?
Thanks in advance.
I'm moving up from VB5 (and doing graphics with the API) to .net and trying to get a grip on the graphics system. I'm simply trying to load a picture, resize it, and save it as a jpeg at a specific quality.
My test app uses the following to load and draw the graphic, which works fine:
VB.NET:
Private myBitmap As Bitmap
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load[/SIZE]
[SIZE=2] myBitmap = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Bitmap([/SIZE][SIZE=2][COLOR=#a31515]"C:\Documents and Settings\Owner\Desktop\Windy.bmp"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] PictureBox1_Paint([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.PaintEventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] PictureBox1.Paint[/SIZE]
[SIZE=2] e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic[/SIZE]
[SIZE=2] e.Graphics.DrawImage(myBitmap, 0, 0, PictureBox1.Width, PictureBox1.Height)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_KeyDown([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.KeyEventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].KeyDown[/SIZE]
[SIZE=2] PictureBox1.Image.Save([/SIZE][SIZE=2][COLOR=#a31515]"C:\Documents and Settings\Owner\Desktop\WindyTest.jpg"[/COLOR][/SIZE][SIZE=2], Imaging.ImageFormat.Jpeg)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
...but when I try to save it tells me that the Image = Nothing. (NullreferenceException was unhandled, IOW the "image" doesn't exist.)
I've read several other threads, and the answers are always in generalities, no code... what exactly (in code) do I need to do in order to put what is in the picturebox into a file?
Also, I have not been able to figure out what reference is used to set/get the "quality/compression" level used when saving a jpeg. Can this be set to any integer between 1-100 or it is only a couple of predefined "quality" settings?
Thanks in advance.