@@ -27,17 +27,17 @@ Add this line in the `HelloWorld.html` body to create a color mode conversion bu
2727
2828``` html
2929<input
30- type =" button"
31- value =" Convert to binary image"
32- onclick =" binarizeImage();"
30+ type =" button"
31+ value =" Convert to binary image"
32+ onclick =" binarizeImage();"
3333/>
3434```
3535
3636Then, define ` binarizeImage() ` in the ` script ` element:
3737
3838``` js
3939function binarizeImage () {
40- DWTObject .ConvertToBW (DWTObject .CurrentImageIndexInBuffer );
40+ DWTObject .ConvertToBW (DWTObject .CurrentImageIndexInBuffer );
4141}
4242```
4343
@@ -59,10 +59,10 @@ Define the rotation functions in the `script` element:
5959
6060``` js
6161function rotateCW () {
62- DWTObject .RotateRight (DWTObject .CurrentImageIndexInBuffer );
62+ DWTObject .RotateRight (DWTObject .CurrentImageIndexInBuffer );
6363}
6464function rotateCCW () {
65- DWTObject .RotateLeft (DWTObject .CurrentImageIndexInBuffer );
65+ DWTObject .RotateLeft (DWTObject .CurrentImageIndexInBuffer );
6666}
6767```
6868
@@ -76,90 +76,90 @@ APIs used:
7676
7777``` html
7878<html >
79- <head >
80- <script src =" Resources/dynamsoft.webtwain.initiate.js" ></script >
81- <script src =" Resources/dynamsoft.webtwain.config.js" ></script >
82- </head >
83-
84- <body >
85- <input type =" button" value =" Scan" onclick =" AcquireImage();" />
86- <input type =" button" value =" upload" onclick =" upload();" />
87- <div id =" dwtcontrolContainer" ></div >
88- <input
89- type =" button"
90- value =" Convert to binary image"
91- onclick =" binarizeImage();"
92- />
93- <input type =" button" value =" Rotate clockwise" onclick =" rotateCW();" />
94- <input
95- type =" button"
96- value =" Rotate counter-clockwise"
97- onclick =" rotateCCW();"
98- />
99-
100- <script type =" text/javascript" >
101- var DWTObject;
102-
103- Dynamsoft .DWT .RegisterEvent (" OnWebTwainReady" , function () {
104- DWTObject = Dynamsoft .DWT .GetWebTwain (" dwtcontrolContainer" );
105- });
106-
107- function AcquireImage () {
108- if (DWTObject) {
109- DWTObject .SelectSourceAsync ()
110- .then (function () {
111- return DWTObject .AcquireImageAsync ({
112- IfCloseSourceAfterAcquire: true ,
113- IfShowUI: false ,
114- PixelType: Dynamsoft .DWT .EnumDWT_PixelType .TWPT_GRAY ,
115- Resolution: 150 ,
116- });
117- })
118- .catch (function (exp ) {
119- alert (exp .message );
120- });
121- }
122- }
123-
124- function upload () {
125- if (DWTObject && DWTObject .HowManyImagesInBuffer > 0 ) {
126- var strUrl = " https://demo.dynamsoft.com/sample-uploads/" ;
127- var imgAry = [DWTObject .CurrentImageIndexInBuffer ];
128- DWTObject .HTTPUpload (
129- strUrl,
130- imgAry,
131- Dynamsoft .DWT .EnumDWT_ImageType .IT_PNG ,
132- Dynamsoft .DWT .EnumDWT_UploadDataFormat .Binary ,
133- " WebTWAINImage.png" ,
134- onUploadSuccess,
135- onUploadFailure
136- );
137- } else {
138- alert (" There is no image in buffer." );
139- }
140- }
141-
142- function onUploadSuccess () {
143- alert (" Upload successful" );
144- }
145-
146- function onUploadFailure (errorCode , errorString , sHttpResponse ) {
147- alert (sHttpResponse .length > 0 ? sHttpResponse : errorString);
148- }
149-
150- function binarizeImage () {
151- DWTObject .ConvertToBW (DWTObject .CurrentImageIndexInBuffer );
152- }
153-
154- function rotateCW () {
155- DWTObject .RotateRight (DWTObject .CurrentImageIndexInBuffer );
156- }
157-
158- function rotateCCW () {
159- DWTObject .RotateLeft (DWTObject .CurrentImageIndexInBuffer );
160- }
161- </script >
162- </body >
79+ <head >
80+ <script src =" Resources/dynamsoft.webtwain.initiate.js" ></script >
81+ <script src =" Resources/dynamsoft.webtwain.config.js" ></script >
82+ </head >
83+
84+ <body >
85+ <input type =" button" value =" Scan" onclick =" AcquireImage();" />
86+ <input type =" button" value =" upload" onclick =" upload();" />
87+ <div id =" dwtcontrolContainer" ></div >
88+ <input
89+ type =" button"
90+ value =" Convert to binary image"
91+ onclick =" binarizeImage();"
92+ />
93+ <input type =" button" value =" Rotate clockwise" onclick =" rotateCW();" />
94+ <input
95+ type =" button"
96+ value =" Rotate counter-clockwise"
97+ onclick =" rotateCCW();"
98+ />
99+
100+ <script type =" text/javascript" >
101+ var DWTObject;
102+
103+ Dynamsoft .DWT .RegisterEvent (" OnWebTwainReady" , function () {
104+ DWTObject = Dynamsoft .DWT .GetWebTwain (" dwtcontrolContainer" );
105+ });
106+
107+ function AcquireImage () {
108+ if (DWTObject) {
109+ DWTObject .SelectSourceAsync ()
110+ .then (function () {
111+ return DWTObject .AcquireImageAsync ({
112+ IfCloseSourceAfterAcquire: true ,
113+ IfShowUI: false ,
114+ PixelType: Dynamsoft .DWT .EnumDWT_PixelType .TWPT_GRAY ,
115+ Resolution: 150 ,
116+ });
117+ })
118+ .catch (function (exp ) {
119+ alert (exp .message );
120+ });
121+ }
122+ }
123+
124+ function upload () {
125+ if (DWTObject && DWTObject .HowManyImagesInBuffer > 0 ) {
126+ var strUrl = " https://demo.dynamsoft.com/sample-uploads/" ;
127+ var imgAry = [DWTObject .CurrentImageIndexInBuffer ];
128+ DWTObject .HTTPUpload (
129+ strUrl,
130+ imgAry,
131+ Dynamsoft .DWT .EnumDWT_ImageType .IT_PNG ,
132+ Dynamsoft .DWT .EnumDWT_UploadDataFormat .Binary ,
133+ " WebTWAINImage.png" ,
134+ onUploadSuccess,
135+ onUploadFailure
136+ );
137+ } else {
138+ alert (" There is no image in buffer." );
139+ }
140+ }
141+
142+ function onUploadSuccess () {
143+ alert (" Upload successful" );
144+ }
145+
146+ function onUploadFailure (errorCode , errorString , sHttpResponse ) {
147+ alert (sHttpResponse .length > 0 ? sHttpResponse : errorString);
148+ }
149+
150+ function binarizeImage () {
151+ DWTObject .ConvertToBW (DWTObject .CurrentImageIndexInBuffer );
152+ }
153+
154+ function rotateCW () {
155+ DWTObject .RotateRight (DWTObject .CurrentImageIndexInBuffer );
156+ }
157+
158+ function rotateCCW () {
159+ DWTObject .RotateLeft (DWTObject .CurrentImageIndexInBuffer );
160+ }
161+ </script >
162+ </body >
163163</html >
164164```
165165
0 commit comments