473,406 Members | 2,220 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,406 software developers and data experts.

Delay when updating picturebox image

Raventara
Hi all,

I have a program which will routinely update the image of a picturebox and resize the picturebox to keep the aspect ratio of the image in tact. The problem I am having is that after about 10 or so changes of the image there is a really long delay in updating the image. The size properties will update but the image itself stays the same. I have tried forcing it to revalidate (even though changing the size of the picturebox does this) and 3 or 4 different ways of loading the image from the file in the first place. I have managed to improve my code so it chews less memory in all this but it's still having a long delay...

Has anyone seen anything like this and if so how do I get around it?

Thanks in advance.
Dec 16 '08 #1
3 2712
nukefusion
221 Expert 100+
Have you checked to make sure that you are disposing of the old images before loading the new one?
A code sample may help.
Dec 16 '08 #2
That's something I was not doing and I watched the memory get eaten and was exactly what I thought the issue was. I fixed that but it's still happening despite not eating memory up...


Expand|Select|Wrap|Line Numbers
  1.         Dim itemno As Integer
  2.  
  3.         itemno = CInt((imagelist.Length) * Rnd())
  4.  
  5.         If Image1.Image IsNot Nothing Then Image1.Image.Dispose()
  6.         Image1.ImageLocation = imagelist(itemno)
  7.         Image1.Load()
  8.  
  9.         Dim ratio As Double
  10.         If Image1.Image.Width >= Image1.Image.Height Then 
  11.             ratio = Image1.Image.Height / Image1.Image.Width 
  12.             Image1.Height = CInt(Image1.Width * ratio)
  13.         Else
  14.             ratio = Image1.Image.Width / Image1.Image.Height 
  15.             Image1.Width = CInt(Image1.Height * ratio)
  16.         End If
  17.  
  18.  
"imagelist" is a string array which contains the images filenames.

I have tried using a temporary Bitmap and loading the image there first and assigning it to the picturebox and have tried using image1.image = image.fromfile(imagelist(itemno)) but neither made a difference.

Thanks.
Dec 16 '08 #3
Okay, So after some more testing it's not the image loading that is stuffing things up, but the resizing code for the form ("me.width =" and "me.height =") that is doing it...

when I remove the resizing from the code the images change and update just as you would imagine they should, but when I reinstate that code the same thing starts to happen.

Does anyone know why this would happen?

Interestingly it also happens if I set the forms autosize property to Shrink and Grow and let the form autosize itself!!

Expand|Select|Wrap|Line Numbers
  1.         Me.Width = 533
  2.         Me.Height = 424
  3.         Image1.Width = 509
  4.         Image1.Height = 400
  5.  
  6.  
  7.  
  8.         Dim ratio As Double
  9.         If Image1.Image.Width >= Image1.Image.Height Then 'imagelist(itemno).Width >= imagelist(itemno).Height Then
  10.  
  11.             ratio = Image1.Image.Height / Image1.Image.Width 'imagelist(itemno).Height / imagelist(itemno).Width
  12.             Image1.Height = CInt(Image1.Width * ratio)
  13.             Me.Height = Image1.Height + 24
  14.         Else
  15.             ratio = Image1.Image.Width / Image1.Image.Height 'imagelist(itemno).Width / imagelist(itemno).Height
  16.             Image1.Width = CInt(Image1.Height * ratio)
  17.             Me.Width = Image1.Width + 24
  18.         End If
  19.         Me.CenterToScreen()
Dec 18 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: CroDude | last post by:
Hi all! I've made a little app that creates thumbnails and if user clicks on it, it displays the original picture in the picturebox on a panel control. In a thumbnail mouse down event I'm using...
1
by: M West | last post by:
continuation of my previous post, thanks to all those that contributed with answers I am creating a control that will take an image and make parts of it transparent, this is done by creating and...
0
by: dlamar | last post by:
I'm using VB.NET with 2.0 - I have a number of PictureBoxes in my application - all of which use a context menu to change the associated Image to one of 5 options. I need to maintain the state of...
2
by: Frank | last post by:
For various reasons I want to use a PictureBox to display images. That is I want sometimes to assign an Image to the PictureBox Sometimes I want to draw on that Image. What are the reasons for...
3
by: Andrzej | last post by:
I have a picturebox on my C# .NET form. The picturebox size mode is set to zoom. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and...
4
by: Jerry West | last post by:
I have a routine that updates a PictureBox image every x seconds. I do this by first loading an array with the path to all of the images. I then generate a random number to use as the index of the...
0
by: irtehnoob | last post by:
Hi there, I'm pretty new to c# (started up a few days ago) and I'm making a simple program, so far everything is going good except I can't figure somethine out.. hence why I'm here. Anyways, in my...
5
by: 55555 | last post by:
rectangle drawn on picturebox gets erased when i scroll image.i.e i have made application for image cropping. on mouse down and mouse up event, an rectangle is drawn on picturebox using graphics....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.