Convert QByteArray QImage

Hi all

Is it possible to convert QByteArray QImage?

Answer please!

See you soon!

use the registration method.

example of http://qt-project.org/doc/qt-4.8/qimage.html#save-2

QImage image;
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "PNG"); // writes image into ba in PNG format

Tags: BlackBerry Developers

Similar Questions

  • How to convert QByteArray QImage?

    Hello

    Anyone know how to convert QByteArray QImage?

    You can use this:

    QImage img = getAnImage();
    QByteArray arr;
    QBuffer buf(&arr);
    buf.open(QIODevice::WriteOnly);
    img.save(&buf, "PNG");
    buf.close();
    
  • Nfc_ndef_record_t convert QByteArray HowTo

    in one of my applications, I use NFC with custom instead of the record to the text file Type to be able to invoke my app since the NFC Tag directly.

    Also, within my application, there is a feature allowing the user to write these Tags NFC

    I would like to use an InvokeActionItem to use the sys. NFCViewer - I love the beautiful UI of it.

    For my text NFC files, it works well.

    Here's the InvokeActionItem:

           InvokeActionItem {
                imageSource: "asset:///images/ic_add.png"
                title: qsTr("NFC Tag Text")
                enabled: nfcActionSelector.selectedValue > 0
                ActionBar.placement: ActionBarPlacement.OnBar
                query {
                    mimeType: "application/vnd.rim.nfc.ndef"
                    invokeTargetId: "sys.NFCViewer"
                    invokeActionId: "bb.action.SHARE"
                }
                handler: InvokeHandler {
                    id: shareHandler
                    onInvoking: {
                        tagWriteAction.data = app.getNdefTextMessage("en", nfcText);
                        shareHandler.confirm();
                    }
                }
            }
    

    This works well using a QByteArray:

    QByteArray ApplicationUI::getNdefTextMessage(const QVariant &lang,
            const QVariant &text) {
        QString ndefLang = lang.toString();
        QString ndefText = text.toString();
        QtMobilitySubset::QNdefRecord ndefRecord = QtMobilitySubset::QNdefRecord();
        int langLength = (ndefLang.length() <= 63) ? ndefLang.length() : 63;
        QByteArray ndefPayload;
        ndefPayload[0] = langLength;
        ndefPayload.append(ndefLang.left(langLength)).append(ndefText.toUtf8());
        ndefRecord.setTypeNameFormat(QtMobilitySubset::QNdefRecord::NfcRtd);
        QByteArray nfcRtdText = "T";
        ndefRecord.setType(nfcRtdText);
        ndefRecord.setPayload(ndefPayload);
        QtMobilitySubset::QNdefMessage ndefMessage = QtMobilitySubset::QNdefMessage(
                ndefRecord);
        return ndefMessage.toByteArray();
    }
    

    So far so good

    Now, I wanted to implement similar but using a recording of NFC Custom type.

    This application example

    has a method to create a record custom:

    nfc_ndef_record_t* ApplicationUI::makeCustomRecord(QString domain, QString type,
            QString content) {
    
        nfc_ndef_record_t* record = 0;
    
        int textLen = content.length();
        QString domainPlusType = domain.append(":");
        domainPlusType = domainPlusType.append(type);
        int totalLen = textLen;
    
        uchar_t payload[totalLen];
    
        int offset = 0;
        memcpy(&payload[offset], content.toUtf8().constData(), textLen);
    
        CHECK(
                nfc_create_ndef_record(NDEF_TNF_EXTERNAL,
                        domainPlusType.toUtf8().constData(), payload, totalLen, 0,
                        &record));
    
        return record;
    }
    

    Unfortunately, I'm a nfc_ndef_record_t but need a QByteArray, use the same InvokeActionItem way in which regards NFC text documents.

    Who knows how to convert the nfc_ndef_record_t in QByteArray?

    thx for the help

    Thanks to the help John Murray on twitter (@jcmrim) I'm creating a QNdefRecord:

    QByteArray ApplicationUI::makeCustomRecord(QString domain, QString type,
            QString content) {
    
        QString domainPlusType = domain.append(":");
        domainPlusType = domainPlusType.append(type);
    
        QtMobilitySubset::QNdefRecord ndefRecord = QtMobilitySubset::QNdefRecord();
    
        ndefRecord.setTypeNameFormat(QtMobilitySubset::QNdefRecord::ExternalRtd);
        ndefRecord.setType(domainPlusType.toUtf8());
        ndefRecord.setPayload(content.toUtf8());
    
        QtMobilitySubset::QNdefMessage ndefMessage = QtMobilitySubset::QNdefMessage(
                ndefRecord);
    
        return ndefMessage.toByteArray();
    }
    

    Now the sys. Rises in NFCViewer:

    InvokeActionItem {
                imageSource: "asset:///images/ic_add.png"
                title: qsTr("NFC Custom")
                ActionBar.placement: ActionBarPlacement.OnBar
                query {
                    mimeType: "application/vnd.rim.nfc.ndef"
                    invokeTargetId: "sys.NFCViewer"
                    invokeActionId: "bb.action.SHARE"
                }
                handler: InvokeHandler {
                    id: shareHandler2
                    onInvoking: {
                        tagWriteAction.data = app.makeCustomRecord("org.xxxx", "mytype", nfcText);
                        shareHandler2.confirm();
                    }
                }
            }
    

    But if by tapping a NFC Tag I get

    The data could not be shared over NFC
    

    Any idea?

    Or the NFCViewer not accept ExternalRtd?

    documentation :

    NDEF message is sent in the form of a byte array. The following method is used to create the byte array message:
    

    It works with text documents

    Or I do something wrong to build the payload or the record?

  • ImageView is not showing any transparency since QImage converted to bb::cascades:Image

    Hi all

    I always try to create an overlay to the mapView. I'm now trying to use a standard QImage QPainter solution, then converting the QImage I called a bb::cascade:Image. But for some reason, the ImageView still has a white background, even when the Image I give all its alpha set to 0 pixel values.

    NVM solved, I'm stupid. It's that the I had the container root of my set of custom controls to the disposal of the battery... (aka no overlap) so it would draw on transparency for nothing and he appeared as white.

  • Integration of ImageView and Qimage

    A large part of this issue has been discussed here:

    http://supportforums.BlackBerry.com/T5/Cascades-development/imageView-Cascades-noob-question/TD-p/17...

    Basically, the suggested correct way of converting a QImage ImageView is this one:

    PixelBufferData pbd (PixelBufferData::RGBA_PRE,yourQImage.width(),yourQImage.height(),yourQImage.width(),yourQImage.bits());
    
    yourImageView->setImage(pbd);
    

    Then there was someone by specifying the format must be probably BGR instead of RGB, which could be done with OpenGL or like this:

    image.rgbSwapped();
    

    Here is my code I have a problem with:

    PixelBufferData pbd(PixelBufferData::RGBA_PRE, orgPattern.width(), orgPattern.height(),  orgPattern.width(),  orgPattern.rgbSwapped().bits());
    m_patternFrame->setImage(pbd);
    

    orgPattern is a QImage loaded from a file path that is sure to exist. m_patternFrame is a pointer to the ImageView.

    I know that m_patternFrame is a pointer valid because if I call its method setImageSource by the way I created the QImage, it displays this image. But when I run this code, it is printed in the console:

    Context: Cannot find the node target with id %d 906.

    Sometimes the number is different. When I tried again, it was 563. The application is not cursh or gel, but nothing happens with the framework, it is still empty.

    Can anyone provide any help with this problem?

    Thanks for starting a new thread and referring to another thread.  Allows us to provide you with a timely response.

    Before dive us into this too far, what is the width and height?  (We are within the limits, I guess?)

    And can you try to make the setImage in 2 steps: first to create the Image of the PDB rather than implicitly and test! image.isNull)

    Stuart

  • Use on QImage QPainter

    I'm looking at ways to generate images running. I have been informed that Cascades does not support the fields defined by the user (i.e., I would like to write a class that implements the logic of painting and layout). It was suggested that QPainter could be used to generate the image on a QImage and Image that should be assigned to the picture property of an ImageView and then convert with QImage.

    In order to do this, I wrote code like this:

    MyClass::image() QVariant
    {
    QString str ("Hi");

    QImage image (QSize (100,100), QImage::Format_RGB32);

    QPainter painter (&image);)
    painter.fillRect (0, 0, 100, 100, Qt::white);

    painter.setPen (Qt::blue);
    painter.setFont (QFont ("Arial", 30));

    Causes Segmentation fault!
    painter.drawText (0, 0, 100, 100, Qt::AlignCenter |) Qt::AlignHCenter, str);

    PB of PixelBufferData (PixelBufferData::RGBX, 100, 100, 100, image.bits ());

    QVariant var (QVariant::Image);
    var.setValue (Image (pb));

    return var;
    }

    Unfortunately, this method generates a Segmentation fault when calling drawText. Autour Googling reveals that others face this in the world of Qt with QPainter in the absence of a QApplication object.

    So my question is: QPainter can be used in an application of Cascades? If so, there are samples? If not, what would be the best way to generate images on the fly (for example, a field that displays a result bar graph of the data, etc.)

    Thank you

    Jamie

    You studied WebView with a canvas JS, or OpenGL?

    Stuart

  • Loading XML data in ListView of C++ after extraction of http data

    I'm sorry did searh but could not find any refrence related to my problem
    I am trying to load the xml data returned from a web service HTTP Post QNetworkRequest and QNetworkReply in c ++.

    My XML that gets donwloaded is as

    
     http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/">
      
        tu7652
        F
        Marry
        Wijaya
      
      
        23
        F
        Marry
        Wijaya
      
    
    

    In My QML, it comes to the ListView can say SearchResult.qml

    ListView {
              objectName: "resultlist"
              dataModel: feedsdatamodel
              listItemComponents: [
                ListItemComponent {
                            type: "item"
                            PeopleListItem {
                                name: ListItemData.givenName + ", " + ListItemData.sn
                                role: ListItemData.ExtFunction
                                leftPaddingText: 40
                            }
                        }
               ]
            }
     attachedObjects: [
           // The data model that contains the content of a XML file
            GroupDataModel {
                id: feedsDataModel
                sortingKeys: [
                    "givenName"
                ]
                grouping: ItemGrouping.None
            }
        ]
    

    PeopleListItem.qml

    import bb.cascades 1.0
    
    Container {
        property alias name: titleLabel.text
        property alias role: functionLabel.text
        property alias leftPaddingText: textcontainer.leftPadding
    
        layout: StackLayout {
            orientation: LayoutOrientation.TopToBottom
        }
        preferredWidth: 768
        preferredHeight: 135
        Container {
    
            id: textcontainer
            topPadding: 10
    
            layout: StackLayout {
                orientation: LayoutOrientation.TopToBottom
            }
            Label {
    
                id: titleLabel
                textStyle.base: SystemDefaults.TextStyles.TitleText
                textStyle.color: Color.Black
            }
            Label {
                id: functionLabel
                textStyle.base: SystemDefaults.TextStyles.BodyText
                textStyle.color: Color.Gray
            }
        }
        Divider {
            verticalAlignment: VerticalAlignment.Bottom
        }
    }
    

    This is the function I'm using to display the QML it is called from main.qml and works correctly.

    void PeopleFinder::onSearchClicked() {
        qDebug() << "PeopleFinder::PeopleFinder::onSearchClicked::\t" << "begin";
        qDebug() << "PeopleFinder::PeopleFinder::onSearchClicked::\tfname:"
                << m_fname << "\tlname:" << m_lname;
    
        // Create a network access manager and connect a custom slot to its
        // finished signal
        mNetworkAccessManager = new QNetworkAccessManager(this);
    
        // create a data model with sorting keys for lastname and firstname
        Q_ASSERT(
                connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestFinished(QNetworkReply*))));
    
        //Load the bew QML file of Search from here
        QmlDocument *qml = QmlDocument::create("asset:///SearchResults.qml").parent(
                this);
        qml->setContextProperty("peoplefinder", this);
    
        Page *mypage = qml->createRootObject();
        qml->setParent(mypage);
        qDebug() << "PeopleFinder::PeopleFinder::onSearchClicked::\t s444444";
    
        // Retrieve the activity indicator from QML so that we can start
        // and stop it from C++
    //  mActivityIndicator = mypage->findChild("myIndicator");
    
        // Retrieve the list so we can set the data model on it once
        // we retrieve it
        mListView = mypage->findChild("resultlist");
    
        mNavigator->push(mypage);
    }
    

    Once the page loads in the QML it call the launch request providing c ++ file and once the
    query is completed under function is called with the data. I checked that data are downloaded properly

    void PeopleFinder::requestFinished(QNetworkReply* reply) {
        qDebug() << "PeopleFinder::PeopleFinder::requestFinished::\t"
                << "response received";
        // Check the network reply for errors
        if (reply->error() == QNetworkReply::NoError) {
    
            // Open the file and print an error if the file cannot be opened
            qDebug() << "PeopleFinder::PeopleFinder::requestFinished::\t"
                    << "No error";
    
            // Write to the file using the reply data and close the file
            QByteArray xml = reply->readAll();
            qDebug() << "Data: \n" << xml;
    
            // load the xml data
            XmlDataAccess xda;
            QVariant list = xda.load(xml, "ArrayOfPeople");
    
            qDebug() << "List:::\n" << list;
    
            GroupDataModel *datamodel = (GroupDataModel*)mListView->dataModel();
            // add the data to the model
            datamodel->clear();
            datamodel->insertList(list.value());
            datamodel->setSortingKeys(QStringList() << "givenName" << "sn");
            qDebug() << "PeopleFinder::PeopleFinder::requestFinished::\t"
                    << "Datamodel set size:: " << datamodel->size();
    
            // Set the new data model on the list and stop the activity indicator
    
        } else {
            qDebug() << "\n Problem with the network";
            qDebug() << "\n" << reply->errorString();
        }
    }
    

    But now, the real problem begins as in how to convert QByteArray data type of QVariantList which can be loaded into the datamodel
    I don't want to write the data to the XML file and then pass that as a list his will is very slow, once I move test environment to the production environment.

    Please help me solve this problem

    I got it to work using xml parsing with QXmlStreamReader

  • How to convert the Qbytearray into image in cascades

    Hi guys,.

    How can I convert a Qbytearray in image, so that I can show to imageView.Any the code examples will be useful

    Concerning

    Rakesh Shankar.P

    Thanks for your help, I was able to retrieve image

     QImage swapped;
         qDebug()<<"data"<setImage(image);     container->add(testImage);
    

    Concerning

    Rakesh Shankar.P

  • How to record the QByteArray Image?

    Hello

    How to save picture JPG of QByteArray to BB10 device?

    Thanks a lot before

    QByteArray table;<--- this="" has="" the="" image="" data="" in="" byte="">

    QImage image = QImage::fromData (table, "BMP"); original was bmp for me, I convert it to jpeg format below

    QFile outFile("shared/photos/temp1.jpeg");

    outFile.open (QIODevice::WriteOnly);
    image. Save (& outFile, "JPEG");

    Let me know if it works, I just finished finished written an application that allows a user to sketch and doodle photos with their fingers and it had save function to debug it.

  • QImage Image conversion

    Hi, I have a QImage I want to use an ImageView. What I did was converted into a bb::ImageData and then create an Image using this ImageData. The code is given below.

    QImage imageQ;
    imageQ.load("app/native/assets/images/bg.png");
    imageData = bb::ImageData::fromPixels(imageQ.bits(), bb::PixelFormat::RGBX, canvasWidth, canvasHeight, imageQ.bytesPerLine());
    
    image = ImageView::create().
    image(Image(imageData));
    

    But the problem is that the image is reversed. The original image and the image converting QImage image run this public DropBox folder.

    https://www.dropbox.com/sh/0c1tlan6a1jh0pv/AACDHIvqWTryXA0JjOo0_P-OA

    Try to make a

        imageQ = imageQ.rgbSwapped();
    

    before the line fromPixels.

  • Create a QImage bb::cascades:Image

    Hi, how can we create a QImage from bb::cascades:Image or bb::cascades:ImageData?

    Thank you

    Sorry to bring this element thead dead to life, but you can easily extract data from bb::ImageData using bb::utility:ImageConverter :

    bb::ImageData imageData; // our source imageDataQByteArray encoded = bb::utility::ImageConverter::encode("image/bmp", imageData);QImage image; // destination QImage
    
    if (image.loadFromData(encoded, "BMP")) { // load QImage from encoded QByteArray as BMP streamQImage scaledImage = image.scaled(720, 720, Qt::KeepAspectRatio); // if we wish to scale source image    scaledImage.save("sample.png", "PNG"); // if we wish to save scaled image}
    
  • How to convert the &lt; Contact &gt; QLIST Qstring

    Hello

    I would like to send my contacts from the device to the server using the Soap web service. but the method which who sent the item on the server takes the QString parameter and the contacts which I am retriving are type QLIST then please suggest me a method that converts the QList QString.

    Help, please...

    QString has a constructor that accepts a QByteArray.

  • QByteArray fromHex error.

    Hi all

    I'm usin the QByteArray fromHex function, it works for small chains, but fails to larger.

    any body facing a similar question?

    Kind regards.

    I see only a 20 M byte array, converted into a hexagon of 40 M work of encoding...

    #include 
    #include 
    #include 
    
    int main(int argc, char *argv[]) {
        QByteArray test;
        for (int i = 0; i < 20000000; ++i) {
            test.append(rand());
        }
        QByteArray asHex(test.toHex());
        QString useEvenMoreMemory(asHex);
        QByteArray back(QByteArray::fromHex(useEvenMoreMemory.toLocal8Bit()));
    
        if (test.length() != back.length()) {
            qDebug() << "Size problems...";
        } else {
            bool good = true;
            qDebug() << "Length match";
            for (int i = 0; good && i < test.length(); ++i) {
                if (test[i] != back[i]) {
                    good = false;
                }
            }
    
            qDebug() << "Good" << good;
        }
    
        return 0;
    }
    
  • QByteArray in Json

    How to convert a QByteArray from a JSON response network?

    Check with the function below:

    void GridSample::requestFinished( QNetworkReply * reply){
        QVariantMap dataName;
                if (reply) {
                    if (reply->error() == QNetworkReply::NoError) {
                        const int available = reply->bytesAvailable();
                        if (available > 0) {
                            const QByteArray buffer(reply->readAll());
    
                            bb::data::JsonDataAccess ja;
                            const QVariant jsonva = ja.loadFromBuffer(buffer);
                            const QVariantMap jsonreply = jsonva.toMap();
                            QVariantList data = jsonreply["photos"].toList();
                            foreach(QVariant v, data){
                                dataName["text"]=v.toMap().value("created_at").toString();
                                myGroupModel->insert(dataName);
                            }
                        }
                    } else {
    
                    }
                    reply->deleteLater();
                }
    }
    
  • So with the new update every attachment I get an Outlook user is converted in a winmail.dat file.  How Apple could make a such big screw-up?  Even when I check gmail via apple mail conversion is made, but if I connect to google, the files are

    Why is each attachment outlook, I get in the Mail now converted in a winmail.dat file?  I don't want to go make an app to allow me to open these files - it is something stupid on the part of Apple - please correct!

    Tell Apple - http://www.apple.com/feedback/

Maybe you are looking for

  • Photosmart 7520 does not Mac since Yosemite print

    My 7520 continues to run wireless on my home network to print from a computer laptop Windows 7 and via an iPhone 8 ongoing iOS AirPrint.  But it stopped working with my desktop Mac since installing OS 10.10 Yosemite yesterday. After the installation

  • Installation of 8 GB of RAM in a HP Pavilion

    I bought a Hp Pavilion 2305sl. I want to upgrade the RAM with new RAM device. I have 1 free slot, and the ram I have is called AM1U16BC4P2-B19H. I need 12 GB of RAM and now I have 4 GB. The pc supports the 12 GB of RAM? and what is the name of the mo

  • a fake explorer.exe not causing no office

    When I started my PC today and login, only my document poped place No Desktop (icons and taskbar) and black background I have to manully load the desktop by running explorer.exe then when I'm in the process explorer.exe theres 2 so im not sure theres

  • BlackBerry 10 functions and features can not turn off my Blackberry Protect z10 after changing the password ID.

    My wife's phone was last updated the operating system more recent 10.3.2. I then tried to access a service and found when he asked for the Blackberry ID, we had forgotten the issue of password and user. Then I deleted the ID and set up a new. I can c

  • Fields are disappearing while scrolling

    Hi comrades. I need help with this problem. I did some research but I did not yet find an answer for this. What is happening is that some fields disappear depending on how the screen scrolls. The same screen, with the same fields but different conten