Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8443685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:12:16+00:00 2026-06-10T09:12:16+00:00

I’m developing a clipboard manager (which can be seen here: http://flamefusion.net/software/shapeshifter ). However, I

  • 0

I’m developing a clipboard manager (which can be seen here: http://flamefusion.net/software/shapeshifter).

However, I am currently having issues with a bitmap (bmp) that won’t really insert itself into the clipboard properly. My first approach was the following, using SetClipboardData.

var hBitmap = bmp.GetHBitmap();
SetClipboardData(CF_BITMAP, hBitmap);

I am aware of the potential memory leaks in this, and it was made solely as a test. The test failed. The image put into the clipboard was not readable by Paint when pasting it in.

So after a lot of researching and failed attempts, I got a new theory. The bitmap I am using is created from a MemoryStream, which has been created through a previous call to the Bitmap.Save(Stream, ImageFormat) method. This leads me to believe that a System.Drawing.Bitmap‘s GetHBitmap is not the kind of HBITMAP the SetClipboardData function expects.

So I tried the following, with some kind of success.

var memDC = CreateCompatibleDC(IntPtr.Zero);
var memBitmap = CreateCompatibleBitmap(memDC, bmp.Width, bmp.Height);
SetClipboardData(CF_BITMAP, memBitmap);

Now the image is inserted with the right dimensions, but as a black image. And this is quite obvious, since nothing from bmp is actually used to create the “compatible” bitmap other than its width and height.

I assume I have to use BitBlt somehow to copy my original bitmap over to this now “compatible” bitmap, but I have no clue of where to begin.

Would any of you GDI wizards know? Magic is obviously needed here.

Edit 1
As dthorpe nicely pointed out, it seems that my problem is that the image I am trying to save is in fact a DIB. Now the question has changed. I need to figure out how to convert from a DIB to a DDB. I am aware of the alpha loss while doing this among other things, but it is nevertheless needed.

Edit 2
It is not acceptable to use Clipboard.SetImage. This won’t work in my scenario. I need to use the APIs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:12:18+00:00Added an answer on June 10, 2026 at 9:12 am

    CF_BITMAP is probably the wrong format to use with your bitmap. The CF_BITMAP clipboard format specifies a device bitmap, but nearly all bitmaps today are DIBs – device independent bitmaps. Device bitmaps are relative to the system/hardware device palette (think EGA graphics) and must match the pixel format of the current display mode. DIBs carry their own color info and their pixel format is independent of the display mode.

    Docs say that the clipboard manager will convert a CF_BITMAP to a CF_DIB if an application asks for CF_DIB when reading from the clipboard, but that assumes that the original image is actually a device bitmap in the current display mode pixel format. If it is not, the conversion will produce garbage because the input is garbage.

    Try again using CF_DIB instead of CF_BITMAP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.