×

Discussion Board

Results 1 to 14 of 14

Thread: image bmp file

  1. #1
    Regular Contributor
    Join Date
    Jul 2011
    Posts
    100

    image bmp file

    hi,
    I want to be an image with a arrya data
    I keep it in a bmp file.
    My code is as follows:
    ...........
    connect( socket, SIGNAL(readyRead()), this, SLOT(recv()));
    .......
    void cliente::recv()
    {
    message.clear();
    message.append(socket->readAll());
    emit newMessage(this, "<command>", QString(message));
    cont=cont+1;
    if(img==true){
    cont=cont+1;
    if(cont>5){
    mesage.push_back(message);
    }
    data come from a TCP connection and is an image taken by a camera.
    How I can save a. Bmp file named c: / pic3.bmp?

    and no means fromimagedata * of the following expression:
    QImage image(fromimagedata *,640, 480,QImage::Format_RGB16);

    thanks

  2. #2
    Regular Contributor
    Join Date
    Jul 2011
    Posts
    100

    Re: image bmp file

    No one knows form a bmp image with an array of data (save to a file image.bmp)?

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    29

    Re: image bmp file

    if you receive it from network in bmp format then open a new file and write the received data to it.

  4. #4
    Regular Contributor
    Join Date
    Jul 2011
    Posts
    100

    Re: image bmp file

    One thing that you like that?
    it does not work

    QFile file("c:/foto2.bmp");
    file.open(QIODevice::ReadWrite);
    file.write();
    file.close();*/

  5. #5
    Super Contributor
    Join Date
    Mar 2008
    Posts
    1,481

    Re: image bmp file

    Hi,

    Try this code (put it in a simple project and call it from some where )

    void MyImageClass::HandleImage()
    {
    QImage image("c:\\data\\images\\test.png");
    QByteArray ba;
    QBuffer buf(&ba);
    bool b= image.save(&buf, "BMP");
    qDebug() << b;

    QByteArray compressed = qCompress(ba, 1); // better just open file with QFile, load data, compress and toHex?
    QByteArray hexed = compressed.toHex();
    // save to a file
    QString str(hexed);
    QFile f("c:\\data\\images\\test.hex");
    if (f.exists())
    f.remove();
    if (f.open(QFile::WriteOnly))
    {
    f.write(str.toLatin1()); // holds only 0..f nothing special.
    }
    else
    {
    qDebug() << "failed to open file \"test.hex\"";
    }
    f.close();
    ////----------
    if (f.open(QFile::ReadOnly))
    {
    qDebug() << "File open";
    QByteArray read = f.readAll();
    f.close();
    QString rStr = QString::fromLatin1(read.data(), read.size());
    if (rStr != str)
    qDebug() << "Writed and read two different hexed strings.";
    QByteArray readCompressed = QByteArray::fromHex(rStr.toAscii());
    if (readCompressed != compressed)
    qDebug() <<"bytes before hexing and dehexing _is_ different.";
    QByteArray readDecompressed = qUncompress(readCompressed);
    if (readDecompressed != ba)
    {
    qDebug() << "bytes before and after compressions are different.";
    }
    QImage readImg;
    readImg.loadFromData(readDecompressed);
    if (readImg.isNull())
    {
    qDebug() << "The image is null. Something failed.";
    }
    else
    {
    qDebug() << "The image finally OK";
    readImg.save("c:\\data\\images\\test.bmp");
    }
    }
    else
    {
    qDebug() << "failed to open test.hex file for reading";
    }
    }

    for Symbian create a test.png file and put it same folder with as the project. when you run you see test.png is located in this folder c:\data\images\ , c:\data\images\test.hex (hex data ) and c:\data\images\test.bmp has been created by this code.

    In pro file you need to have similar code

    symbian {
    symbian:TARGET.UID3 = 0xE06BB94C
    myFiles.sources = test.png
    myFiles.path = c:\data\images
    DEPLOYMENT += myFiles
    }


    Hope this help, and hope course there are plenty of information in Qt pages like http://doc.qt.nokia.com/4.7/qimage.html

  6. #6
    Regular Contributor
    Join Date
    Jul 2011
    Posts
    100

    Re: image bmp file

    I only creates the file. hex archivo.bmp not believe me

    the PRO should I paste everything as is here?

    symbian {
    symbian:TARGET.UID3 = 0xE06BB94C
    myFiles.sources = test.png
    myFiles.path = c:\data\images
    DEPLOYMENT += myFiles
    }

    thanks mahbub

  7. #7
    Regular Contributor
    Join Date
    Jul 2011
    Posts
    100

    Re: image bmp file

    bmp file does not create

  8. #8
    Super Contributor
    Join Date
    Mar 2008
    Posts
    1,481

    Re: image bmp file

    hi,

    You can follow the logs if all goes OK
    And you should have test.png in the same folder where is your project is. It will convert the test.png to hex file and finally it will convert to bmp file.
    Now if you don't have the original file then nothing will work.
    I tested this code to C7 Belle SW and it looks OK for me. In the c:\data\images folder there are 3 files, test.png, test.hex and test.bmp.
    Could you tell what phone you are using for this?

  9. #9
    Regular Contributor
    Join Date
    Jul 2011
    Posts
    100

    Re: image bmp file

    need this
    How I can do this in qt for symbian?
    matlab code:
    % connect to server socket
    fprintf('Trying to connect to port 2002\n');
    con2002=tcpip('158.42.55.161',2002,'InputBufferSize',640*480,'ByteOrder','littleEndian');
    fopen (con2002);
    fprintf('Connected. Put in corn kernels! \n');
    Iunfold=0;
    while(1)
    % wait for data
    while (con2002.BytesAvailable == 0) end;
    close all;
    % read incoming data
    imagen = uint8(fread(con2002,[640 480],'uint8')');
    % write result to bmp
    imwrite(imagen,'img7.bmp');
    % bayer 2 rgb function
    rgbcolor = demosaic(imagen,'rggb');
    imshow(rgbcolor);
    ck=input('Accept picture? Y/N [Y]:','s');
    if((ck=='n'))
    % don't do anything
    else
    mia_ddrct(coeff, rgbcolor);
    end;

    ck=input('Continue testing? Y/N [Y]:','s');
    if(ck=='n')
    break;
    end;
    end;


    % closing connections
    while (~(con2002.BytesAvailable == 0))
    imagen = uint8(fread(con2002,[640 480],'uint8')');
    end;

    fprintf('Disconnecting from server port 2002\n');
    fclose (con2002);
    fprintf(con23,'%s','\n');
    respuesta = fscanf(con23,'%s',30);
    pause(2);
    fprintf(con23,'%s','\n');
    pause(1);
    fprintf('Disconnecting telnet connection\n');
    fclose(con23);
    fprintf('\Connection terminated. However, Smart camera might need to be reset!\n');
    end

  10. #10
    Super Contributor
    Join Date
    Mar 2008
    Posts
    1,481

    Re: image bmp file

    Sorry Friend !
    Long long time ago I was doing something with Matlab/MatchCad :-)
    You need to start with Qt tutorial QtNetwork

  11. #11
    Regular Contributor
    Join Date
    Jul 2011
    Posts
    100

    Re: image bmp file

    Sorry folks,
    without matlab, how I can use a QByteArray to form an RGB image?
    An example would be:

    image.loadFromData(buffer->buffer()); // Load the image from the receive buffer

    for(int i =315; i < 361; ++i)
    for(int j =235; j < 461; ++j) {
    QRgb c = image.pixel(i,j);
    int r = qRed(c);
    int g = qGreen(c);
    int b = qBlue(c);

    // r=gamma[r];

    image.setPixel(i,j,qRgb(r,g,b));

    Can you use a pixmap? Or I can just use a picture?

    // r=gamma[r]; that meaning is not

    thanks

  12. #12
    Super Contributor
    Join Date
    Mar 2008
    Posts
    1,481

    Re: image bmp file

    Hi,
    What are you trying to achieve? I mean could you describe your use case one more time? If you use Qt and Qt supported mobile phone then post # 5 should solve your problem.

  13. #13
    Regular Contributor
    Join Date
    Jul 2011
    Posts
    100

    Re: image bmp file

    my phone is nokia 5800, and am trying to do a telnet client that connects a camera that is networked, I have it connected to the camera, and send me pictures achievement, but fails to form and display, I need to form a bmp image with QByteArray data and I need please do it with RGB pixel by pixel.
    symbian 4.3.3

  14. #14
    Super Contributor
    Join Date
    Mar 2008
    Posts
    1,481

    Re: image bmp file

    Hi,

    -So you are receiving all the data byte from remote device and not able to form the QImage? (Can you try to test the code in post #5 in your device and compare with your code)
    -What is Symbian 4.3.3?

Similar Threads

  1. puting a png image with other image data in the file
    By TacB0sS in forum Mobile Java General
    Replies: 17
    Last Post: 2009-12-07, 11:03
  2. Replies: 2
    Last Post: 2008-09-25, 06:53
  3. Replies: 3
    Last Post: 2004-07-21, 12:09

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×