Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Save Clipboard image to Sql Server Table

Posted on 2009-04-07
2
362 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

829 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