Is there anyway to convert user input text to an image file (.jpg, .bmp , .gif)
| Fri, 2006-02-17 09:32 | |
|
Hello,
I experiment something (a test project). I found I need to convert text to an image file. For example, I get text input from user. Then I have to convert those input text as an image file. There must be some way to do it. But I could not really find where to start for creating own image file. Could someone point me to a right direction? Thanks! |
|






Forum posts: 982
If you need an image with the text typed by the user there is a very simple method to achieve it: just draw the user text into a bitmap (you can find a lot of examples on how to use different graphic contents).
pirosl
Forum posts: 1233
When you are done, save it to a file with the format of your choise using CImageEncoder
Search for the above classes on this forum and you will find plenty of examples on their usage.
Forum posts: 68
Problem solved!
But there are something I would like to add for future developer who will need same solution. They dont need to dig it from the very bottom, as I did so. Solution is given below:
_LIT( KImageFile2, "c:\\MyBmp.bmp");
void CMyClass::ConvertBitmapToFileL(CFbsBitmap*& aBitmap, const TDesC& aText)
{
//set size for bitmap
TInt aWidth = 200, aHeight = 200;
aBitmap = new(ELeave)CFbsBitmap();
CleanupStack::PushL(aBitmap);
User::LeaveIfError(aBitmap->Create(TSize(aWidth, aHeight), EColor64K));
CFbsBitmapDevice* bitDevice = CFbsBitmapDevice::NewL(aBitmap);
CFbsBitGc* bitGc;
User::LeaveIfError(bitDevice->CreateContext(bitGc));
CleanupStack::Pop(aBitmap);
//make your drawings here
//e.g.
bitGc->SetPenColor(KRgbBlack);
bitGc->UseFont( LatinBold19() ); // a font has to be set otherwise it panics!
bitGc->SetPenStyle(CGraphicsContext::ESolidPen);
bitGc->DrawText(aText, TPoint(10, 10));
RFs fs;
User::LeaveIfError( fs.Connect() );
// constructing encoder
CImageEncoder* imgEncoder = CImageEncoder::FileNewL( fs, KImageFile2, _L8("image/bmp"),
CImageEncoder::EOptionAlwaysThread );
// Following settings are for JPG file format
// TJpegImageData* imageData = new (ELeave) TJpegImageData;
// Set some format specific data
// imageData->iSampleScheme = TJpegImageData::EColor444;
// imageData->iQualityFactor = 95;
// Following settings are for BMP file format
TBmpImageData* imgData = new(ELeave) TBmpImageData;
imgData->iBitsPerPixel = 24;
CFrameImageData* iFrameImageData = CFrameImageData::NewL();
// frameData - ownership passed to iFrameImageData after AppendImageData
User::LeaveIfError(iFrameImageData->AppendImageData(imgData)); // or append imageData for jpg file
// Do the convert
TRequestStatus iRequesStatus;
imgEncoder->Convert( &iRequesStatus, *aBitmap, iFrameImageData);
User::WaitForRequest( iRequesStatus );
fs.Close();
delete iFrameImageData;
delete aBitmap;
delete imgEncoder;
delete bitGc;
delete bitDevice;
}
//call it like this:
TBuf<KMaxName> myText;
myText.Copy(_L("Problem Solved! MADSUM"));
CFbsBitmap *myBitmap;
ConvertBitmapToFileL(myBitmap, myText);