   How to convert a string to a bitmap? C++
  Hi,I have a problem. I want to get the text entered by the user in an edit box control to a bitmap. I'm using Visual C++. How do I convert it? No MFCs, please.Thanks,M   
  You can't convert an apple to an orange...If the string contained bitmap data, then this would let you access that data as if it were a bitmap... But I'm guessing that's not what you meant?std::string userInput = "foo";class Bitmap;Bitmap* = (Bitmap*)userInput.c_str();Do you mean that you want to create a new bitmap, and then render the contents of the string into it?If that's the case, you might find a 3rd-party library like Image Magick handy.   ;Quote:Original post by HodgmanDo you mean that you want to create a new bitmap, and then render the contents of the string into it?That's EXACTLY what I want. I cannot use any third party libraries. Is there any other way?Thanks,M;Quote:Original post by HellzGodQuote:Original post by HodgmanDo you mean that you want to create a new bitmap, and then render the contents of the string into it?That's EXACTLY what I want.In what colour, font and size? And why?Quote:I cannot use any third party libraries.Why not?Quote:Is there any other way?Yes; you can duplicate the work done by one of the third party libraries.Hint: It's a lot of work, even for the small amount of functionality you're actually going to use.   ;  Hi,I'll have to ask for permission to download libraries. Thanks,M   ;Quote:Original post by HellzGodI'll have to ask for permission to download libraries. Then just ask. The worst that they can say is no. In which case you will have to duplicate the functionality provided in the other library. On the other hand they might say yes. In which case you have just saved yourself a ton of work.;Quote:Original post by HellzGodHi,I'll have to ask for permission to download libraries.From who? If it's your employer, then you can justify the downloads by the time they'll save you. If it's a teacher, then you can tell him that working with libraries is an important aspect of programming these days. Not to mention that it's often just the smarter approach.   ;  Isn't it just a case of:Determine the size of the text (GetTextExtentPoint32)Create a compatible DC (CreateCompatibleDC)Create a bitmap (CreateBitmap)Select the standard GUI font into the device context (SelectObject(GetStockObject(DEFAULT_GUI_FONT)))Draw the text to it (DrawText)Save the bitmap (You'll need to write the code for that, but it's pretty easy).It's not that much work really.;  I've limited the scope a bit. What if I use a Rich Edit Control (I've no idea of that either).Anyway, this is what I do:[Source] HBITMAP hBmp; void WriteTextToBMP ( HWND hRichEdit )  {   HDC hdc = GetDC(hRichEdit);   HDC hMemDC = CreateCompatibleDC(hdc);   hBmp = CreateCompatibleBitmap(hdc,MAXWIDTH,MAXHEIGHT);   HBITMAP hBmpOld = SelectObject(hMemDC,hBmp);   BitBlt(hdc,0,0,MAXWIDTH,MAXHEIGHT,hMemDC,0,0,SRCCOPY);   SelectObject(hMemDC,hBmpOld); DeleteDC(hMemDC); ReleaseDC(hdc,NULL); }[/Source]I use hBmp elsewhere. I'm not getting any change. Is the above code correct? I have invoked this in WM_PAINT. Is that ok?Thanks,M   