Hi all,
i have been doing r & d since past couple of days on this issue ( get image from clipboard in asp.net ) again. my client strictly wanted this functionality. Atlast i implemented an activx control using windows control library. where it has a richtextbox control and upload button. in richtextbox control(by default it suports text and image) we can paste images and text also . at first i got achieved this clipboard image using system dll's (user32.ddl etc). it worked fine in my localsystem, but not working in intranet or remote systems. it asking lot more permissions to run or execute this user control. so retrieved this image meta data from richtextbox and dynamically i converted it into image (gif format). then i uploaded this image data in byte[] format to webserver using webservice. in web server(where i hosted webapp) again i converted it into gif format and saving into webserver attachments folder. thats it its working fine now.
the below code gives the how to get image data from richtextbox control... if you need full code .. send me a mail to vrsanaidu@gmail.com... i cant write total code here.
If you got any better ideas after using this.. please share with me.
Private Sub FindMetafiles()
Dim BoxCopy As String
Dim n, m, StartCode, StartofImage, EndofImage As Long
Dim FoundBegin, FoundEnd As Boolean
Dim number As Int32 = 0
FoundBegin = False
FoundEnd = False
'Find the Pics and save them to Metafile array:
BoxCopy = RichTextBox1.Rtf
RichTextBox2.Text = RichTextBox1.Rtf()
For n = 0 To BoxCopy.Length - 7
'
If BoxCopy.Substring(n, 6) = "{\pict" Then
StartofImage = n
FoundBegin = True
End If
'
If FoundBegin = True Then
If BoxCopy.Substring(n, 1) = "}" Then
EndofImage = n - 2
'n = BoxCopy.Length
FoundEnd = True
End If
End If
'
'Execute the piece if the beginning({\pic) and the end (}) of the image is found
If FoundBegin = True And FoundEnd = True Then
FoundEnd = False
FoundBegin = False
number += 1
ReDim Preserve Pictures(number)
'
'Find beginning of Hex code of picture; this might give problems if the image properties are more than one line!!
StartCode = StartofImage
For m = StartofImage To StartofImage + 200 'max(?) of preferences of picture (e.g. \pichgoal)
If BoxCopy.Substring(m, 1).GetHashCode = 177583 Then
StartCode = m + 1
m = StartofImage + 200
End If
Next
'
'We now can cut off the hexcode to process it further
HexString = BoxCopy.Substring(StartCode, EndofImage - StartCode)
'
'We also need the properties of the image (\picxgoal...etc) so:
'Properties = BoxCopy.Substring(StartofImage, StartCode - StartofImage) & " " 'Add this extra spaces (>=10) as 'safety' zone so the
'
'Now try to extract the image sizes and mmtype:
If HexString.Substring(0, 6) = "{\pict" Then
HexString = HexString.Substring(6, HexString.Length - 6)
End If
If HexString.Substring(0, 10) = "\wmetafile" Then
HexString = HexString.Substring(11, HexString.Length - 11)
End If
If HexString.Substring(0, 5) = "\picw" Then
HexString = HexString.Substring(10, HexString.Length - 10)
End If
If HexString.Substring(0, 5) = "\pich" Then
HexString = HexString.Substring(10, HexString.Length - 10)
End If
If HexString.Substring(0, 9) = "\picwgoal" Then
HexString = HexString.Substring(14, HexString.Length - 14)
End If
If HexString.Substring(0, 9) = "\pichgoal" Then
HexString = HexString.Substring(14, HexString.Length - 14)
End If
RemoveCrLr()
CopyIntoBuffer()
End If
'
Next
End Sub
Sub CopyIntoBuffer()
Dim i As Long
Dim intArraySize As Long = CInt((Len(HexString) + 1) / 2) - 1
ReDim Buffer(intArraySize)
For i = 0 To intArraySize
Buffer(i) = "&H" & Mid(HexString, i * 2 + 1, 2)
Next i
HexString = Nothing
If (mStr_UserText = "") Then // i am passing this property value (Image) from my aspx page.
mStr_UserText = System.Guid.NewGuid().ToString()
End If
If (clipBoardGUID = "") Then
clipBoardGUID = System.Guid.NewGuid().ToString()
End If
MessageBox.Show("1")
Dim ms As New System.IO.MemoryStream(Buffer)
ms.Position = 0
clipService.PutImage(Buffer, clipBoardGUID)
HexString = String.Empty
MessageBox.Show("Successfully uploaded!.")
End Sub
Thanks & Regards
Naidu