Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to generate automatically an image from a simple text


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Jun 11, 2016 6:15 PM Last Post By: Patricio Cerda
Patricio Cerda

Posts: 122
Registered: 3/13/01
How to generate automatically an image from a simple text  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 11, 2016 10:46 AM
Hi,

I need some help to do the following: I have a C++ Builder application that manages products (with a few attributes per each one) that are saved on an InterBase database; one of those attributes is a small image that represents the product.

What I want is to automatically generate an image to help the user on the creation process of new products, using for that the nickname of the product. If the product is an Apple fruit and its nickname is "Asian Apple" then the image would be "Asian Apple" with special format that makes it simple to visually be recognized by the user (for example: Helvetica Neue font, bold and red text, centered and adjusted).

I'm not sure which is the better way to do it.
Could someone help me showing with maybe a way, an example or ideas?

Thanks in advance,
Patricio Cerda
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to generate automatically an image from a simple text  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 11, 2016 3:03 PM   in response to: Patricio Cerda in response to: Patricio Cerda
Patricio wrote:

I'm not sure which is the better way to do it.

Create an instance of Graphics::TBitmap and draw your desired text onto its
Canvas in whatever Font you want. Then do whatever you need with the TBitmap.
For example:

Graphics::TBitmap *bmp = new Graphics::TBitmap;
try
{
    bmp->SetSize(DesiredWidth, DesiredHeight);
    TRect r = Rect(0, 0, bmp->Width, bmp->Height);
 
    bmp->Canvas->Brush->Color = ...; // desired background color
    bmp->Canvas->FillRect(r);
 
    bmp->Canvas->Font->Name = "Helvetica Neue";
    bmp->Canvas->Font->Style = TFontStyle() << fsBold;
    bmp->Canvas->Font->Color = clRed;
    String s = ...; // desired text
    bmp->Canvas->TextRect(r, s, TTextFormat() << tfCenter << tfSingleLine 
<< tfVerticalCenter);
 
    // use bmp...
}
__finally {
    delete bmp;
}


--
Remy Lebeau (TeamB)
Patricio Cerda

Posts: 122
Registered: 3/13/01
Re: How to generate automatically an image from a simple text  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 11, 2016 6:15 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Excellent, thanks Remy!

bmp->Canvas->Font->Style = TFontStyle() << fsBold;
Just a little modification, I think that this line of code must be: bmp->Canvas->Font->Style = TFontStyles() << fsBold;

Best regards,
Patricio Cerda
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02