Solved

Save Clipboard image to Sql Server Table

Posted on 2009-04-07
2
352 Views
Last Modified: 2012-05-06
I copy a chart from Excel to the clipboard and now want to save to a table. Problem is changing the format. I'm trying to save to two different formats to see if it makes a difference. col DImage is a varbinary(max) type and XChart is image type. Just testing to see what works. When I try to copy the image to either field I get an error trying to copy to a byte type.  Does someone have a code example to convert the clipboard image to the right type?

Using VB.net 2005 with sql server 2005.

oChart.CopyPicture(Appearance:=Excel.XlPictureAppearance.xlScreen, Size:=Excel.XlPictureAppearance.xlScreen, Format:=Excel.XlCopyPictureFormat.xlBitmap)
 
                        Dim ClipImage As System.Drawing.Image
                        If My.Computer.Clipboard.ContainsImage() Then
                            ClipImage = My.Computer.Clipboard.GetImage
 
                        Else
                            MsgBox("No Images in ClipBoard")
                        End If
               
                        Dim row As DataRow
                        Dim intRCnt As Integer
                        intRCnt = 0
                        For Each row In dtDODICImages.Rows
                            If dtDImages.Rows(intRCnt).Item("DCD") = strDCD Then
                                dtDImages.Rows(intRCnt).Item("DImage") = ClipImage
                                dtDImages.Rows(intRCnt).Item("XChart") = ClipImage
                                Exit For
                            End If
                            intRCnt += 1
                        Next row

Open in new window

0
Comment
Question by:MadIce
2 Comments
 
LVL 15

Accepted Solution

by:
JackOfPH earned 500 total points
ID: 24256984
Try this Function...

Private Function ConvertImageToByte(Byval ClipImage as  System.Drawing.Image) as Byte

 Dim ms As New System.IO.MemoryStream
 ClipImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
 ms.Seek(0, IO.SeekOrigin.Begin)
 Dim data(ms.Length - 1) As Byte
 ms.Read(data, 0, ms.Length)
 ms.Close()
 
Return data

End Function


'Usage...

ClipImage = ConvertImageToByte(My.Computer.Clipboard.GetImage)

0
 

Author Closing Comment

by:MadIce
ID: 31567651
I thought I closed this. sorry for the delay. I didn't use exactly what you  put but it help me solve the issue. Thanks
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question