Solved

Save Clipboard image to Sql Server Table

Posted on 2009-04-07
2
344 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now