View Full Version : editing a image using QT
qtlearner123
20th April 2012, 11:33
Hi all,
i have this doubt if i have an image in my computer and i access that image (.jpeg or anyother format) using QT program and after accessing the image is it possible for me to edit the image using QT program? i.e can i modify the image as per my needs dynamically is it possible??
thanks in advance,
regards,
satya
wysota
20th April 2012, 13:13
You can access each pixel of the image using QImage API.
qtlearner123
24th April 2012, 09:41
hi,
thank you very much for the reply, i am going through the documentation of QImage, but i have one small question suppose i have one image say image1 and i want to remove some part of the image1 and replace it with another image2 can i achieve the task it, based upon your feedback i can make sure i am not going in the wrong direction.
thanks and regards,
satya
wysota
24th April 2012, 13:57
You have to open a painter on the image and use QPainter::drawImage() to draw the part that is to replace old content.
qtlearner123
24th April 2012, 15:57
you are so precise and to the point.
thanks and regards,
satya
qtlearner123
25th April 2012, 09:40
Hi,
iam trying to take image1 and on image1 at some portion i want to overwrite image2, i did with the following code.
#include <QtGui/QApplication>
#include <QLabel>
#include <QGraphicsView>
#include <stdio.h>
#include <QRect>
#include <QPainter>
#include "lines1.h"
QImage firstImage;
QImage secondImage;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Lines window;
firstImage.load(":/images/myImage1.png");
secondImage.load(":/images/myImage2.png");
window.show();
return a.exec();
}
void Lines::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QRect rect1,rect2;
rect1.setX(0);
rect1.setY(0);
rect1.setHeight(600);
rect1.setWidth(700);
rect2.setX(500);
rect2.setY(200);
rect2.setHeight(50);
rect2.setWidth(50);
painter.drawImage(rect1, firstImage);
painter.drawImage(rect2,secondImage);
}
my questions are
1. Is it the correct way of doing it or any better method is available to achieve the same?
2. suppose i want to overwrite at a particular part of image how to know the coordinates of those points? right now i am using trial and error method?
thanks in advance,
regards,
satya
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.