|
-
Nov 30th, 2002, 01:24 AM
#1
Thread Starter
Junior Member
Resizing An Image in VB.NET
Well, I'm writing a Windows app to open up an image, store that into an SQL DB, resize it to a thumbnail size, and store that into the DB. I got everything to work, except for saving the image. First, just to test it, I .save'ed it to a system.io.file, instead of a system.io.stream (i need a stream to insert into the database). Here is my code, maybe I'm missing something...
Code:
Private Sub Go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Go.Click
Dim origimg As System.Drawing.Image = System.Drawing.Image.FromFile(Image.Text)
Dim tsize As Size, dw As Int16, dh As Int16, thumbnail As Stream, bigimage As Stream
With origimg.Size
If .Width <= 320 Then dw = 1
If .Width > 320 And .Width <= 640 Then dw = 2
If .Width > 640 And .Width <= 960 Then dw = 3
If .Width > 960 And .Width <= 1024 Then dw = 4
If .Width > 1024 Then dw = 5
If .Height <= 320 Then dh = 1
If .Height > 320 And .Height <= 640 Then dh = 2
If .Height > 640 And .Height <= 960 Then dh = 3
If .Height > 960 And .Height <= 1024 Then dh = 4
If .Height > 1024 Then dh = 5
End With
tsize.Height = origimg.Size.Height / dh
tsize.Width = origimg.Size.Width / dw
'''''''''''''''''Errors on the following line
origimg.Save(bigimage, Imaging.ImageFormat.Jpeg)
Dim thumba As New System.Drawing.Bitmap(origimg, tsize.Width, tsize.Height)
thumba.Save(thumbnail, System.Drawing.Imaging.ImageFormat.Gif)
UpdateDB(Description.Text, bigimage, thumbnail, Category.SelectedText)
End Sub
The error it gives is: An unhandled exception of type 'System.NullReferenceException' occurred in DBImageUploader.exe, Additional information: Object reference not set to an instance of an object.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|