This will teach you how to create STU images, and upload them to your Wacom device.
There are three functions you will need in order to upload an image to your STU signature pad. The first is to select an image from a folder. The second alters the properties of the image in order to make it compatible with the STU pad, and the third is to upload it to the pad itself.
The code below was written in Visual Basic, although should be easily converted to any of the other Visual languages. For more information on Visual Studio, and the programming languages it is compatible with, please follow this link to view the Visual Studio homepage.
First, select the image. This function is created as part of a Button Click event, in this case, btnBrowse.
Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
Dim res
res = OpenFileDialog1.ShowDialog()
If (res = DialogResult.OK) Then
txtFilename.Text = OpenFileDialog1.FileName
DisplayImage(Image.FromFile(OpenFileDialog1.FileName))
End If
End Sub
As you can see, the final line in this function calls the next – DisplayImage. This will process the image into a format that can be displayed by the STU signature pad, then display it in a PictureBox control.
Private Sub DisplayImage(ByVal img As Image)
‘ resize the image to fit the panel
‘ STU displays: 300:396×100 430:320×200 500:640×480 520:800×480 530:800×480
‘ 300/420 scale by 2, else scale by 4. Also handle unexpected size.
Dim scale = 1
If (img.Width > 400) Then
scale = 4
ElseIf (img.Width > Panel1.Width) Then
scale = 2
End If
PictureBox1.Size = New Size(img.Width / scale, img.Height / scale)
‘ don’t exceed the panel size:
If (PictureBox1.Size.Width > Panel1.Size.Width Or PictureBox1.Size.Height > Panel1.Size.Height) Then
PictureBox1.Size = Panel1.Size
End If
‘ centre the image in the panel
Dim x, y
x = Panel1.Location.X + ((Panel1.Width – PictureBox1.Width) / 2)
y = Panel1.Location.Y + ((Panel1.Height – PictureBox1.Height) / 2)
PictureBox1.Location = New Point(x, y)
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureBox1.Image = img
PictureBox1.Parent = Me
PictureBox1.BringToFront()
End Sub
Finally, the function needed to upload the image onto the STU pad. Note that this is not a permanent upload. You are not saving the image onto the pad, rather you are sending a screen for the pad to display that just happens to consist of the graphical data of an image file.
Private Sub SendToSTU()
Try
If Connect() <> True Then
Return
End If
print(“Connected: ” + info.modelName)
Dim protocolHelper = New wgssSTU.ProtocolHelper()
Dim encodingFlag As wgssSTU.encodingFlag = 0
Dim encodingMode As wgssSTU.encodingMode = 0
Dim idP = thepad.getProductId()
encodingFlag = protocolHelper.simulateEncodingFlag(idP, encodingFlag)
print(“Encoding flag: ” + encodingFlag.ToString())
If (encodingFlag And wgssSTU.encodingFlag.EncodingFlag_24bit) Then
If (thepad.supportsWrite()) Then
encodingMode = wgssSTU.encodingMode.EncodingMode_24bit_Bulk
Else
encodingMode = wgssSTU.encodingMode.EncodingMode_24bit
End If
ElseIf (encodingFlag And wgssSTU.encodingFlag.EncodingFlag_16bit) Then
If (thepad.supportsWrite()) Then
encodingMode = wgssSTU.encodingMode.EncodingMode_16bit_Bulk
Else
encodingMode = wgssSTU.encodingMode.EncodingMode_16bit
End If
Else
‘ assumes 1bit is available
encodingMode = wgssSTU.encodingMode.EncodingMode_1bit
End If
print(“encodingMode: ” + encodingMode.ToString())
Dim bitmapData ‘// This is the flattened data of the bitmap that we send to the device.
Dim stream As New System.IO.MemoryStream()
PictureBox1.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
bitmapData = protocolHelper.resizeAndFlatten(stream.ToArray(),
0, 0, 0, 0, cap.screenWidth, cap.screenHeight, CByte(encodingMode), wgssSTU.Scale.Scale_Fit, False, 0)
thepad.writeImage(encodingMode, bitmapData)
Disconnect()
Catch ex As Exception
print(“Exception: ” + ex.Message)
End Try
End Sub