如何设置分辨率并调整捕获图像的大小? [英] how to set resolution and resize the captured image?
本文介绍了如何设置分辨率并调整捕获图像的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨!全部,
我已经在VB.Net中创建了一个图像捕获代码,为此我使用了interop.WIA.dll,
我面临的问题是,当我捕获图像时,它的大小很大,我想将其分辨率和大小调整为较小.
以下是我用来捕获图像的代码,我无法调整图像的大小.
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.
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
推荐答案
希望使用VB.NET调整图像大小并裁剪图像 [
Hope Image Cropping with Image Resizing Using VB.NET[^] article from CP might help you.
此处是调整图像大小的便捷小程序
Here is a handy little routine for resizing images
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
这篇关于如何设置分辨率并调整捕获图像的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文