473,406 Members | 2,281 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,406 software developers and data experts.

Is there an easy way to put a DIB on the clipboard?

Is there an easy way to add a Dib to the clipboard.

I've tried these commands.

myData.SetData(DataFormats.Bitmap, True, MyBitmap)

SetClipboardData(CLIPFORMAT.CF_BITMAP, MyBitmap.GetHbitmap)

SetClipboardData(CLIPFORMAT.CF_DIB, MyBitmap.GetHbitmap)

Clipbrd may menu the DIB but even when it does it can not display it.

It's not necessary that I add the DIB but if it's easy I'd like to.

Thanks
Jul 29 '07 #1
2 2563
CLIPFORMAT.CF_DIB is a handle based clipboard format.

The handle is allocated with GlobalAlloc and the memory must be moveable.

The DIB's memory layout is as follows:
1) BITMAPINFOHEADER
2) ColorTable or Bitfields array, if any(i.e, predicated on bpp of image)
3) Bitmap's bits

The easiest way to put a DIB on the clipboard is as follows:
1) Load a Bitmap as a MemoryStream
2) Use GlobalAlloc to allocate memory. The allocated size is the sizeof the
BITMAPINFOHEADER
plus the sizeof the colortable. if any, and the size of the bitmap's
bits.
3) Seek past the BITMAPFILEHEADER in the MemoryStream(i.e.,14 bytes)
4) Copy the BITMAPINFOHEADER, ColorTable, if any, and the bits to the block
of memory allocated in step 2.
You must use GlobalLock and the Interop's Marshal copy routines.
5) After you have finished. Be sure to use GlobalUnlock. Pass the HGLOBAL
memory handle to the clipboard.
SetClipboardData(CLIPFORMAT.CF_DIB, hGlobal). Where hGlobal is an
IntPtr.
" active" <ac**********@a-znet.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Is there an easy way to add a Dib to the clipboard.

I've tried these commands.

myData.SetData(DataFormats.Bitmap, True, MyBitmap)

SetClipboardData(CLIPFORMAT.CF_BITMAP, MyBitmap.GetHbitmap)

SetClipboardData(CLIPFORMAT.CF_DIB, MyBitmap.GetHbitmap)

Clipbrd may menu the DIB but even when it does it can not display it.

It's not necessary that I add the DIB but if it's easy I'd like to.

Thanks


Jul 29 '07 #2
Works great and surprising little code.

Thanks again

"Michael Phillips, Jr." <mp*********@nospam.jun0.c0mwrote in message
news:eJ**************@TK2MSFTNGP05.phx.gbl...
CLIPFORMAT.CF_DIB is a handle based clipboard format.

The handle is allocated with GlobalAlloc and the memory must be moveable.

The DIB's memory layout is as follows:
1) BITMAPINFOHEADER
2) ColorTable or Bitfields array, if any(i.e, predicated on bpp of image)
3) Bitmap's bits

The easiest way to put a DIB on the clipboard is as follows:
1) Load a Bitmap as a MemoryStream
2) Use GlobalAlloc to allocate memory. The allocated size is the sizeof
the BITMAPINFOHEADER
plus the sizeof the colortable. if any, and the size of the bitmap's
bits.
3) Seek past the BITMAPFILEHEADER in the MemoryStream(i.e.,14 bytes)
4) Copy the BITMAPINFOHEADER, ColorTable, if any, and the bits to the
block of memory allocated in step 2.
You must use GlobalLock and the Interop's Marshal copy routines.
5) After you have finished. Be sure to use GlobalUnlock. Pass the
HGLOBAL memory handle to the clipboard.
SetClipboardData(CLIPFORMAT.CF_DIB, hGlobal). Where hGlobal is an
IntPtr.
" active" <ac**********@a-znet.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Is there an easy way to add a Dib to the clipboard.

I've tried these commands.

myData.SetData(DataFormats.Bitmap, True, MyBitmap)

SetClipboardData(CLIPFORMAT.CF_BITMAP, MyBitmap.GetHbitmap)

SetClipboardData(CLIPFORMAT.CF_DIB, MyBitmap.GetHbitmap)

Clipbrd may menu the DIB but even when it does it can not display it.

It's not necessary that I add the DIB but if it's easy I'd like to.

Thanks



Jul 31 '07 #3

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

Similar topics

8
by: LG | last post by:
Just have a question with regards to the clipboard, and how to read what other applications (Adobe InDesignCS) place in the clipboard. I am currently in the process of creating a booklet from a...
4
by: Kevin Brown | last post by:
I simply want to copy the DataView and paste it into an email. What's the best way to accomplish that? I could obviously write the XML to a string and copy the string, but that's "ugly" for an...
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...
7
by: Newbie | last post by:
How do I clear the clipboard in VB.NET 2003? TIA Newbie
15
by: Peter Duniho | last post by:
I'm trying to use .NET and C# to draw a metafile copied to the clipboard by another application (Word 2003 in this case, but it shouldn't matter). I naively thought that I'd be able to use the...
1
by: Figmo | last post by:
Wow.....this is darned odd.... I have an app that integrates with other applications. It registers a global hotkey with Windows. When the hotkey executes it sends a CTRL-C to the active...
8
by: active | last post by:
Guess I'm looking for someone who likes to work difficult puzzles. I can't seem to ever retrieve a palette handle from the clipboard. Below is a simple test program that demonstrates the...
20
by: Joe Duchtel | last post by:
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...
8
by: Irene | last post by:
Hi, I have an MS Access Database with 1 Table containing about 2 million records in Unicode (diferent languages). I would like to export the Table to a Text file (CSV, Tab, etc.) Access...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.