petrosken Posted June 13, 2003 Posted June 13, 2003 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. Quote
ThePentiumGuy Posted June 13, 2003 Posted June 13, 2003 see this post: http://207.68.162.250/cgi-bin/linkrd?_lang=EN&lah=ea3465f61f72f56f5917f83731dde4a1&lat=1055509682&hm___action=http%3a%2f%2fwww%2edotnetforums%2enet%2fshowthread%2ephp%3fthreadid%3d72953%26goto%3dnewpost Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
ThePentiumGuy Posted June 13, 2003 Posted June 13, 2003 i heard tat the above link doesnt work just go under graphics and see Saving a Graphic as a bitmap. (C#) Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
petrosken Posted June 13, 2003 Author Posted June 13, 2003 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 Quote
*Gurus* divil Posted June 13, 2003 *Gurus* Posted June 13, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
petrosken Posted June 13, 2003 Author Posted June 13, 2003 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?? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.