You are not logged in.

1

Friday, September 17th 2004, 3:03am

how to zoom a png image?

i have read a png into a QPixmap.

but i don't know how to zoom in or zoom out the pixmap.

is there any method to figure out how to zoom a image

This post has been edited 1 times, last edit by "commonone" (Sep 17th 2004, 3:04am)


e8johan

Professional

  • "e8johan" is male

Posts: 1,195

Location: Sweden

  • Send private message

2

Friday, September 17th 2004, 6:23am

RE: how to zoom a png image?

Look at the QjPixmapView of the JSeries.

Thomas

Trainee

  • "Thomas" is male

Posts: 108

Location: Socorro, New Mexico, USA

Occupation: Software Engineer

  • Send private message

3

Friday, September 17th 2004, 10:06am

RE: how to zoom a png image?

Hi e8johan,

zooming a QPixmap is easy.

1) QPixmap *myPixmap contains your image.
2) Do the following:

QPainter p;
p.begin(Zoom); // The QWidget where the zoomed QPixmap is drawn to.
p.scale(zoom_factor,zoom_factor);
p.drawPixmap(0,0,*myPixmap,x,y,width,height);
p.end();
There are 10 types of people in the world. Those that understand binary numbers and those that don't.

This post has been edited 1 times, last edit by "Thomas" (Sep 17th 2004, 10:07am)


e8johan

Professional

  • "e8johan" is male

Posts: 1,195

Location: Sweden

  • Send private message

4

Friday, September 17th 2004, 10:31am

RE: how to zoom a png image?

Quoted

Originally posted by Thomas
Hi e8johan,

zooming a QPixmap is easy.


I know, but the JSeries provides a widget for showing a zoomable image. It also handles the case when the image is too large (by showing scrollbars).

5

Friday, September 17th 2004, 10:54am

RE: how to zoom a png image?

You could also load the png into a QImage first. There you have scale and smooth scale functions to do the zooming. After you zoomed it to the desired size, convert the image to a pixmap.

Especially the smooth scaling function might result in better quality (but it is rather slow).

Rainer

Thomas

Trainee

  • "Thomas" is male

Posts: 108

Location: Socorro, New Mexico, USA

Occupation: Software Engineer

  • Send private message

6

Friday, September 17th 2004, 10:56am

RE: how to zoom a png image?

O.k., you are right. I needed the zooming stuff for an application which should display astronomical fits files. I never made it to the state where I could zoom into the image and scroll around. Therefore I just downloaded your toolset and will have a deeper look into it. :-) Thank's a lot!
There are 10 types of people in the world. Those that understand binary numbers and those that don't.

n_ezdiani

Trainee

  • "n_ezdiani" is female

Posts: 47

Location: Malaysia

  • Send private message

7

Tuesday, October 26th 2004, 8:31am

hi johan,

i would like to ask you about the the visiblity of a magnified pixmap...what i mean is, let say the viewport size is smaller than the magnified pixmap, why cant i scroll the rest of the part that havent shown? i mean when i scroll it , the previous shown magnified part will be erased when it's not visible anymore ... i thought the reason we use scroller is to scroll to see the hidden parts...but here it's as if it only paints on the visible area only & the rest is missing, so when i scroll i can see the map as if it had been cut...could you help me with that? i hope u understand what im trying to tell u here...

btw i've looked at your jseries tool but I want to try to do it myself ...so could you help me please..

e8johan

Professional

  • "e8johan" is male

Posts: 1,195

Location: Sweden

  • Send private message

8

Tuesday, October 26th 2004, 11:43am

Quoted

Originally posted by n_ezdiani
i would like to ask you about the the visiblity of a magnified pixmap...what i mean is, let say the viewport size is smaller than the magnified pixmap, why cant i scroll the rest of the part that havent shown?...

btw i've looked at your jseries tool but I want to try to do it myself ...so could you help me please..



It is very to hard to tell what is wrong without any code. Look at the QjPixmapView. There, the viewport is resized when the zoom factor changes. That is how you do it.

Krasu

Unregistered

9

Tuesday, October 26th 2004, 12:22pm

I think the best way is to use QImage::scale || QImage::smoothScale, anyway, QPixmap can be translated to QImage (see doc.) and back to QPixmap.

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

10

Tuesday, October 26th 2004, 5:05pm

Quoted

Originally posted by Krasu
I think the best way is to use QImage::scale || QImage::smoothScale, anyway, QPixmap can be translated to QImage (see doc.) and back to QPixmap.


It's not worth it... the conversions are slow. Better than that is to use QCanvas, QCanvasView, QCanvasSprite and QWMatrix :)

e8johan

Professional

  • "e8johan" is male

Posts: 1,195

Location: Sweden

  • Send private message

11

Wednesday, October 27th 2004, 5:55am

Quoted

Originally posted by wysota

Quoted

Originally posted by Krasu
I think the best way is to use QImage::scale || QImage::smoothScale, anyway, QPixmap can be translated to QImage (see doc.) and back to QPixmap.


It's not worth it... the conversions are slow. Better than that is to use QCanvas, QCanvasView, QCanvasSprite and QWMatrix :)

Or OpenGL, to get hardware acceleration.

n_ezdiani

Trainee

  • "n_ezdiani" is female

Posts: 47

Location: Malaysia

  • Send private message

12

Wednesday, October 27th 2004, 6:36am

Quoted

It is very to hard to tell what is wrong without any code. Look at the QjPixmapView. There, the viewport is resized when the zoom factor changes. That is how you do it.


These are some of the codes,

Quoted

Map::Map( QWidget* parent, const char* name, WFlags fl )
: QWidget( parent, name, fl )
{
.....
ms = new MapScroll(this, "ms");
.....
......
}

MapScroll::MapScroll(QWidget* parent, const char* name)
: QScrollView(parent,"zoom"),bg("images/map.png")
{
bg.load("images/map.png");
setGeometry (20,10,200,260);
setMouseTracking (TRUE);
setDragAutoScroll (TRUE);
setVScrollBarMode( QScrollView::Auto );
setHScrollBarMode( QScrollView::Auto );
};

void MapScroll:: contentsMouseReleaseEvent( QMouseEvent * e)
{
contentsToViewport(e->x(), e->y(),x,y);
qDebug("value x = %d", x);
qDebug("value y = %d", y);

viewport()->update();

}

void MapScroll::drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph)
{
qWarning("inside drawContents");

/* this part is not occurate yet!!*/
if (x<=viewport()->width()/2)
w = 0;
else
w = x - viewport()->width()/2;

if (y<=viewport()->height()/2)
h = 0;
else
h = y - viewport()->height()/2;
/*=========================*/

p->scale(cbono+1,cbono+1);
resizeContents(bg.width()*cbono+1,bg.height()*cbono+1);
p->drawPixmap(0,0,bg,w,h,-1,-1);

}

by the way, cbono is the zoom option from the combobox..

so as i said earlier, my problem is to view the hidden magnified pixmap... i've tried using resizeContents, yes the size of the viewport got bigger but the pixmap is still not painted full...only on the visible area of the viewport... and then when i scroll down, it's missing too since it's not on the visible area anymore... am i do it correctly?

n_ezdiani

Trainee

  • "n_ezdiani" is female

Posts: 47

Location: Malaysia

  • Send private message

13

Wednesday, October 27th 2004, 8:53am

by the way johan, ive tried your tool (QjPixmapView), and ive noticed that the viewport is smaller than the pixmap which isexactly like my case here ..how did you manage to make the pixmap or should i say repaint the pixmap when the scroller is used? is there any Qscrollview members that i can use to make the pixmap stay there when using the scroller? please help...thanx

-nani-

e8johan

Professional

  • "e8johan" is male

Posts: 1,195

Location: Sweden

  • Send private message

14

Wednesday, October 27th 2004, 10:36am

Well, the JSeries uses the following code to draw the contents:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
void QjPixmapView::drawContents( QPainter *p, int clipx, int clipy, int clipw, int cliph )
{
	p->setBrush( Qt::darkGray );
	p->setPen( Qt::darkGray );
	p->drawRect( clipx, clipy, clipw, cliph );

	if( !pd->pm.isNull() )
	{
		p->setClipping( false );
		int left, top;

		if( viewport()->width() <= pd->pm.width()*pd->zoom )
			left = 0;
		else
			left = (int)(viewport()->width()-pd->pm.width()*pd->zoom)/2;

		if( viewport()->height() <= pd->pm.height()*pd->zoom )
			top = 0;
		else
			top = (int)(viewport()->height()-pd->pm.height()*pd->zoom)/2;

		if( pd->zoom != 1.0 )
		{
			p->translate( -left*(pd->zoom-1.0), -top*(pd->zoom-1.0) );
			p->scale( pd->zoom, pd->zoom );
		}

		p->drawPixmap( left, top, pd->pm );

		if( pd->zoom != 1.0 )
			p->resetXForm();

		p->setPen( Qt::black );
		p->setBrush( Qt::NoBrush );
		p->drawRect( left-1, top-1, (int)(pd->pm.width()*pd->zoom+2), (int)(pd->pm.height()*pd->zoom+2) );
	}
}


The code would really benefit from smarter painting of the background (draw around the image) and some double buffering of the zoomed pixmap.

n_ezdiani

Trainee

  • "n_ezdiani" is female

Posts: 47

Location: Malaysia

  • Send private message

15

Friday, October 29th 2004, 4:33am

hi johan,

ive settled the problem with the missing pixmap...thanx...

but now, i have a question to ask you regarding the scrollbar...it's like this.... i have a horizontal & vertical scrollbars and besides using the scrollbars, i want to pan the pixmap by clicking on the pixmap... so i tried using center(int,int) or ensureVisible(int,int) so that the clicked point can be centered(visible)... at first, when i click, it can pan the pixmap to the left, right, top or bottom but somehow after a few clicks, the scrollbars keep on increasing to the right and to the bottom respectively eventhough i click to the left or top... seems like after panning to the middle area of the pixmap the pixmap can only be panned to the right and bottom only...it doesnt want to scroll back to the left nor the top...

btw, is there any other way to make the clicked point visible other than center(int,int) and ensureVisible(int,int)...

actually i just add the center(int,int) like this, i didnt change anything else... am i doing it right johan?

Quoted


p->scale(cbono+1,cbono+1);
resizeContents(bg.width()*cbono+1,bg.height()*cbono+1);
p->drawPixmap(0,0,bg,w,h,-1,-1);
center (x,y); // OR ensureVisible(int,int)

This post has been edited 1 times, last edit by "n_ezdiani" (Oct 29th 2004, 4:41am)


e8johan

Professional

  • "e8johan" is male

Posts: 1,195

Location: Sweden

  • Send private message

16

Friday, October 29th 2004, 7:00am

Quoted

Originally posted by n_ezdiani
but now, i have a question to ask you regarding the scrollbar...it's like this.... i have a horizontal & vertical scrollbars and besides using the scrollbars, i want to pan the pixmap by clicking on the pixmap... so i tried using center(int,int) or ensureVisible(int,int) so that the clicked point can be centered(visible)... at first, when i click, it can pan the pixmap to the left, right, top or bottom but somehow after a few clicks, the scrollbars keep on increasing to the right and to the bottom respectively eventhough i click to the left or top... seems like after panning to the middle area of the pixmap the pixmap can only be panned to the right and bottom only...it doesnt want to scroll back to the left nor the top...
[/qoute]

This sounds really odd, but it is very hard to tell what has gone wrong from your description.

Quoted

Originally posted by n_ezdiani
btw, is there any other way to make the clicked point visible other than center(int,int) and ensureVisible(int,int)...
[/qoute]

You could always calculate new slider values and setting them manually...

n_ezdiani

Trainee

  • "n_ezdiani" is female

Posts: 47

Location: Malaysia

  • Send private message

17

Monday, November 1st 2004, 7:03am

hi johan,

i'm still stucked with the scroller. in your jseries tool, does it use scrollbars and still can pan the pixmap? in my case, if i want to use the scrollbars, i cant pan the pixmap... as ive explained it to u before, when i the scrollbars has reached to the left & to the bottom respectively, it stucked there... please help me on how to pan the pixmap by mouseclick and at the same time can use the scrollbars... by the way, can i combine these two features together?

This post has been edited 1 times, last edit by "n_ezdiani" (Nov 1st 2004, 7:18am)


e8johan

Professional

  • "e8johan" is male

Posts: 1,195

Location: Sweden

  • Send private message

18

Monday, November 1st 2004, 7:47am

JSeries uses a QScrollView. The features that you request should be possible to combine, but it is very hard to tell what goes wrong in your case.

n_ezdiani

Trainee

  • "n_ezdiani" is female

Posts: 47

Location: Malaysia

  • Send private message

19

Monday, November 1st 2004, 7:54am

hi johan,

i'm using QScrollView too.. do you provide panning in your jseries? if you do, what members did you use for panning the pixmap and make it centered?

e8johan

Professional

  • "e8johan" is male

Posts: 1,195

Location: Sweden

  • Send private message

20

Monday, November 1st 2004, 9:25am

Quoted

Originally posted by n_ezdiani
i'm using QScrollView too.. do you provide panning in your jseries? if you do, what members did you use for panning the pixmap and make it centered?


I support no other panning than the one that you get from the scrollbars around the scroll view.