?
Solved

Save Clipboard image to Sql Server Table

Posted on 2009-04-07
2
Medium Priority
?
375 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
[X]
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
2 Comments
 
LVL 15

Accepted Solution

by:
JackOfPH earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

771 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