11-21-2012 06:11 AM
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.
11-21-2012 07:28 AM
11-21-2012 07:33 AM
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(th is);
// 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.
11-21-2012 11:40 AM
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.