Example #1
0
        /// <summary>
        /// Sets an extension control property image (if supported by tablet).
        /// </summary>
        /// <param name="context_I">wintab context</param>
        /// <param name="extTagIndex_I">which extension tag we're setting</param>
        /// <param name="tabletIndex_I">index of the tablet being set</param>
        /// <param name="controlIndex_I">the index of the control being set</param>
        /// <param name="functionIndex_I">the index of the control function being set</param>
        /// <param name="propertyID_I">ID of the property being set</param>
        /// <param name="value_I">value of the property being set (a string)</param>
        /// <returns>true if successful</returns>
        public static bool ControlPropertySetImage(
            HCTX context_I,
            byte extTagIndex_I,
            byte tabletIndex_I,
            byte controlIndex_I,
            byte functionIndex_I,
            ushort propertyID_I,
            String imageFilePath_I
            )
        {
            bool retStatus = false;
            WTExtensionImageProperty extProperty = new WTExtensionImageProperty();
            IntPtr buf = CMemUtils.AllocUnmanagedBuf(extProperty);

            try
            {
                byte[] imageBytes             = null;
                System.Drawing.Image newImage = Image.FromFile(imageFilePath_I);

                if (newImage == null)
                {
                    MessageBox.Show("Oops - couldn't find/read image: " + imageFilePath_I);
                    return(false);
                }

                using (MemoryStream ms = new MemoryStream())
                {
                    newImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    imageBytes = ms.ToArray();
                }

                extProperty.extBase.version       = 0;
                extProperty.extBase.tabletIndex   = tabletIndex_I;
                extProperty.extBase.controlIndex  = controlIndex_I;
                extProperty.extBase.functionIndex = functionIndex_I;
                extProperty.extBase.propertyID    = propertyID_I;
                extProperty.extBase.reserved      = 0;
                extProperty.extBase.dataSize      = (uint)imageBytes.Length;
                extProperty.data = new byte[WTExtensionsGlobal.WTExtensionPropertyImageMaxDataBytes];

                // Send image as an array of bytes.
                System.Buffer.BlockCopy(imageBytes, 0, extProperty.data, 0, (int)extProperty.extBase.dataSize);

                Marshal.StructureToPtr(extProperty, buf, false);

                retStatus = CWintabFuncs.WTExtSet((UInt32)context_I, (UInt32)extTagIndex_I, buf);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(retStatus);
        }
        /// <summary>
        /// Sets an extension control property image (if supported by tablet).
        /// </summary>
        /// <param name="context_I">wintab context</param>
        /// <param name="extTagIndex_I">which extension tag we're setting</param>
        /// <param name="tabletIndex_I">index of the tablet being set</param>
        /// <param name="controlIndex_I">the index of the control being set</param>
        /// <param name="functionIndex_I">the index of the control function being set</param>
        /// <param name="propertyID_I">ID of the property being set</param>
        /// <param name="value_I">value of the property being set (a string)</param>
        /// <returns>true if successful</returns>
        public static bool ControlPropertySetImage(
            HCTX context_I,
            byte extTagIndex_I,
            byte tabletIndex_I,
            byte controlIndex_I,
            byte functionIndex_I,
            ushort propertyID_I,
            String imageFilePath_I
            )
        {
            bool retStatus = false;
            WTExtensionImageProperty extProperty = new WTExtensionImageProperty();
            IntPtr buf = CMemUtils.AllocUnmanagedBuf(extProperty);

            try
            {
                byte[] imageBytes = null;
                System.Drawing.Image newImage = Image.FromFile(imageFilePath_I);

                if (newImage == null)
                {
                    MessageBox.Show("Oops - couldn't find/read image: " + imageFilePath_I);
                    return false;
                }

                using (MemoryStream ms = new MemoryStream())
                {
                    newImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    imageBytes = ms.ToArray();
                }

                extProperty.extBase.version = 0;
                extProperty.extBase.tabletIndex = tabletIndex_I;
                extProperty.extBase.controlIndex = controlIndex_I;
                extProperty.extBase.functionIndex = functionIndex_I;
                extProperty.extBase.propertyID = propertyID_I;
                extProperty.extBase.reserved = 0;
                extProperty.extBase.dataSize = (uint)imageBytes.Length;
                extProperty.data = new byte[WTExtensionsGlobal.WTExtensionPropertyImageMaxDataBytes];

                // Send image as an array of bytes.
                System.Buffer.BlockCopy(imageBytes, 0, extProperty.data, 0, (int)extProperty.extBase.dataSize);

                Marshal.StructureToPtr(extProperty, buf, false);

                retStatus = CWintabFuncs.WTExtSet((UInt32)context_I, (UInt32)extTagIndex_I, buf);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return retStatus;
        }