Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
shahumang8
Posts: 600
Registered: ‎08-09-2010
My Device: Not Specified

Draw text into Image at that time Application Crash

Hello,

 

    When i draw text into Image at that time Application Crash so please check attachement and update me.

 

    Note :- But when i draw Rectangle at that time ractangle draw perfect and run.

 

Thanks.

Please use plain text.
Developer
simon_hain
Posts: 16,018
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Draw text into Image at that time Application Crash

I did not check your code, but maybe you could use a Container with an image background and a Label as content?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
shahumang8
Posts: 600
Registered: ‎08-09-2010
My Device: Not Specified

Re: Draw text into Image at that time Application Crash

Hello Simon,

 

   No.Actully i do image Processing.

 

   Please check my code.

 

   main.qml

 

   

// Default empty project template
import bb.cascades 1.0

// creates one page with a label

Page {
    Container {
        layout: DockLayout {
        }
        ImageView {
            objectName: "imageView"
        }
    }
}

   TextDraw.cpp

 

 

   

// Default empty project template
#include "TextDraw.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/Page>
#include <bb/cascades/ImageView>
#include <bb/ImageData>
#include <bb/PixelFormat>

using namespace bb;
using namespace bb::cascades;

TextDraw::TextDraw(bb::cascades::Application *app) :
		QObject(app) {
	// create scene document from main.qml asset
	// set parent to created document to ensure it exists for the whole application lifetime
	QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

	// create root object for the UI
	Page *root = qml->createRootObject<Page>();
	ImageView* testImage = root->findChild<ImageView *>("imageView");

	QImage *qImageMain = new QImage("app/native/assets/test.jpg");

	QPainter painter(qImageMain);

	// Draw Rect
	painter.fillRect(QRect(0, 0, 50, 50), QColor::fromRgb(255, 0, 0));

	//Draw Text
	painter.drawText(150, 150, "Hello");

	int width = qImageMain->width();
	int height = qImageMain->height();

	ImageData imageData = ImageData(PixelFormat::RGBA_Premultiplied, width,
			height);

	int A, R, G, B;
	unsigned char *dstLine = imageData.pixels();
	for (int y = 0; y < height; y++) {
		unsigned char * dst = dstLine;
		for (int x = 0; x < width; x++) {
			QRgb srcPixel = qImageMain->pixel(x, y);

			A = qAlpha(srcPixel);
			R = qRed(srcPixel);
			G = qGreen(srcPixel);
			B = qBlue(srcPixel);

			*dst++ = R;
			*dst++ = G;
			*dst++ = B;
			*dst++ = A;
		}
		dstLine += imageData.bytesPerLine();
	}

	Image image = Image(imageData);

	testImage->setImage(image);

	// set created root object as a scene
	app->setScene(root);
}

 

   And update me. 

 

 Thanks.

 

    

Please use plain text.
Developer
smiley
Posts: 1,449
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: Draw text into Image at that time Application Crash

This is a known problem as I have posted before and another user before me.

 

//Draw Text
	painter.drawText(150, 150, "Hello");

No one from RIM had confirmed the problem yet but drawText() crashes everytime. 

 

the error I got is something about font.  if you search the forum you will find the posting.

 

Please use plain text.