mismael85
28th March 2010, 13:23
hi every body;
i am facing a problem in drawing Image in a QLabel
i used the follwoing code to draw the image
m_pQiblaImage = new QImage(QSize(289,289),QImage::Format_ARGB32_Premul tiplied);
m_pPainter = new QPainter(m_pQiblaImage);
m_pPainter->setCompositionMode(QPainter::CompositionMode_Sourc eOver);
m_pPainter->translate(144.5,144.5);
m_pPainter->save();
//Compass background
QString fileName(IMAGES_PATH);
fileName.append("compass.png");
QImage source(fileName);
m_pPainter->rotate(360 - angleToNorth);
m_pPainter->drawImage(-144.5,-144.5,source);
// m_pPainter->restore();
//m_pPainter->save();
fileName.clear();
fileName.append(IMAGES_PATH);
fileName.append("Qibla-needle.png");
source.load(fileName);
m_pPainter->rotate(NormalizeTo360(m_qibla-90/*+ (360-angleToNorth)*/));
m_pPainter->drawImage(-114.5,-20.5,source);
// m_pPainter->restore();
//m_pPainter->save();
if(QTime::currentTime() < m_prayerTimes[4] && QTime::currentTime() > m_prayerTimes[1] && m_gpsMode != 2/*ON*/)
{
//qDebug()<<"current time is "<< QTime::currentTime();
//qDebug()<<"prayer Time = "<<m_prayerTimes[5];
fileName.clear();
fileName.append(IMAGES_PATH);
fileName.append("sun-needle.png");
source.load(fileName);
m_pPainter->rotate(360 - NormalizeTo360(getSunQiblaDir(m_CityInfo.longitude , m_CityInfo.latitude) * DPR)/*+(360 - angleToNorth)*/);
m_pPainter->drawImage(-114.5,-20.5,source);
m_pPainter->restore();
m_pPainter->save();
}
else
{
m_pPainter->restore();
m_pPainter->save();
}
fileName.clear();
fileName.append(IMAGES_PATH);
fileName.append("Compass-needle.png");
source.load(fileName);
m_pPainter->rotate(360 - angleToNorth);
m_pPainter->drawImage(-17.5,-106.5,source);
m_pPainter->restore();
m_pPainter->save();
fileName.clear();
fileName.append(IMAGES_PATH);
fileName.append("compass-center.png");
source.load(fileName);
m_pPainter->drawImage(-10.5,-10.5,source);
m_pPainter->restore();
m_pPainter->save();
fileName.clear();
fileName.append(IMAGES_PATH);
fileName.append("compass-glass.png");
source.load(fileName);
m_pPainter->drawImage(-144.5, -144.5,source);
m_pPainter->end();
ui->compass->setPixmap(QPixmap::fromImage(*m_pQiblaImage));
delete m_pQiblaImage;
m_pQiblaImage=NULL;
delete m_pPainter;
m_pPainter =NULL;
update(47, 33, 289, 289);
and i get the follwong result
http://i43.tinypic.com/dpbp1j.png
the compass image is a transparent PNG , the blue color should not be displayed because the part that contain blue color are in fact transparent so why it is displayed in blue rather than transparent?
what is wrong? please help me to find a solution to this problem
i am facing a problem in drawing Image in a QLabel
i used the follwoing code to draw the image
m_pQiblaImage = new QImage(QSize(289,289),QImage::Format_ARGB32_Premul tiplied);
m_pPainter = new QPainter(m_pQiblaImage);
m_pPainter->setCompositionMode(QPainter::CompositionMode_Sourc eOver);
m_pPainter->translate(144.5,144.5);
m_pPainter->save();
//Compass background
QString fileName(IMAGES_PATH);
fileName.append("compass.png");
QImage source(fileName);
m_pPainter->rotate(360 - angleToNorth);
m_pPainter->drawImage(-144.5,-144.5,source);
// m_pPainter->restore();
//m_pPainter->save();
fileName.clear();
fileName.append(IMAGES_PATH);
fileName.append("Qibla-needle.png");
source.load(fileName);
m_pPainter->rotate(NormalizeTo360(m_qibla-90/*+ (360-angleToNorth)*/));
m_pPainter->drawImage(-114.5,-20.5,source);
// m_pPainter->restore();
//m_pPainter->save();
if(QTime::currentTime() < m_prayerTimes[4] && QTime::currentTime() > m_prayerTimes[1] && m_gpsMode != 2/*ON*/)
{
//qDebug()<<"current time is "<< QTime::currentTime();
//qDebug()<<"prayer Time = "<<m_prayerTimes[5];
fileName.clear();
fileName.append(IMAGES_PATH);
fileName.append("sun-needle.png");
source.load(fileName);
m_pPainter->rotate(360 - NormalizeTo360(getSunQiblaDir(m_CityInfo.longitude , m_CityInfo.latitude) * DPR)/*+(360 - angleToNorth)*/);
m_pPainter->drawImage(-114.5,-20.5,source);
m_pPainter->restore();
m_pPainter->save();
}
else
{
m_pPainter->restore();
m_pPainter->save();
}
fileName.clear();
fileName.append(IMAGES_PATH);
fileName.append("Compass-needle.png");
source.load(fileName);
m_pPainter->rotate(360 - angleToNorth);
m_pPainter->drawImage(-17.5,-106.5,source);
m_pPainter->restore();
m_pPainter->save();
fileName.clear();
fileName.append(IMAGES_PATH);
fileName.append("compass-center.png");
source.load(fileName);
m_pPainter->drawImage(-10.5,-10.5,source);
m_pPainter->restore();
m_pPainter->save();
fileName.clear();
fileName.append(IMAGES_PATH);
fileName.append("compass-glass.png");
source.load(fileName);
m_pPainter->drawImage(-144.5, -144.5,source);
m_pPainter->end();
ui->compass->setPixmap(QPixmap::fromImage(*m_pQiblaImage));
delete m_pQiblaImage;
m_pQiblaImage=NULL;
delete m_pPainter;
m_pPainter =NULL;
update(47, 33, 289, 289);
and i get the follwong result
http://i43.tinypic.com/dpbp1j.png
the compass image is a transparent PNG , the blue color should not be displayed because the part that contain blue color are in fact transparent so why it is displayed in blue rather than transparent?
what is wrong? please help me to find a solution to this problem