473,395 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Zooming and panning large images

Hi there,
I am currently writing an application where one inspects images and
annotates certain features. Thus, one has to zoom in (4x) and pan around. The
features are marked with little red rectangles.The images are 2048x2048
pixels.

It seems that I can find no efficient way to implement both zooming and
panning.

At present I have a panel with autoscroll set to true inside which there is
a pictureBox in which I can draw both the images and the rectangles. This
allows me to efficiently pan the image. However, zooming is a pain:
Displaying a 2048x2048 image at four times its size is fun to pan, but
getting it to display in the first place takes forever. I assume this is
because it needs to first transfer all the data to the graphics card which is
slow.

Previously I had done it a different way: I hod no panel but only a
pictureBox. In that I drew whichever portion of the image I displayed. This
made zooming in quite fast but panning was a pain because again it had to
transfer that portion to the graphics card each time the image moved.

Does anybody have a better idea how this can be done?

Thanks in advance for any help you can offer!

Regards,
Marcus

Jun 30 '07 #1
4 10098
Speedy wrote:
Hi there,
I am currently writing an application where one inspects images and
annotates certain features. Thus, one has to zoom in (4x) and pan around. The
features are marked with little red rectangles.The images are 2048x2048
pixels.

It seems that I can find no efficient way to implement both zooming and
panning.

At present I have a panel with autoscroll set to true inside which there is
a pictureBox in which I can draw both the images and the rectangles. This
allows me to efficiently pan the image. However, zooming is a pain:
Displaying a 2048x2048 image at four times its size is fun to pan, but
getting it to display in the first place takes forever. I assume this is
because it needs to first transfer all the data to the graphics card which is
slow.
No, the entire image is not transfered to the graphics card. I doubt
that you even have a graphics card with that much memory.

I don't know exactly how you accomplish the zooming, but what probably
takes time is to create a working copy of the image in memory. If you
zoom a 2048x2048 image to four times, you get a 8192x8192 image, which
uses 192 MB of memory.
Previously I had done it a different way: I hod no panel but only a
pictureBox. In that I drew whichever portion of the image I displayed. This
made zooming in quite fast but panning was a pain because again it had to
transfer that portion to the graphics card each time the image moved.
Well, the image that is drawn is transferred to the graphics part, but
that is not a problem. That is done whenever any image is drawn. The
problem is the extra step between the image and the actual drawing to
the screen, as you are drawing on an image in a PictureBox, then that
image is drawn on the screen. I hope that you at least reused the image
in the PictureBox, and not just created a new image object for every
update...
Does anybody have a better idea how this can be done?
You can for example skip the PictureBox entirely. Override the Paint
event in the panel, and draw the portion of the image that should be
displayed. That way there is no huge working copy of the image, and
there is no extra step between the image and the drawing.

--
Göran Andersson
_____
http://www.guffa.com
Jun 30 '07 #2
Hi Göran,

thanks for your quick reply!

"Göran Andersson" wrote:
Speedy wrote:
Hi there,
I am currently writing an application where one inspects images and
annotates certain features. Thus, one has to zoom in (4x) and pan around. The
features are marked with little red rectangles.The images are 2048x2048
pixels.

No, the entire image is not transfered to the graphics card. I doubt
that you even have a graphics card with that much memory.
How does the panel control accomplish the scrolling so fast? It does take
forever for the image to display but once it is there I can scroll around and
pan with practically no visible delay. I would have thought this is only
possible if the image is on the graphics card and is moved there.
I don't know exactly how you accomplish the zooming, but what probably
takes time is to create a working copy of the image in memory. If you
zoom a 2048x2048 image to four times, you get a 8192x8192 image, which
uses 192 MB of memory.
That's pretty much right. What I do when I zoom in is to create a bitmap of
the right size, i.e. 8192x8192, then create a Graphics object from it and
then first draw the image and then the annotations. Then I assign the bitmap
to the picturebox which is set to AutoSize. The advantage of this is that the
panel control takes care of all the scrolling. It just takes loads of memory
and time.
Previously I had done it a different way: I hod no panel but only a
pictureBox. In that I drew whichever portion of the image I displayed. This
made zooming in quite fast but panning was a pain because again it had to
transfer that portion to the graphics card each time the image moved.

Well, the image that is drawn is transferred to the graphics part, but
that is not a problem. That is done whenever any image is drawn. The
problem is the extra step between the image and the actual drawing to
the screen, as you are drawing on an image in a PictureBox, then that
image is drawn on the screen. I hope that you at least reused the image
in the PictureBox, and not just created a new image object for every
update...
Well the bitmap and the graphics object remained but I had to do a DrawImage
everytime I panned the image. Basically I gave a source and a destination
rectangle. Panning was done by moving the source rectangle and zooming by
making them different sizes. Then after drawing the image and the annotations
I assigned the Bitmap to the pictureBox.Image.
You can for example skip the PictureBox entirely. Override the Paint
event in the panel, and draw the portion of the image that should be
displayed.
Hm, I have never tried overriding a Paint event but I could give it a try.
Are there any snags I should look out for?

Thanks for your help!

Regards,
Marcus
Jun 30 '07 #3
"Speedy" wrote:
You can for example skip the PictureBox entirely. Override the Paint
event in the panel, and draw the portion of the image that should be
displayed.

Hm, I have never tried overriding a Paint event but I could give it a try.
Are there any snags I should look out for?
Sorry for following up to my own post but I have an additional question: If
I override the Paint event of the control in which I display the image with
the annotations what is the advantage of using a Panel control over using a
PictureBox control? If I use the Panel control I assume I do not get
scrolling for free, right?

Regards,
Marcus
Jun 30 '07 #4
Hi Göran,

"Göran Andersson" wrote:
You can for example skip the PictureBox entirely. Override the Paint
event in the panel, and draw the portion of the image that should be
displayed. That way there is no huge working copy of the image, and
there is no extra step between the image and the drawing.
I just wanted to say that your assessment of the situation was spot on. I
tried what you suggested and it works beautifully! It was actually quite easy
too, I don't know why I haven't done it before!

Thank you very much!

Best regards,
Marcus
Jul 1 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gopi | last post by:
Hi All I have set a BackgroundImage for windows forms and i need to implement the image zooming feature for the form ie when ever i m zooming in or zooming out the form the corrosponding...
1
by: Diogo Alves - Software Developer | last post by:
Hi, currently I am programming a control to zoom in/out images and move them inside a frame, but when I zoom it keeps the upper left corner static making the image growing to the lower-rigth...
0
by: gerstla | last post by:
hi I am building a simple control to view images with zooming capabilities. i want the image to zoom when it is clicked on. after zooming i want the control to try and move the point clicked to the...
1
by: John | last post by:
I have an app where I want to show an icon in a large PictureBox. I've set the SizeMode to Zoom but the icon image is extremely fuzzy because the scaling up also anti-aliases. Is there a way to...
0
by: pavanjosh | last post by:
Hello Frineds, Can anyone please help me in getting the code or library for written in C# for zooming in and zooming out the images in the picture box? Or is there any other way from which i can...
8
by: theCancerus | last post by:
Hi All, I am not sure if this is the right place to ask this question but i am very sure you may have faced this problem, i have already found some post related to this but not the answer i am...
0
by: johot | last post by:
I am currently creating a little photo application. In this application the user is able to zoom in the image and after zooming panning around inside the zoomed image with the mouse. The strange...
1
by: pavanip | last post by:
Hi, I am doing a simple application Zooming Image. Here I am taking an image and dividing that image into different regions. I have a tree structure of different levels like this. ...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.