<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBScript: сканирование с заданными параметрами]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=4387&amp;type=atom" />
	<updated>2010-05-06T09:05:54Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=4387</id>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: сканирование с заданными параметрами]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=35342#p35342" />
			<content type="html"><![CDATA[<p>На практике встретился случай: в строке задания размеров <strong>А4</strong>, предельно допустимая длина оказалась равной <strong>296.92 мм</strong> вместо <strong>297 мм</strong>. Т.е:<br /></p><div class="codebox"><pre><code>intVerticalSize   = (296.92 / 25.4) * intDPI &#039; Размер по вертикали — A4</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Lucky]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=25698</uri>
			</author>
			<updated>2010-05-06T09:05:54Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=35342#p35342</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBScript: сканирование с заданными параметрами]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=35325#p35325" />
			<content type="html"><![CDATA[<p>Если вдруг у вас не оказалось нужной dll-библиотеки для создания объекта <strong>&quot;WIA.DeviceManager&quot;</strong>, она тут: <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=a332a77a-01b8-4de6-91c2-b7ea32537e29#filelist">Download details: Windows® Image Acquisition Automation Library v2.0 Tool: Image acquisition and manipulation component for VB and scripting</a></p>]]></content>
			<author>
				<name><![CDATA[Lucky]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=25698</uri>
			</author>
			<updated>2010-05-06T07:45:45Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=35325#p35325</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBScript: сканирование с заданными параметрами]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=34878#p34878" />
			<content type="html"><![CDATA[<p>Сканирование с заданным форматом (размером и положением области сканирования), разрешением, цветовой моделью и сохранение полученного изображения в файл посредством технологии <strong>Windows Image Acquisition</strong> (<strong>WIA</strong>):<br /></p><div class="codebox"><pre><code>Option Explicit

Const ScannerDeviceType = 1
Const ColorIntent = 1
Const wiaFormatJPEG = &quot;{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}&quot;


Dim objDeviceManager
Dim objDeviceInfos
Dim objDevice

Dim objImageFile
Dim objImageProcess

Dim strPath2Save
Dim strFormat
Dim intQuality
Dim intDPI
Dim intHorizontalSize
Dim intVerticalSize


&#039; Задаём характеристики изображения
strPath2Save      = &quot;c:\MyImage.jpg&quot;      &#039; Полное имя файла для сохранения
strFormat         = wiaFormatJPEG         &#039; Формат файла — *.jpg
intQuality        = 85                    &#039; Качество jpg
intDPI            = 150                   &#039; Разрешение — 150 dpi
intHorizontalSize = (210 / 25.4) * intDPI &#039; Размер по горизонтали — A4
intVerticalSize   = (297 / 25.4) * intDPI &#039; Размер по вертикали — A4


Set objDeviceManager = WScript.CreateObject(&quot;WIA.DeviceManager&quot;)
Set objDeviceInfos = objDeviceManager.DeviceInfos

If objDeviceInfos.Count &gt; 0 Then
    &#039; Выбираем устройство для сканирования. Если оно единственное, то сие произойдёт без отображения диалога.
     Set objDevice = WScript.CreateObject(&quot;WIA.CommonDialog&quot;).ShowSelectDevice(ScannerDeviceType, False, False)
    &#039; Кроме того, зная DeviceID устройства, можно использовать иной способ подключения, например:
    &#039;Dim objDeviceInfo
    &#039;
    &#039;For Each objDeviceInfo In objDeviceManager.DeviceInfos
    &#039;    WScript.Echo objDeviceInfo.DeviceID
    &#039;    
    &#039;    If objDeviceInfo.DeviceID = &quot;{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0000&quot; Then
    &#039;        Set objDevice = objDeviceInfo.Connect
    &#039;    End If
    &#039;Next
    
    If Not objDevice Is Nothing Then
        WScript.Echo objDevice.Properties.Item(&quot;Name&quot;) &amp; &quot; [&quot; &amp; objDevice.DeviceID &amp; &quot;]&quot;
        WScript.Echo &quot;Scanning...&quot;
        
        With objDevice
            With .Items(1)
                &#039; Задаём требуемые характеристики изображения для сканирования
                With .Properties
                    .Item(&quot;6146&quot;).Value = ColorIntent             &#039; Цветовая модель (Current Intent)
                    
                    &#039; Разрешение…
                    .Item(&quot;6147&quot;).Value = intDPI                  &#039; …по горизонтали (Horizontal Resolution)
                    .Item(&quot;6148&quot;).Value = intDPI                  &#039; …по вертикали (Vertical Resolution)
                    
                    &#039; Начало области сканирования…
                    .Item(&quot;6149&quot;).Value = 0                       &#039; …по горизонтали (Horizontal Start Position)
                    .Item(&quot;6150&quot;).Value = 0                       &#039; …по вертикали (Vertical Start Position)
                    
                    &#039; Размер области сканирования…
                    .Item(&quot;6151&quot;).Value = intHorizontalSize       &#039; …по горизонтали (Horizontal Extent)
                    .Item(&quot;6152&quot;).Value = intVerticalSize         &#039; …по вертикали (Vertical Extent)
                End With
                
                &#039; Инициируем начало операции сканирования
                Set objImageFile = .Transfer()
                
                &#039; Конвертируем полученное изображение
                WScript.Echo &quot;Converting...&quot;
                
                Set objImageProcess = WScript.CreateObject(&quot;WIA.ImageProcess&quot;)
                
                With objImageProcess
                    With .Filters
                        .Add objImageProcess.FilterInfos(&quot;Convert&quot;).FilterID
                        
                        With .Item(1).Properties
                            .Item(&quot;FormatID&quot;).Value = strFormat  &#039; Формат изображения
                            .Item(&quot;Quality&quot;).Value  = intQuality &#039; Качество изображения
                        End With
                    End With
                    
                    Set objImageFile = .Apply(objImageFile)
                End With
            End With
        End With
        
        &#039; Если файл существует — предварительно удаляем его
        With WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;)
            If .FileExists(strPath2Save) Then
                .DeleteFile strPath2Save
            End If
        End With
        
        &#039; Сохраняем полученное изображение
        objImageFile.SaveFile strPath2Save
        
        WScript.Echo &quot;Complete.&quot;
        
        Set objDevice = Nothing
    Else
        WScript.Echo &quot;Cancel scanning by user&quot;
    End If
Else
    WScript.Echo &quot;No connected devices&quot;
End If

Set objDeviceManager = Nothing
Set objDeviceInfos   = Nothing

WScript.Quit 0</code></pre></div>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2010-04-18T02:16:13Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=34878#p34878</id>
		</entry>
</feed>
