×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Jul 2011
    Posts
    100

    please help grey scale image

    Hi, I like to make a grayscale image, and I can not do it, I have the program and was wondering if it is correct.
    thank you very much.

    program.

    #include "cliente.h"
    #include <iostream>
    #include <QBuffer>
    #include <QImage>
    #include <QFile>
    #include <math.h>
    #include <QLabel>
    #include <QPixmap>
    #include <QWidget>
    #include <QLayout>
    #include <QVBoxLayout>
    #include <QVector>
    #include <QColor>
    #include<QRgb>
    #include <QImageWriter>
    #include<QTimer>

    bool img=false;
    int cont=0;
    QFile archivo;


    cliente::cliente()
    {

    socket = new QTcpSocket(this);

    connect( socket, SIGNAL(connected()), this, SLOT(conectado()));
    connect( socket, SIGNAL(readyRead()), this, SLOT(recv()));
    connect( socket, SIGNAL(disconnected()), this, SLOT(disconnect()));
    connect( socket, SIGNAL(error(QAbstractSocket::SocketError)),
    this, SLOT(displayError(QAbstractSocket::SocketError)));

    this->estaConectado =false;
    }
    void cliente::recv()
    {
    message.clear();
    message.append(socket->readAll());
    emit newMessage(this, "<command>", QString(message));
    cont=cont+1;
    if(img==true){

    leeimagen(message);
    }


    }

    void cliente::conectarse(QString host, int port)
    {
    this->socket->abort();
    this->socket->connectToHost(host, port);
    }

    void cliente::conectado()
    {
    this->sendMessage(" \n\r");

    emit connected(this, "<command>");
    this->estaConectado=true;
    }

    void cliente::sendMessage(QString msg)
    {

    if (socket->isValid())
    socket->write(msg.toAscii());

    }
    void cliente::aTrue(){img=true;}

    void cliente::sendcabecera(QString host,int port )
    {
    static const char mydata[] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x80, 0x02, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00
    };

    QByteArray data = QByteArray::fromRawData(mydata, sizeof(mydata));
    this->socket->connectToHost( host, port);
    this->socket->write(data);

    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(aTrue()));
    timer->start(2);


    }

    void cliente::sendArchivo(QByteArray byteArray)
    {

    if (socket->isValid())
    socket->write(byteArray);
    }



    void cliente::leeimagen(QByteArray bytesReceived)
    {
    QBuffer* buffer = new QBuffer(&bytesReceived, this);
    QImage im(200, 200, QImage::Format_RGB888) ;
    QImage im2(200, 200,QImage::Format_RGB888);
    im.loadFromData(bytesReceived)




    for(int i=0; i<200; i++)
    {

    for(int j=0; j<200; j++)
    {
    int pixl = im.pixel(i,j);
    int pix = (int)qGray(pixl);
    im2.setPixel(i,j, qGray(pix));


    }

    }



    //return image.convertToFormat(f);







    emit imageReceived(im2);
    qDebug() <<bytesReceived.data();
    return;
    }

    void cliente::disconnect()
    {

    this->estaConectado =false;
    this->socket->close();
    emit disconnected(this, "<command>");
    img=false;
    cont=0;

    }

    void cliente::displayError(QAbstractSocket::SocketError socketError)
    {
    switch (socketError)
    {
    case QAbstractSocket::RemoteHostClosedError:
    break;
    case QAbstractSocket::HostNotFoundError:
    emit ConnectionError(this, tr("Conection Client"),
    tr("The host was not found. Please check the "
    "host name and port settings."));
    break;
    case QAbstractSocket::ConnectionRefusedError:
    emit ConnectionError(this, tr("Conection Client"),
    tr("The conection was refused by the peer. "
    "Make sure the server is running, "
    "and check that the host name and port "
    "settings are correct."));
    break;
    default:
    emit ConnectionError(this, tr("Conection Client"),
    tr("The following error occurred: %1.")
    .arg(socket->errorString()));
    }
    }

  2. #2
    Registered User
    Join Date
    Jul 2008
    Posts
    90

    Re: please help grey scale image

    Nobody _should_ give you any advice about making a grayscale image when you just post an obscure http code listing that mostly has no relevance whatsoever to grayscale images... Try again, with an actual focused _question_ and just include the input data from which you wish to create the grayscale image.

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

    Re: please help grey scale image

    I do not understand your answer, all we want is to see because I can not form the image, because only with a square black and gray striped.
    thank you very much

Similar Threads

  1. How to scale a background image using Polish
    By tavez04 in forum Mobile Java General
    Replies: 3
    Last Post: 2009-11-06, 10:42
  2. Load and scale image very slow in 9.1
    By amfat in forum Symbian
    Replies: 3
    Last Post: 2009-07-25, 16:59
  3. Replies: 1
    Last Post: 2009-05-24, 03:21
  4. error=4 when try to scale the image
    By sandy_zeng in forum Symbian
    Replies: 3
    Last Post: 2007-10-28, 14:27
  5. How to disable scale down of image in MMS?
    By mozat in forum General Messaging
    Replies: 1
    Last Post: 2002-12-02, 06:07

Posting Permissions

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