Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Drawing / August 2004

Tip: Looking for answers? Try searching our database.

Get DC for sys.dr.bitmap

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Thomas Fisher - 28 Aug 2004 15:59 GMT
Hello All,

I've been working on this for several days now and could use some direction
so thanks in advace for any help.

I have a COM method which needs "the handle to the device context for the
bitmap."  I'm guessing that it's expecting a DIB but I'm not certain. If so,
how do I create a DIB from a GDI+ bitmap?

Here's the code I've written so far for creating the device context.  But
the result is a reference to an empty bitmap (regardless of the DIB issue).

   Public OSDBitmap As Bitmap
   Public OSDGraphics As Graphics

   Public Function GetHDCFromBitmap() As IntPtr
       OSDBitmap = New Bitmap("c:\testing.dib")
       Dim r As New Rectangle(0, 0, OSDBitmap.Width, OSDBitmap.Height)
       OSDBitmap.LockBits(r, Imaging.ImageLockMode.ReadWrite,
OSDBitmap.PixelFormat)
       OSDGraphics = Graphics.FromImage(OSDBitmap)

       'just for testing
       OSDGraphics.FillRectangle(New SolidBrush(Color.Red), 10, 10, 50, 50)
       Me.pbOSD.Image = bm
       'end testing

       Dim h1 As GCHandle = GCHandle.Alloc(bm, GCHandleType.Normal)
       Dim hBitmap As IntPtr = bm.GetHbitmap()

       Dim hdcBmp, hbmOld As IntPtr

       Dim h2 As GCHandle = GCHandle.Alloc(OSDGraphics,
GCHandleType.Normal)
       Dim hdc As IntPtr = OSDGraphics.GetHdc
       hdcBmp = CreateCompatibleDC(hdc)
       hbmOld = SelectObject(hdcBmp, hBitmap) 'hbitmap or hdc or hdcbmp?
       OSDGraphics.ReleaseHdc(hdc)
       If hdcBmp.ToInt32 = 0 Then
           Throw New Exception("no hdcBmp")
       End If

       DeleteObject(hdc)
       h1.Free()
       h2.Free()

       Return hdcBmp
   End Function

What am I doing wrong? and do you think I need a DIB?

Thanks,
Tom
James Westgate - 29 Aug 2004 18:23 GMT
Hi Thomas

Have you tried

Graphics g = Graphics.FromImage(image);
IntPtr ptr = g.GetHdc;

James

Signature

Create interactive diagrams and flowcharts with ERM Diagram at
http://www.crainiate.net

Take the ERM Tour at http://www.flowchartcontrol.com

> Hello All,
>
[quoted text clipped - 53 lines]
> Thanks,
> Tom

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.