473,786 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10162
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.Imag e.
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
1525
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 background image also needs to be zoomed in and zoomed out. the zoom factors ( zooming values are) 50%,100% and 150% how do i implement this? thanks in advance Gopi
1
1510
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 direction... I would like to make the the image fixed on the center of the frame expanding it to all the sides from that point.... Guess that ou can figure out what I want (forgive my bad english)
0
1312
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 center or at least be in view. The code I am using know for centering isnt working correctly. AutoScrollPosition = new Point((int)(currentPoint.X * _zoom), (int)(currentPoint.Y * _zoom)); currentPoint is the last place I clicked. thanks
1
11654
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 turn the anti-aliasing off so I get a nice blocky icon image? -- "I have nothing but the greatest respect for other peoples' crackpot beliefs". -- Sam the Eagle.
0
1822
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 achieve the same task? Your help will be gretely appreciated. Thanks and Reagrds Pavan Joshi
8
6394
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 looking for. My problem is that i have to upload images and store them. I am using filesystem for that. setup is something like this, their will be items/groups/user each can
0
1617
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 thing is that the first zoom is really slow, and so is the first panning. So if you zoom into an image it will first take some time, and when trying to pan the image around things will be really choppy. However if i zoom into the image even more, and...
1
1240
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. Ex. Image + ABC Level1 + DEF level1 - GHI level1
5
13381
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 http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10360
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8988
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.