Sender::Sender(int no)
{
a = 0;
img_block = 0;
block_size = 20;
num = no;
if(num == 1)
image
= new QImage("C:/Users/Public/Pictures/Sample Pictures/Desert.jpg" );
if( image->isNull() )
qDebug() << "Failed to open test.jpg" ;
timer->isSingleShot();
QTimer::singleShot(1000,
this,
SLOT(broadcastLine
()) );
connect( this, SIGNAL(done()), this, SLOT(broadcastLine()) );
}
void Sender::broadcastLine()
{
QByteArray buffer
( block_size
+3*image
->width
(),
0 );
stream << (quint16)image->width() << (quint16)image->height();
stream << img_block;
for( int x=0; x<image->width(); ++x )
{
for(int y=block_size*a; y <block_size+(block_size*a);y++)
{
if( y < image->height())
{
QRgb rgb = image->pixel( x, y );
stream << (quint8)qRed( rgb ) << (quint8)qGreen( rgb ) << (quint8)qBlue( rgb );
}
else
{
img_block = y = a = 0;
img_block = -block_size;
}
}
}
if(num==1)
socket
->writeDatagram
( buffer,
QHostAddress::Broadcast,
9988 );
img_block = img_block + block_size;
a++;
emit done();
}
Sender::Sender(int no)
{
socket = new QUdpSocket( this );
a = 0;
img_block = 0;
block_size = 20;
num = no;
if(num == 1)
image = new QImage("C:/Users/Public/Pictures/Sample Pictures/Desert.jpg" );
if( image->isNull() )
qDebug() << "Failed to open test.jpg" ;
QTimer *timer = new QTimer( this );
timer->isSingleShot();
QTimer::singleShot(1000, this, SLOT(broadcastLine()) );
connect( this, SIGNAL(done()), this, SLOT(broadcastLine()) );
}
void Sender::broadcastLine()
{
QByteArray buffer( block_size+3*image->width(), 0 );
QDataStream stream( &buffer, QIODevice::WriteOnly );
stream.setVersion( QDataStream::Qt_5_5 );
stream << (quint16)image->width() << (quint16)image->height();
stream << img_block;
for( int x=0; x<image->width(); ++x )
{
for(int y=block_size*a; y <block_size+(block_size*a);y++)
{
if( y < image->height())
{
QRgb rgb = image->pixel( x, y );
stream << (quint8)qRed( rgb ) << (quint8)qGreen( rgb ) << (quint8)qBlue( rgb );
}
else
{
img_block = y = a = 0;
img_block = -block_size;
}
}
}
if(num==1)
socket->writeDatagram( buffer, QHostAddress::Broadcast,9988 );
img_block = img_block + block_size;
a++;
emit done();
}
To copy to clipboard, switch view to plain text mode
Bookmarks