Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi guys.

Anybody can help me with this problem?

 

I would like to save the content of a control (for example a TreeView) as a Bitmap.

 

I think I must go throug HWND and such things. I made a lot of attempts but all unsuccessful.

 

What I really need is to export the complete content of a control EVEN if this has scrollbars and only a part of the content is visible.

 

Thanks a lot.

Posted
Posted

Oh, I read that topic and it's another matter.

In that topic the user at last gets a Graphic from a bitmap, draws on the Graphic and then saves the bitmap.

 

I need to do another thing.

 

I use a "whatever" control then at a certain point I would like to do something like this

 

Graphics myGr = WhatherverControl.CreateGraphics();

Bitmap bmp = CreateABitmapFromAGraphics(myGr); :D

bmp.Save(bmpFileName);

 

Here's something that I already tried

 

[DllImport("gdi32.dll",

ExactSpelling=true,

SetLastError=true)]

public static extern IntPtr CreateCompatibleBitmap(IntPtr hObject,

int width,

int height);

 

----------------------

Graphics g = treeChartView1.CreateGraphics();

IntPtr hdc = g.GetHdc();

IntPtr bmpHdc = CreateCompatibleBitmap(hdc,sizeX,sizeY);

Bitmap bmp = Bitmap.FromHbitmap(bmpHdc);

 

then saved the bitmap and got a black image

  • *Gurus*
Posted

When you draw to a control, you're drawing directly to screen memory. Your bitmap isn't stored anywhere. That's why there is no method to get a bitmap from a control or graphics object.

 

The best you could hope for would be to interop and see if you can get BitBlt working.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

Sigh, I made this attempt also.

 

I post the code here, I hope I made some terrible mistake so that it can be fixed. I'm losing the hope :(

 

 

----------

 

 

[DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]

public static extern Bool BitBlt(IntPtr hObject,

int nXDest,

int nYDest,

int nWidth,

int nHeight,

IntPtr hObjSource,

int nXSrc,

int nYSrc,

int dwRop);

 

----

 

 

Graphics g = TreeView1.CreateGraphics();

IntPtr hdc = g.GetHdc();

Bitmap bmp = new Bitmap(630,570);

Graphics bg = Graphics.FromImage(bmp);

IntPtr bHdc = bg.GetHdc();

 

BitBlt(hdc,

0, 0,

630, 570,

bHdc,

0, 0,

0x00CC0020);

 

Bitmap bmp = Bitmap.FromHbitmap(bHdc);

 

bmp.Save("c:\\pippo.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

Console.WriteLine("Salvato");

g.ReleaseHdc(hdc);

 

 

----

 

 

any ideas??

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...