473,324 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Bitmap from Clipboard back to Clipboard as PNG?

Hello -

I have the following code to get a bitmap from the clipboard and to
save it to a *.png file ...

Dim lData As IDataObject = Clipboard.GetDataObject()

If lData.GetDataPresent(DataFormats.Bitmap) Then
Dim lPictureBox As New PictureBox

lPictureBox.Image = lData.GetData(DataFormats.Bitmap,
True)
lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
End If

How can I take the Image and put it back onto the Clipboard as a Png?
I found the Clipboard.SetDataObject() function but how can I use the
PictureBox or Image to convert it into a format that can be used by
SetDataObject()?

Thanks!
Joe

Jun 27 '08 #1
20 6940
On Jun 5, 4:00*pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -

I have the following code to get a bitmap from the clipboard and to
save it to a *.png file ...

* * * * Dim lData As IDataObject = Clipboard.GetDataObject()

* * * * If lData.GetDataPresent(DataFormats.Bitmap) Then
* * * * * * Dim lPictureBox As New PictureBox

* * * * * * lPictureBox.Image = lData.GetData(DataFormats.Bitmap,
True)
* * * * * * lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
* * * * End If

How can I take the Image and put it back onto the Clipboard as a Png?
I found the Clipboard.SetDataObject() function but how can I use the
PictureBox or Image to convert it into a format that can be used by
SetDataObject()?

Thanks!
Joe
To retrieve image from clipboard, have you considered using:

' Assuming your picturebox's name is "lPictureBox"
lPictureBox.Image = Clipboard.GetImage

' Save now in PNG format
lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)

.... and

' To add image to clipboard
Clipboard.SetImage(lPictureBox.Image)
Thanks,

Onur Güzel
Jun 27 '08 #2
Hello -

I have .NET 1.1 and Visual Studio 2003 and there is no GetImage and
SetImage function of Clipboard.

Thanks,
Joe

On Jun 5, 9:24*am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 4:00*pm, Joe Duchtel <duch...@gmail.comwrote:


Hello -
I have the following code to get a bitmap from the clipboard and to
save it to a *.png file ...
* * * * Dim lData As IDataObject = Clipboard.GetDataObject()
* * * * If lData.GetDataPresent(DataFormats.Bitmap) Then
* * * * * * Dim lPictureBox As New PictureBox
* * * * * * lPictureBox.Image = lData.GetData(DataFormats.Bitmap,
True)
* * * * * * lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
* * * * End If
How can I take the Image and put it back onto the Clipboard as a Png?
I found the Clipboard.SetDataObject() function but how can I use the
PictureBox or Image to convert it into a format that can be used by
SetDataObject()?
Thanks!
Joe

To retrieve image from clipboard, have you considered using:

' Assuming your picturebox's name is "lPictureBox"
lPictureBox.Image = Clipboard.GetImage

' Save now in PNG format
lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)

.... and

' To add image to clipboard
Clipboard.SetImage(lPictureBox.Image)

Thanks,

Onur Güzel- Hide quoted text -

- Show quoted text -
Jun 27 '08 #3
On Jun 5, 5:18 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -

I have .NET 1.1 and Visual Studio 2003 and there is no GetImage and
SetImage function of Clipboard.

Thanks,
Joe

On Jun 5, 9:24 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 4:00 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -
I have the following code to get a bitmap from the clipboard and to
save it to a *.png file ...
Dim lData As IDataObject = Clipboard.GetDataObject()
If lData.GetDataPresent(DataFormats.Bitmap) Then
Dim lPictureBox As New PictureBox
lPictureBox.Image = lData.GetData(DataFormats.Bitmap,
True)
lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
End If
How can I take the Image and put it back onto the Clipboard as a Png?
I found the Clipboard.SetDataObject() function but how can I use the
PictureBox or Image to convert it into a format that can be used by
SetDataObject()?
Thanks!
Joe
To retrieve image from clipboard, have you considered using:
' Assuming your picturebox's name is "lPictureBox"
lPictureBox.Image = Clipboard.GetImage
' Save now in PNG format
lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
.... and
' To add image to clipboard
Clipboard.SetImage(lPictureBox.Image)
Thanks,
Onur Güzel- Hide quoted text -
- Show quoted text -
Sorry, there are in .NET 2.0. I don't know if they're not present in
VS 2003 / .NET 1.1

So try this to copy image to clipboard as you say SetDataObject exists
in .NET 1.1:

Dim myimage As Object = lPictureBox.Image
Clipboard.SetDataObject(myimage)

Thanks,

Onur Güzel
Jun 27 '08 #4
Hello -

The snipped you gave me will compile and run but the Clipboard tells
me that the "ClipBook Viewer cannot display the information in its
current format or there is not enough memory ...". I cannot paste it
into anything either.

I think that the Image is in some raw format that needs to be
converted to a *.png. It works with the Image.Save but I have found
no other way to convert the format.

Thanks,
Joe

On Jun 5, 10:43*am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 5:18 pm, Joe Duchtel <duch...@gmail.comwrote:


Hello -
I have .NET 1.1 and Visual Studio 2003 and there is no GetImage and
SetImage function of Clipboard.
Thanks,
Joe
On Jun 5, 9:24 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 4:00 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -
I have the following code to get a bitmap from the clipboard and to
save it to a *.png file ...
* * * * Dim lData As IDataObject = Clipboard.GetDataObject()
* * * * If lData.GetDataPresent(DataFormats.Bitmap) Then
* * * * * * Dim lPictureBox As New PictureBox
* * * * * * lPictureBox.Image = lData.GetData(DataFormats.Bitmap,
True)
* * * * * * lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
* * * * End If
How can I take the Image and put it back onto the Clipboard as a Png?
I found the Clipboard.SetDataObject() function but how can I use the
PictureBox or Image to convert it into a format that can be used by
SetDataObject()?
Thanks!
Joe
To retrieve image from clipboard, have you considered using:
' Assuming your picturebox's name is "lPictureBox"
lPictureBox.Image = Clipboard.GetImage
' Save now in PNG format
lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
.... and
' To add image to clipboard
Clipboard.SetImage(lPictureBox.Image)
Thanks,
Onur Güzel- Hide quoted text -
- Show quoted text -

Sorry, there are in .NET 2.0. I don't know if they're not present in
VS 2003 / .NET 1.1

So try this to copy image to clipboard as you say SetDataObject exists
in .NET 1.1:

Dim myimage As Object = lPictureBox.Image
Clipboard.SetDataObject(myimage)

Thanks,

Onur Güzel- Hide quoted text -

- Show quoted text -
Jun 27 '08 #5
On Jun 5, 5:59 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -

The snipped you gave me will compile and run but the Clipboard tells
me that the "ClipBook Viewer cannot display the information in its
current format or there is not enough memory ...". I cannot paste it
into anything either.

I think that the Image is in some raw format that needs to be
converted to a *.png. It works with the Image.Save but I have found
no other way to convert the format.

Thanks,
Joe

On Jun 5, 10:43 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 5:18 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -
I have .NET 1.1 and Visual Studio 2003 and there is no GetImage and
SetImage function of Clipboard.
Thanks,
Joe
On Jun 5, 9:24 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 4:00 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -
I have the following code to get a bitmap from the clipboard and to
save it to a *.png file ...
Dim lData As IDataObject = Clipboard.GetDataObject()
If lData.GetDataPresent(DataFormats.Bitmap) Then
Dim lPictureBox As New PictureBox
lPictureBox.Image = lData.GetData(DataFormats.Bitmap,
True)
lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
End If
How can I take the Image and put it back onto the Clipboard as a Png?
I found the Clipboard.SetDataObject() function but how can I use the
PictureBox or Image to convert it into a format that can be used by
SetDataObject()?
Thanks!
Joe
To retrieve image from clipboard, have you considered using:
' Assuming your picturebox's name is "lPictureBox"
lPictureBox.Image = Clipboard.GetImage
' Save now in PNG format
lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
.... and
' To add image to clipboard
Clipboard.SetImage(lPictureBox.Image)
Thanks,
Onur Güzel- Hide quoted text -
- Show quoted text -
Sorry, there are in .NET 2.0. I don't know if they're not present in
VS 2003 / .NET 1.1
So try this to copy image to clipboard as you say SetDataObject exists
in .NET 1.1:
Dim myimage As Object = lPictureBox.Image
Clipboard.SetDataObject(myimage)
Thanks,
Onur Güzel- Hide quoted text -
- Show quoted text -
Hi,
With the code i posted using SetDataObject, i ran it for once or more
it worked. Then it gave error when i try to paste onto Paint, after re-
creating project or changing picturebox name or re-launching
application it worked and image pasted to Paint with NO problem.

Anyway, SetImage method in .NET 2.0 never did this behaviour. So i
cannot say a certain thing on the issue and you may consider upgrading
to 2.0 at least.

Thanks,

Onur Güzel
Jun 27 '08 #6
On Jun 5, 5:59 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -

The snipped you gave me will compile and run but the Clipboard tells
me that the "ClipBook Viewer cannot display the information in its
current format or there is not enough memory ...". I cannot paste it
into anything either.

I think that the Image is in some raw format that needs to be
converted to a *.png. It works with the Image.Save but I have found
no other way to convert the format.

Thanks,
Joe

On Jun 5, 10:43 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 5:18 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -
I have .NET 1.1 and Visual Studio 2003 and there is no GetImage and
SetImage function of Clipboard.
Thanks,
Joe
On Jun 5, 9:24 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 4:00 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -
I have the following code to get a bitmap from the clipboard and to
save it to a *.png file ...
Dim lData As IDataObject = Clipboard.GetDataObject()
If lData.GetDataPresent(DataFormats.Bitmap) Then
Dim lPictureBox As New PictureBox
lPictureBox.Image = lData.GetData(DataFormats.Bitmap,
True)
lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
End If
How can I take the Image and put it back onto the Clipboard as a Png?
I found the Clipboard.SetDataObject() function but how can I use the
PictureBox or Image to convert it into a format that can be used by
SetDataObject()?
Thanks!
Joe
To retrieve image from clipboard, have you considered using:
' Assuming your picturebox's name is "lPictureBox"
lPictureBox.Image = Clipboard.GetImage
' Save now in PNG format
lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
.... and
' To add image to clipboard
Clipboard.SetImage(lPictureBox.Image)
Thanks,
Onur Güzel- Hide quoted text -
- Show quoted text -
Sorry, there are in .NET 2.0. I don't know if they're not present in
VS 2003 / .NET 1.1
So try this to copy image to clipboard as you say SetDataObject exists
in .NET 1.1:
Dim myimage As Object = lPictureBox.Image
Clipboard.SetDataObject(myimage)
Thanks,
Onur Güzel- Hide quoted text -
- Show quoted text -
.. or you can simply try to use:

Clipboard.SetDataObject(lPictureBox.Image)

...and see if it does not result with errors anylonger.

Hope this helps,

Onur Güzel
Jun 27 '08 #7
Hello -

I actually did try the Clipboard.SetDataObject(lPictureBox.Image)
without using an Object and it is still not working.

Thanks,
Joe

On Jun 5, 11:19*am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 5:59 pm, Joe Duchtel <duch...@gmail.comwrote:


Hello -
The snipped you gave me will compile and run but the Clipboard tells
me that the "ClipBook Viewer cannot display the information in its
current format or there is not enough memory ...". *I cannot paste it
into anything either.
I think that the Image is in some raw format that needs to be
converted to a *.png. *It works with the Image.Save but I have found
no other way to convert the format.
Thanks,
Joe
On Jun 5, 10:43 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 5:18 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -
I have .NET 1.1 and Visual Studio 2003 and there is no GetImage and
SetImage function of Clipboard.
Thanks,
Joe
On Jun 5, 9:24 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 4:00 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -
I have the following code to get a bitmap from the clipboard andto
save it to a *.png file ...
* * * * Dim lData As IDataObject = Clipboard.GetDataObject()
* * * * If lData.GetDataPresent(DataFormats.Bitmap) Then
* * * * * * Dim lPictureBox As New PictureBox
* * * * * * lPictureBox.Image = lData.GetData(DataFormats.Bitmap,
True)
* * * * * * lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
* * * * End If
How can I take the Image and put it back onto the Clipboard as aPng?
I found the Clipboard.SetDataObject() function but how can I usethe
PictureBox or Image to convert it into a format that can be usedby
SetDataObject()?
Thanks!
Joe
To retrieve image from clipboard, have you considered using:
' Assuming your picturebox's name is "lPictureBox"
lPictureBox.Image = Clipboard.GetImage
' Save now in PNG format
lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
.... and
' To add image to clipboard
Clipboard.SetImage(lPictureBox.Image)
Thanks,
Onur Güzel- Hide quoted text -
- Show quoted text -
Sorry, there are in .NET 2.0. I don't know if they're not present in
VS 2003 / .NET 1.1
So try this to copy image to clipboard as you say SetDataObject exists
in .NET 1.1:
Dim myimage As Object = lPictureBox.Image
Clipboard.SetDataObject(myimage)
Thanks,
Onur Güzel- Hide quoted text -
- Show quoted text -

.. or you can simply try to use:

*Clipboard.SetDataObject(lPictureBox.Image)

...and see if it does not result with errors anylonger.

Hope this helps,

Onur Güzel- Hide quoted text -

- Show quoted text -
Jun 27 '08 #8
On Jun 5, 8:02 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -

I actually did try the Clipboard.SetDataObject(lPictureBox.Image)
without using an Object and it is still not working.

Thanks,
Joe

On Jun 5, 11:19 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 5:59 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -
The snipped you gave me will compile and run but the Clipboard tells
me that the "ClipBook Viewer cannot display the information in its
current format or there is not enough memory ...". I cannot paste it
into anything either.
I think that the Image is in some raw format that needs to be
converted to a *.png. It works with the Image.Save but I have found
no other way to convert the format.
Thanks,
Joe
On Jun 5, 10:43 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 5:18 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -
I have .NET 1.1 and Visual Studio 2003 and there is no GetImage and
SetImage function of Clipboard.
Thanks,
Joe
On Jun 5, 9:24 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 4:00 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -
I have the following code to get a bitmap from the clipboard and to
save it to a *.png file ...
Dim lData As IDataObject = Clipboard.GetDataObject()
If lData.GetDataPresent(DataFormats.Bitmap) Then
Dim lPictureBox As New PictureBox
lPictureBox.Image = lData.GetData(DataFormats.Bitmap,
True)
lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
End If
How can I take the Image and put it back onto the Clipboard asa Png?
I found the Clipboard.SetDataObject() function but how can I use the
PictureBox or Image to convert it into a format that can be used by
SetDataObject()?
Thanks!
Joe
To retrieve image from clipboard, have you considered using:
' Assuming your picturebox's name is "lPictureBox"
lPictureBox.Image = Clipboard.GetImage
' Save now in PNG format
lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
.... and
' To add image to clipboard
Clipboard.SetImage(lPictureBox.Image)
Thanks,
Onur Güzel- Hide quoted text -
- Show quoted text -
Sorry, there are in .NET 2.0. I don't know if they're not present in
VS 2003 / .NET 1.1
So try this to copy image to clipboard as you say SetDataObject exists
in .NET 1.1:
Dim myimage As Object = lPictureBox.Image
Clipboard.SetDataObject(myimage)
Thanks,
Onur Güzel- Hide quoted text -
- Show quoted text -
.. or you can simply try to use:
Clipboard.SetDataObject(lPictureBox.Image)
...and see if it does not result with errors anylonger.
Hope this helps,
Onur Güzel- Hide quoted text -
- Show quoted text -
Which step is not working? Pasting to somewhere?

I was able to paste a image to Clipboard Viewer and mspaint (Paint)
after copying image to the clipboard.
Clipboard.SetDataObject(lPictureBox.Image) and make sure your
picturebox has a picture that'll be copied to the clipboard as well.

Thanks,

Onur Güzel
Jun 27 '08 #9
Hello -

I use the Clipboard.SetDataObject(lPictureBox.Image) and get an "Error
getting the Clipboard Data!" when I try to paste it into Paint.

I also used the debugger to make sure that the lPictureBox.Image is
not Nothing and contains something.

Thanks,
Joachim

On Jun 5, 1:54*pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 8:02 pm, Joe Duchtel <duch...@gmail.comwrote:


Hello -
I actually did try the Clipboard.SetDataObject(lPictureBox.Image)
without using an Object and it is still not working.
Thanks,
Joe
On Jun 5, 11:19 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 5:59 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -
The snipped you gave me will compile and run but the Clipboard tells
me that the "ClipBook Viewer cannot display the information in its
current format or there is not enough memory ...". *I cannot pasteit
into anything either.
I think that the Image is in some raw format that needs to be
converted to a *.png. *It works with the Image.Save but I have found
no other way to convert the format.
Thanks,
Joe
On Jun 5, 10:43 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 5:18 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -
I have .NET 1.1 and Visual Studio 2003 and there is no GetImage and
SetImage function of Clipboard.
Thanks,
Joe
On Jun 5, 9:24 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 5, 4:00 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -
I have the following code to get a bitmap from the clipboardand to
save it to a *.png file ...
* * * * Dim lData As IDataObject = Clipboard.GetDataObject()
* * * * If lData.GetDataPresent(DataFormats.Bitmap) Then
* * * * * * Dim lPictureBox As New PictureBox
* * * * * * lPictureBox.Image = lData.GetData(DataFormats.Bitmap,
True)
* * * * * * lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
* * * * End If
How can I take the Image and put it back onto the Clipboard as a Png?
I found the Clipboard.SetDataObject() function but how can Iuse the
PictureBox or Image to convert it into a format that can be used by
SetDataObject()?
Thanks!
Joe
To retrieve image from clipboard, have you considered using:
' Assuming your picturebox's name is "lPictureBox"
lPictureBox.Image = Clipboard.GetImage
' Save now in PNG format
lPictureBox.Image.Save("Test.png",
System.Drawing.Imaging.ImageFormat.Png)
.... and
' To add image to clipboard
Clipboard.SetImage(lPictureBox.Image)
Thanks,
Onur Güzel- Hide quoted text -
- Show quoted text -
Sorry, there are in .NET 2.0. I don't know if they're not present in
VS 2003 / .NET 1.1
So try this to copy image to clipboard as you say SetDataObject exists
in .NET 1.1:
Dim myimage As Object = lPictureBox.Image
Clipboard.SetDataObject(myimage)
Thanks,
Onur Güzel- Hide quoted text -
- Show quoted text -
.. or you can simply try to use:
*Clipboard.SetDataObject(lPictureBox.Image)
...and see if it does not result with errors anylonger.
Hope this helps,
Onur Güzel- Hide quoted text -
- Show quoted text -

Which step is not working? Pasting to somewhere?

I was able to paste a image to Clipboard Viewer and mspaint (Paint)
after copying image to the clipboard.
Clipboard.SetDataObject(lPictureBox.Image) and make sure your
picturebox has a picture that'll be copied to the clipboard as well.

Thanks,

Onur Güzel- Hide quoted text -

- Show quoted text -
Jun 27 '08 #10
How can I take the Image and put it back onto the Clipboard as a Png?

1) Create a MemoryStream object
2) Save your image to the stream encoded as a Png
Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
3) Create a new DataObject
4) Use SetData("PNG", false, ms) to embed the encoded png memory stream into
the dataObject
5) Use Clipboard.SetDataObject(dataObject, false) to place the dataObject on
the clipboard
Jun 27 '08 #11
Hello -

Thanks a lot for your feedback!

I tried the following ...

Dim lMemoryStream As New MemoryStream

lImage.Save(lMemoryStream,
System.Drawing.Imaging.ImageFormat.Png)

Dim lDataObject As New DataObject

lDataObject.SetData("PNG", False, lMemoryStream)

Clipboard.SetDataObject(lDataObject)

... but I still get the "ClipBook Viewer cannot display the
information in its current format ..." message and cannot past
anything into Paint or Word.

The lImage.Save() to a file works just fine ...

Thanks!
Joe

On Jun 5, 2:54*pm, "Michael Phillips, Jr."
<mphillip...@nospam.jun0.c0mwrote:
How can I take the Image and put it back onto the Clipboard as a Png?

1) Create a MemoryStream object
2) Save your image to the stream encoded as a Png
* * Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
3) Create a new DataObject
4) Use SetData("PNG", false, ms) to embed the encoded png memory stream into
the dataObject
5) Use Clipboard.SetDataObject(dataObject, false) to place the dataObject on
the clipboard
Jun 27 '08 #12
>... but I still get the "ClipBook Viewer cannot display the
>information in its current format ..." message and cannot past
anything into Paint or Word.
The Windows ClipBook Viewer is old. It was never updated to recognize the
"PNG" format.

MSPaint does not recognize the "PNG" format either.

However, Microsoft Office 2007 does recognize the "PNG" format.

You must select "Paste Special" on the menu. You will then be presented
with a "Paste Special" dialog box will show all of the formats presented on
the clipboard. Your "PNG" image will be available on the clipboard. Once
selected, it will appear in the document.
"Joe Duchtel" <du*****@gmail.comwrote in message
news:e2**********************************@27g2000h sf.googlegroups.com...
Hello -

Thanks a lot for your feedback!

I tried the following ...

Dim lMemoryStream As New MemoryStream

lImage.Save(lMemoryStream,
System.Drawing.Imaging.ImageFormat.Png)

Dim lDataObject As New DataObject

lDataObject.SetData("PNG", False, lMemoryStream)

Clipboard.SetDataObject(lDataObject)

.... but I still get the "ClipBook Viewer cannot display the
information in its current format ..." message and cannot past
anything into Paint or Word.

The lImage.Save() to a file works just fine ...

Thanks!
Joe

On Jun 5, 2:54 pm, "Michael Phillips, Jr."
<mphillip...@nospam.jun0.c0mwrote:
How can I take the Image and put it back onto the Clipboard as a Png?

1) Create a MemoryStream object
2) Save your image to the stream encoded as a Png
Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
3) Create a new DataObject
4) Use SetData("PNG", false, ms) to embed the encoded png memory stream
into
the dataObject
5) Use Clipboard.SetDataObject(dataObject, false) to place the dataObject
on
the clipboard

Jun 27 '08 #13
Hello -

Okay ... so the code might have done the right thing all along but I
did not paste it into an application that would accept this format.

I just tried the following to see whether I could put a bitmap back
onto the Clipboard and it still would not let me paste it into
anything ...

Dim lMemoryStream As New MemoryStream
lImage.Save(lMemoryStream,
System.Drawing.Imaging.ImageFormat.Bmp)
Dim lDataObject As New DataObject
lDataObject.SetData("BMP", False, lMemoryStream)
Clipboard.SetDataObject(lDataObject)

Thanks,
Joe

On Jun 6, 9:07*am, "Michael Phillips, Jr."
<mphillip...@nospam.jun0.c0mwrote:
... but I still get the "ClipBook Viewer cannot display the
information in its current format ..." message and cannot past
anything into Paint or Word.

The Windows ClipBook Viewer is old. *It was never updated to recognize the
"PNG" format.

MSPaint does not recognize the "PNG" format either.

However, Microsoft Office 2007 does recognize the "PNG" format.

You must select "Paste Special" on the menu. *You will then be presented
with a "Paste Special" dialog box will show all of the formats presented on
the clipboard. *Your "PNG" image will be available on the clipboard. *Once
selected, it will appear in the document.

"Joe Duchtel" <duch...@gmail.comwrote in message

news:e2**********************************@27g2000h sf.googlegroups.com...
Hello -

Thanks a lot for your feedback!

I tried the following ...

* * * * * * * * Dim lMemoryStream As New MemoryStream

* * * * * * * * lImage.Save(lMemoryStream,
System.Drawing.Imaging.ImageFormat.Png)

* * * * * * * * Dim lDataObject As New DataObject

* * * * * * * * lDataObject.SetData("PNG", False, lMemoryStream)

* * * * * * * * Clipboard.SetDataObject(lDataObject)

... but I still get the "ClipBook Viewer cannot display the
information in its current format ..." message and cannot past
anything into Paint or Word.

The lImage.Save() to a file works just fine ...

Thanks!
Joe

On Jun 5, 2:54 pm, "Michael Phillips, Jr."

<mphillip...@nospam.jun0.c0mwrote:
How can I take the Image and put it back onto the Clipboard as a Png?
1) Create a MemoryStream object
2) Save your image to the stream encoded as a Png
Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
3) Create a new DataObject
4) Use SetData("PNG", false, ms) to embed the encoded png memory stream
into
the dataObject
5) Use Clipboard.SetDataObject(dataObject, false) to place the dataObject
on
the clipboard- Hide quoted text -

- Show quoted text -
Jun 27 '08 #14
On Jun 6, 7:19 pm, Joe Duchtel <duch...@gmail.comwrote:
Hello -

Okay ... so the code might have done the right thing all along but I
did not paste it into an application that would accept this format.

I just tried the following to see whether I could put a bitmap back
onto the Clipboard and it still would not let me paste it into
anything ...

Dim lMemoryStream As New MemoryStream
lImage.Save(lMemoryStream,
System.Drawing.Imaging.ImageFormat.Bmp)
Dim lDataObject As New DataObject
lDataObject.SetData("BMP", False, lMemoryStream)
Clipboard.SetDataObject(lDataObject)

Thanks,
Joe

On Jun 6, 9:07 am, "Michael Phillips, Jr."

<mphillip...@nospam.jun0.c0mwrote:
>... but I still get the "ClipBook Viewer cannot display the
>information in its current format ..." message and cannot past
anything into Paint or Word.
The Windows ClipBook Viewer is old. It was never updated to recognize the
"PNG" format.
MSPaint does not recognize the "PNG" format either.
However, Microsoft Office 2007 does recognize the "PNG" format.
You must select "Paste Special" on the menu. You will then be presented
with a "Paste Special" dialog box will show all of the formats presentedon
the clipboard. Your "PNG" image will be available on the clipboard. Once
selected, it will appear in the document.
"Joe Duchtel" <duch...@gmail.comwrote in message
news:e2**********************************@27g2000h sf.googlegroups.com...
Hello -
Thanks a lot for your feedback!
I tried the following ...
Dim lMemoryStream As New MemoryStream
lImage.Save(lMemoryStream,
System.Drawing.Imaging.ImageFormat.Png)
Dim lDataObject As New DataObject
lDataObject.SetData("PNG", False, lMemoryStream)
Clipboard.SetDataObject(lDataObject)
... but I still get the "ClipBook Viewer cannot display the
information in its current format ..." message and cannot past
anything into Paint or Word.
The lImage.Save() to a file works just fine ...
Thanks!
Joe
On Jun 5, 2:54 pm, "Michael Phillips, Jr."
<mphillip...@nospam.jun0.c0mwrote:
How can I take the Image and put it back onto the Clipboard as a Png?
1) Create a MemoryStream object
2) Save your image to the stream encoded as a Png
Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
3) Create a new DataObject
4) Use SetData("PNG", false, ms) to embed the encoded png memory stream
into
the dataObject
5) Use Clipboard.SetDataObject(dataObject, false) to place the dataObject
on
the clipboard- Hide quoted text -
- Show quoted text -
Joe,
I still recomended using SetImage, GetImage methods which are provided
in .NET 2.0. I sometimes, not always, had errors while pasting PNG or
other images (no matter even with JPG) which are copied to clipboard
using SetDataObject, but it seems Clipboard.SetImage method in 2.0
seems much more stable choice.

Thanks,

Onur Güzel
Jun 27 '08 #15
Okay ... so the code might have done the right thing all along but I
did not paste it into an application that would accept this format.
I just tried the following to see whether I could put a bitmap back
onto the Clipboard and it still would not let me paste it into
anything ...
Dim lMemoryStream As New MemoryStream
lImage.Save(lMemoryStream,
System.Drawing.Imaging.ImageFormat.Bmp)
Dim lDataObject As New DataObject
lDataObject.SetData("BMP", False, lMemoryStream)
Clipboard.SetDataObject(lDataObject)
The above code is not correct!

It should be lDataObject.SetData("DeviceIndependentBitmap", False,
lMemoryStream) but only after you construct the memory stream correctly.

Your lMemoryStream looks like the following in memory:
1) BITMAPFILEHEADER----14 bytes.
2) BITMAPINFOHEADER---40 bytes
3) Color Palette or Bitfields array depending upon the depth of the
bitmap(i.e., 1bpp - 16bpp)
The size in bytes varies from 8 to 1024 bytes.
If your bitmap is 32bpp or PixelFormat16bppRGB555, then no color palette of
bitfield array is necessary.
4) The bitmap's pixels.
For some bitmaps this position in the stream may be aligned on a 32 bit
boundary so it is necessary to parse the BITMAPFILEHEADER for the exact
offset.

The correct format of the MemoryStream for a "DeviceIndependentBitmap"
should look like the following:
1) BITMAPINFOHEADER
2) Color Palette or Bitfields array depending upon the depth of the bitmap
3) The bitmap's pixels.

To correct your code, you need to create a second MemoryStream object and
copy the BITMAPINFOHEADER, Color Palette or Bitfields array, if present, and
the bitmap's pixels from the first stream to the second stream and then
rewind the stream to position 0.

The memory layout must be packed with Color Palette or Bitfields array
depending upon the depth of the bitmap and the bitmap's pixels directly
following the BITMAPINFOHEADER. This requires that you parse the
BITMAPFILEHEADER to get the exact offset of the bitmap's bits.



Jun 27 '08 #16
Hello -

I just used the code as a sample of how I thought I could put the
bitmap back onto the Clipboard. I actually want it to be pasted as a
PNG. Do I have to do something similar to what you outlined below for
that? I assume that the "DeviceIndependentBitmap" would not work?

I guess I did not realize that I had to construct the memory stream
myself. I thought that since I can use the Image.Save() to save a
*.png to a file, I should somehow be able to put that back onto the
Clipboard.

So I assume that based on your feedback, the following is also
incorrect?

Dim lMemoryStream As New MemoryStream
lImage.Save(lMemoryStream, System.Drawing.Imaging.ImageFormat.Png)
Dim lDataObject As New DataObject
lDataObject.SetData("PNG", False, lMemoryStream)
Clipboard.SetDataObject(lDataObject)

I really thought this was going to be a lot easier ;) ...

Thanks a lot!
Joe

On Jun 6, 2:45*pm, "Michael Phillips, Jr."
<mphillip...@nospam.jun0.c0mwrote:
Okay ... so the code might have done the right thing all along but I
did not paste it into an application that would accept this format.
I just tried the following to see whether I could put a bitmap back
onto the Clipboard and it still would not let me paste it into
anything ...
* * * * * * * *Dim lMemoryStream As New MemoryStream
* * * * * * * *lImage.Save(lMemoryStream,
System.Drawing.Imaging.ImageFormat.Bmp)
* * * * * * * * Dim lDataObject As New DataObject
* * * * * * * *lDataObject.SetData("BMP", False, lMemoryStream)
* * * * * * * *Clipboard.SetDataObject(lDataObject)

The above code is not correct!

It should be lDataObject.SetData("DeviceIndependentBitmap", False,
lMemoryStream) but only after you construct the memory stream correctly.

Your *lMemoryStream looks like the following in memory:
1) BITMAPFILEHEADER----14 bytes.
2) BITMAPINFOHEADER---40 bytes
3) Color Palette or Bitfields array depending upon the depth of the
bitmap(i.e., 1bpp - 16bpp)
The size in bytes varies from 8 to 1024 bytes.
If your bitmap is 32bpp or PixelFormat16bppRGB555, then no color palette of
bitfield array is necessary.
4) The bitmap's pixels.
For some bitmaps this position in the stream may be aligned on a 32 bit
boundary so it is necessary to parse the BITMAPFILEHEADER for the exact
offset.

The correct format of the MemoryStream for a "DeviceIndependentBitmap"
should look like the following:
1) BITMAPINFOHEADER
2) Color Palette or Bitfields array depending upon the depth of the bitmap
3) The bitmap's pixels.

To correct your code, you need to create a second MemoryStream object and
copy the BITMAPINFOHEADER, Color Palette or Bitfields array, if present, and
the bitmap's pixels from the first stream to the second stream and then
rewind the stream to position 0.

The memory layout must be packed with Color Palette or Bitfields array
depending upon the depth of the bitmap and the bitmap's pixels directly
following the BITMAPINFOHEADER. *This requires that you parse the
BITMAPFILEHEADER to get the exact offset of the bitmap's bits.
Jun 27 '08 #17
So I assume that based on your feedback, the following is also
incorrect?
Dim lMemoryStream As New MemoryStream
lImage.Save(lMemoryStream, System.Drawing.Imaging.ImageFormat.Png)
Dim lDataObject As New DataObject
lDataObject.SetData("PNG", False, lMemoryStream)
Clipboard.SetDataObject(lDataObject)
The above code is correct. One way to test is to open an empty Word
document and use "Paste Special" from the menu.

The "PNG" clipboard format will appear in the dialog box.

You cannot force an application to support the "PNG" format. The
application may only support bitmaps, metafiles or private image formats.

The Windows clipboook viewer will also show that the "PNG" format is on the
clipboard albeit the format is grayed out.
Jun 27 '08 #18
Hello -

The Edit Paste and Edit Paste Special... menu entries are grayed
out when I run the code. I even tried to use the Tiff format since I
could find it under DataFormats ...

Dim lData As DataObject = Clipboard.GetDataObject()
...
Dim lImage As Image = lData.GetData(DataFormats.Bitmap,
False)
...

Dim lMemoryStream As New MemoryStream
lImage.Save(lMemoryStream,
System.Drawing.Imaging.ImageFormat.Tiff)
Dim lDataObject As New DataObject
lDataObject.SetData(DataFormats.Tiff, False,
lMemoryStream)
Clipboard.SetDataObject(lDataObject)

Still not working ...

Thanks!
Joe


On Jun 7, 9:40*am, "Michael Phillips, Jr."
<mphillip...@nospam.jun0.c0mwrote:
So I assume that based on your feedback, the following is also
incorrect?
Dim lMemoryStream As New MemoryStream
lImage.Save(lMemoryStream, *System.Drawing.Imaging.ImageFormat.Png)
Dim lDataObject As New DataObject
lDataObject.SetData("PNG", False, lMemoryStream)
Clipboard.SetDataObject(lDataObject)

The above code is correct. *One way to test is to open an empty Word
document and use "Paste Special" from the menu.

The "PNG" clipboard format will appear in the dialog box.

You cannot force an application to support the "PNG" format. *The
application may only support bitmaps, metafiles or private image formats.

The Windows clipboook viewer will also show that the "PNG" format is on the
clipboard albeit the format is grayed out.
Jun 27 '08 #19
The Edit Paste and Edit Paste Special... menu entries are grayed
out when I run the code.
What application(i.e., name and version) are you using for the test?

The "PNG" format will paste into any Office 2007 document with "Paste
Special".

I do not have any other version of Microsoft Office to test with.


Jun 27 '08 #20
Dim lMemoryStream As New MemoryStream
lImage.Save(lMemoryStream,
System.Drawing.Imaging.ImageFormat.Tiff)
Dim lDataObject As New DataObject
'rewind the stream to position 0
lDataObject.SetData("TIFF", False, lMemoryStream)
Clipboard.SetDataObject(lDataObject)

The above code works, if you make the change that I indicated.

In all cases(i.e., "PNG", "TIFF"), you must rewind the stream to position 0
before placing the stream in the DataObject.


Jun 27 '08 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: BC | last post by:
Hello, We are creating an Office add-in. We are able to display the add-in successfully. However, we followed a sample program, and it displays a FaceID = 1044 (which is not the bitmap of the...
2
by: John | last post by:
The following 4 lines add a border to a bitmap and save it into clipboard, however it also add a border to the bitmap on the screen. I want to create a temp copy of the bitmap and add a border to...
0
by: chuck rudolph | last post by:
Depending on the program that does the copy, my c# program can not get the bitmap data off the clipboard. The code used to get the data is: IDataObject o = Clipboard.GetDataObject(); if...
0
by: James Russo | last post by:
Hello, I have an application which requires an image to be retrived from the clipboard. So, I am writting a quick C# windows application to take images from a webcam and store a single frame on...
5
by: Paul_Madden via DotNetMonster.com | last post by:
How can I get a bitmap of a Form using .NET 1.1 (ie NO CopyFromScreen) -- Message posted via DotNetMonster.com http://www.dotnetmonster.com/Uwe/Forums.aspx/dotnet-csharp/200605/1
12
by: active | last post by:
I've been looking on the Internet for a way to convert a DIB to a Bitmap without success. Now I'm wondering if that is the approach I should be taking. All I want to do is display the DIB or...
6
by: \Frank\ | last post by:
On the Internet there are many descriptions of the memory layout for a DIB. But none that I can find for a Bitmap. Is that because a Bitmap's layout depends on a related device. If that's...
6
by: \Frank\ | last post by:
I trying to learn what a Bitmap is. Not a Managed Bitmap Object but one that, for example, comes from the clipboard with CF_BITMAP. I'm guessing that a CompatableBitmap is an array of indices...
1
by: info | last post by:
Hi All, I am struggling with this from 48 hours and cannot succeed, of course I've tried: DataObject dObj = new DataObject(); dObj.SetData(DataFormats.Bitmap, false, bitmap);...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.