CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    198

    Using GDI to Draw RichText over an image

    Hey Gurus,

    I'm writing an application to generate subtitle for 2k and 4k digital cinema projectors.
    I have a rich edit control for the user to input and format the text.
    I now need to preview this text over an image (I'm using GDI to do this).

    So far, no worries.

    My question is:
    The text the user enters can conceivably have different attributes on a per character basis. For example the text could look like this:

    This is a line of sub title

    Unlikely I know, however the standard to which I am complying has this ability (DCI Compliance).

    Is there an easy way to print this over an image in a window, or do I have to do it a character at a time, changing the format of the text as I go?

    If I have to do it a character at a time, how do I calculate the position of the next character in the line (ie the width of the previous character in pixels)?

    Thanks in advance for your help.

    Steve Q.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Using GDI to Draw RichText over an image

    Quote Originally Posted by steveq View Post
    ...
    If I have to do it a character at a time, how do I calculate the position of the next character in the line (ie the width of the previous character in pixels)?
    Did you look at the CDC methods like
    CDC:rawText
    CDC::GetTextExtent
    CDC::GetTabbedTextExtent
    and so on...?
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    198

    Re: Using GDI to Draw RichText over an image

    Hey VictorN,

    Thanks so much for your reply.

    I haven't check those functions, so will look at them now.

    I'm assuming from your reply that I have to do it a character at a time... DOH!

    Still, thanks again for your help,

    Regards,

    Steve Q.

  4. #4
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    198

    Re: Using GDI to Draw RichText over an image

    Hey Gurus,

    A further question to the above!

    I've changed to GDI+ because it is easy to load jpegs etc...

    It is all working fine please see my code below:

    Code:
    	RECT lpRect;
    
    	GetClientRect( &lpRect );
    
    	wchar_t progDir[MAX_PATH];
    
    	wchar_t fileName[MAX_PATH];
    
    	// This gets the path and name of the executable.
    	GetModuleFileName( NULL, progDir, MAX_PATH );
    
    	// This loop removes the file name and just leaves the executable's path.
    	for( size_t i = wcslen( progDir ); i > 0 && progDir[ i ] != '\\'; i-- ) progDir[ i ] = '\0';
    
    	wcscpy( fileName, progDir );
    
    	wcscat( fileName, _T( "Toffee.jpg" ) );
    
    	Image image( fileName );
    
    	Graphics graphics( dc.m_hDC );
    
    	FontFamily fontFamily(L"Arial");
    	Font myFont(&fontFamily, 180, FontStyleBold, UnitPixel);
    
    	StringFormat format;
    	SolidBrush blackBrush(Color(255, 255, 255, 255));
    
    	// Draw string.
    	graphics.DrawString(L"This is my text!", 16, &myFont, PointF(0,0), &format, &blackBrush);
    
    	// Create a rect the size of my image container.
    	RectF destRect(0, 0, lpRect.right, lpRect.bottom);
    
    	// Draw the image scaled to fit the image conatiner.
    	graphics.DrawImage(&image, destRect);
    My problem is that I want my text to be scaled along with the image. I can see that my image will overwrite the text in the above code, so how do I draw the image, drawstring text over it and then scale it and draw it into my image container in the window?

    Please ignore my lack of error testing... I'm just trying to get this to work before I write the code properly.

    Thanks heaps in advance for your help,

    Kind regards,

    Steve Q.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured