Solved

Save Clipboard image to Sql Server Table

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

749 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