Click here to Skip to main content
15,937,861 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi! all,
I have created a image capturing code in VB.Net, for this i used the interop.WIA.dll,
the problem i am facing is when i capture the image, it's size is big and i want to resize it's resolution and size to small.
Following is the code i'm using to capture the image and i can't resize the image.
VB
Private Sub btnGrab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGrab.Click
        Dim item As WIA.Item
        Try
            'executes the device's TakePicture command
            item = SelectedDevice.ExecuteCommand(WIA.CommandID.wiaCommandTakePicture)
        Catch ex As System.Exception
            MessageBox.Show("Problem Taking Picture. Please make sure that the camera is plugged in and is not in use by another application. " & vbCrLf & "Extra Info:" & ex.Message, "Problem Grabbing Picture", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)
            Exit Sub
        End Try
        Dim jpegGuid As String
        'retrieves jpegKey from registry, used in saving JPEG
        Dim jpegKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("CLSID\{D2923B86-15F1-46FF-A19A-DE825F919576}\SupportedExtension\.jpg")
        jpegGuid = CType(jpegKey.GetValue("FormatGUID"), String)
        'loops through available formats for the captured item, looking for the JPG format
        For Each format As String In item.Formats
            If (format = jpegGuid) Then
                'transfers image to an imagefile object
                Dim imagefile As WIA.ImageFile = CType(item.Transfer(format), WIA.ImageFile)
                Dim Counter As Integer 'counter in loop appended to filename
                Dim LoopAgain As Boolean = True
                Dim height As Int32 = CInt(Val(10))
                Dim width As Int32 = CInt(Val(10))

                'searches directory, gets next available picture name
                Do Until LoopAgain = False
                    Dim Filename As String = SavePath & "\" & txtPrefix.Text & Counter.ToString & ".jpg"
                    'if file doesnt exist, save the file
                    If Not System.IO.File.Exists(Filename) Then
                        SavedFilePath = Filename
                        imagefile.SaveFile(Filename) 'saves file to disk
                        lblCapName.Text = FormatPath(Filename)
                        lblImageName.Text = txtPrefix.Text & Counter.ToString & ".jpg"
                        picCap.Image = Image.FromFile(Filename) 'loads captured file to picturebox
                        Image.FromFile(Filename)
                        'Image()
                        LoopAgain = False
                        imagefile.Height.ToString()
                    End If
                    Counter = Counter + 1
                Loop
            End If
        Next
        If grpSaved.Enabled = False Then
            grpSaved.Enabled = True
        End If
    End Sub
Posted
Updated 28-Apr-11 23:36pm
v2
Comments
Nischal Bhatt 29-Apr-11 5:43am    
You can have a look at this link for my question.
http://www.vbforums.com/showthread.php?t=378126

Hope Image Cropping with Image Resizing Using VB.NET[^] article from CP might help you.
 
Share this answer
 
Here is a handy little routine for resizing images

C#
private static Image resizeImage(Image imgToResize, Size sizeOfNewImage)
        {
            Bitmap bmp = new Bitmap(sizeOfNewImage.Width, sizeOfNewImage.Height);
            Graphics gra = Graphics.FromImage((Image)bmp);
            gra.InterpolationMode = InterpolationMode.HighQualityBicubic;//Can try various other quality enumerations
            gra.DrawImage(imgToResize, 0, 0, sizeOfNewImage.Width, sizeOfNewImage.Height);
            gra.Dispose();
            return (Image)bmp;
        }


Hope this helps
 
Share this answer
 
Comments
Nischal Bhatt 29-Apr-11 6:28am    
I tried this but it's not working...don't know why..
Wayne Gaylard 29-Apr-11 7:37am    
Did it throw an exception or what was the problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900