Click to See Complete Forum and Search --> : GDI to GDI+
shilpa_9
June 2nd, 2004, 02:53 AM
Hi,
I have recently started working on VC++(7.0).net moving on from VC++(6.0).
All I wanted to know is that, is it possible to convert the GDI bitmap(CBitmap class created) to GDI+ bitmap(Bitmap class), in order to use the functionalities of the Bitmap class?????
Kindly help
Thnx in advance
Marc G
June 2nd, 2004, 04:14 AM
You can use the FromHbitmap function from the gdi+ Bitmap class.
shilpa_9
June 3rd, 2004, 12:37 AM
Hi Marc,
What you suggested is the reverse of what I want to do. I tried that too, but it doesnt work. I am pasting the code that I have currently just tried in the OnDraw function of the View. Pls tell me where I am going wrong, since it doesnt show the output.
Pls note tht the CBitmap member variable which I am using in the OnDraw function as "m_Bitmap", is already initialised in the OnInitialUpdate function of the view by using
m_pBitmap.LoadBitmap("E:\\My Pictures\\Canyon2.jpg");
CMyView::OnDraw(CDC* pDC)
{
HBITMAP hbitmap;
hbitmap = (HBITMAP)m_Bitmap.GetSafeHandle();
Bitmap bitmap(hbitmap, NULL);
INT iWidth = bitmap.GetWidth();
INT iHeight = bitmap.GetHeight();
Graphics g(pDC->GetSafeHdc());
// Now draw the modified bitmap.
g.DrawImage(&bitmap, 0, 0, iWidth, iHeight);
}
Marc G
June 3rd, 2004, 03:10 AM
You can't use LoadBitmap to load from a file but only from a bitmap resource.
But you are already using GDI+, then why not use the Bitmap class itself to load the image from file?
shilpa_9
June 3rd, 2004, 05:25 AM
Hi,
I do agree that instead of going through the long way of creating the Bitmap object from GDI CBitmap object I could very well use Bitmap object itself. But Bitmap class too has its limitations and it can create objects only from BMP, ICON, GIF, JPEG, Exif, PNG, TIFF, WMF, and EMF file types. Whereas in my application I will be using many more file formats like TGA, PCX and so on. Thts the reason I thought of atleast trying out by simply using the LoadBitmap function for testing purpose, though I dont intend using the same in future. I am already using an Image library which helps me convert any file format to HBITMAP. Using the same I would want to convert this HBITMAP to Bitmap class object so that I can use the various functionalities under the Bitmap class.
If anybody out here has an answer to this, I would be most glad
Thnx
Marc G
June 3rd, 2004, 07:58 AM
The code you've posted does work correctly!
But in your example you've posted you use the following:
m_pBitmap.LoadBitmap("E:\\My Pictures\\Canyon2.jpg");
This does not work, but the rest of the code for getting a Bitmap from HBITMAP works.
d0153030
June 28th, 2004, 03:10 AM
Hi Shilpa
Not an answer but was requiring the info from you.
Can you name the graphics library you are using. If possible can you provide me the link, from where i can get it.
Thanks in advance
Sandeep
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.