WIA 2.0 - AJUDA PARA ALTERAR RESOLU?ÃO DPI

SHAFICK 20/08/2016 05:34:05
#466023
Boas!

Estou usando o Microsoft Windows Image Acquisition Library v2.0 (WIA) para digitalizar imagens. Porém, cada imagem está ficando com 25mb em média (jpg, bmp, png, gif ou tiff da na mesma). A ideia é converter para PDF após a digitalização; mesmo assim, o arquivo PDF está ficando com 8mb em média.
Pensei então em diminuir a resolução da imagem digitalizada, mas estou encontrando dificuldade para lidar com essa propriedade.
Alguém pode ajudar? Ou sugerir alguma outra forma de obter imagens menores em MB?
Obrigado.

Código da Class usada.

  
Imports WIA

Public Class class_cp_Scanner

Private ReadOnly _deviceInfo As DeviceInfo

Public Sub New(deviceInfo As DeviceInfo)
Me._deviceInfo = deviceInfo
End Sub

Public Function Scan() As ImageFile
[ô] Connect to the device
Dim device = Me._deviceInfo.Connect()

[ô]define dialogo para telas de scan (para scan com barra de progresso)
Dim dialog = New WIA.CommonDialogClass()

[ô] Start the scan
Dim item = device.Items(1)
[ô]scan sem barra de progresso
[ô][ô][ô][ô]Dim imageFile = DirectCast(item.Transfer(FormatID.wiaFormatJPEG), ImageFile)

AdjustScannerSettings(item, 300, 0, 0, 1010, 620, 0, 0)

[ô]scan com barra de progresso
Dim imageFile = TryCast(dialog.ShowTransfer(item, WIA.FormatID.wiaFormatJPEG), WIA.ImageFile)

[ô] Return the imageFile
Return imageFile
End Function

Public Overrides Function ToString() As String
Return Me._deviceInfo.Properties([Ô]Name[Ô]).Value.ToString [ô] get_Value().ToString()
End Function

Public Sub SetWIAProperty(properties As IProperties, propName As Object, propValue As Object)
Dim prop As [Property] = properties.get_Item(propName)
prop.set_Value(propValue)
End Sub

Public Sub AdjustScannerSettings(scannnerItem As IItem, scanResolutionDPI As Integer, scanStartLeftPixel As Integer, scanStartTopPixel As Integer, scanWidthPixels As Integer, scanHeightPixels As Integer, _
brightnessPercents As Integer, contrastPercents As Integer)
Const WIA_HORIZONTAL_SCAN_RESOLUTION_DPI As String = [Ô]6147[Ô]
Const WIA_VERTICAL_SCAN_RESOLUTION_DPI As String = [Ô]6148[Ô]
Const WIA_HORIZONTAL_SCAN_START_PIXEL As String = [Ô]6149[Ô]
Const WIA_VERTICAL_SCAN_START_PIXEL As String = [Ô]6150[Ô]
Const WIA_HORIZONTAL_SCAN_SIZE_PIXELS As String = [Ô]6151[Ô]
Const WIA_VERTICAL_SCAN_SIZE_PIXELS As String = [Ô]6152[Ô]
Const WIA_SCAN_BRIGHTNESS_PERCENTS As String = [Ô]6154[Ô]
Const WIA_SCAN_CONTRAST_PERCENTS As String = [Ô]6155[Ô]

SetWIAProperty(scannnerItem.Properties, WIA_HORIZONTAL_SCAN_RESOLUTION_DPI, scanResolutionDPI)
SetWIAProperty(scannnerItem.Properties, WIA_VERTICAL_SCAN_RESOLUTION_DPI, scanResolutionDPI)
SetWIAProperty(scannnerItem.Properties, WIA_HORIZONTAL_SCAN_START_PIXEL, scanStartLeftPixel)
SetWIAProperty(scannnerItem.Properties, WIA_VERTICAL_SCAN_START_PIXEL, scanStartTopPixel)
SetWIAProperty(scannnerItem.Properties, WIA_HORIZONTAL_SCAN_SIZE_PIXELS, scanWidthPixels)
SetWIAProperty(scannnerItem.Properties, WIA_VERTICAL_SCAN_SIZE_PIXELS, scanHeightPixels)
SetWIAProperty(scannnerItem.Properties, WIA_SCAN_BRIGHTNESS_PERCENTS, brightnessPercents)
SetWIAProperty(scannnerItem.Properties, WIA_SCAN_CONTRAST_PERCENTS, contrastPercents)
End Sub

End Class


Erro obtido na linha: AdjustScannerSettings(item, 300, 0, 0, 1010, 620, 0, 0)

An unhandled exception of type [ô]System.MissingMemberException[ô] occurred in Microsoft.VisualBasic.dll
Additional information: Public member [ô]get_Item[ô] on type [ô]PropertiesClass[ô] not found.

Referência: http://www.nakov.com/blog/2009/11/17/playing-with-the-scanner-with-wia-and-c/

Usando: VB.NET 2013
Faça seu login para responder