472,378 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

VB .Net "File in Use" on Loading JPG image into a picture box...

Using VB .Net 2003 Standard Edition.

This simple form has a "File in Use" problem while the executable is running.

Created this simple program to make sure that I hadn't done something in my
code in the "real" project.

In the "real" project, One part of the program saves multiple images and
another part of the program moves the images to the appropriate directories
based on user feedback.

Problem is that once a JPG picture is loaded into a PictureBox I see "File
in Use" Problems with it even after a different JPG picture has been loaded
into that same PictureBox.

Once the program is exited, the files aren't in use!

I can't ask the end-user to frequently exit and restart this program.

This program is a "real time" process that needs to stay running, so
launching a new copy of the program and causing the current version to exit
is not an option either.

ALL the current patches for Windows, Visual Basic .Net 2003, etc have been

Think that this problem ONLY applies to JPG Pictures, I've tested BMP files
with absolutely NO problems.

For this application, using JPG images is a MUST, so changing to a different
format is out of the question.

Yet if I save the same picture to a new filename that file is not in use.
Used this to save the JPG image from the PictureBox: (Without the quotes!)
"PictureBox.Image.Save(FileName, Imaging.ImageFormat.Jpeg)"

ANY hints on resolving this issue or any valid workarounds?

Bill N.

--- Complete Code for the sample program ---
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

'This call is required by the Windows Form Designer.

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
End If
End If
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents btnExit As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.btnExit = New System.Windows.Forms.Button
Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.PictureBox1.Location = New System.Drawing.Point(4, 4)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(96, 96)
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchIma ge
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
Me.btnExit.Location = New System.Drawing.Point(80, 132)
Me.btnExit.Name = "btnExit"
Me.btnExit.Size = New System.Drawing.Size(108, 56)
Me.btnExit.TabIndex = 1
Me.btnExit.Text = "Exit"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(290, 271)
Me.Name = "Form1"
Me.Text = "Form1"

End Sub

#End Region

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExit.Click


End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim Filename As String = _

PictureBox1.Image = Image.FromFile(Filename)

End Sub

End Class
Jul 21 '05 #1
2 12193
On Mon, 18 Oct 2004 10:59:07 -0700, Bill N. wrote:
Using VB .Net 2003 Standard Edition.

This simple form has a "File in Use" problem while the executable is running.
ANY hints on resolving this issue or any valid workarounds?

Try using a file stream instead:

Dim img as Image
Dim fs as New FileStream(Filename,IO.FileMode.Open)

img = Image.FromStream(fs)


PictureBox1.Image = img



To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Jul 21 '05 #2
Works much better.

Just needed to add this at the top of the program:
Imports System.IO

Thanks Chris!

Jul 21 '05 #3

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

Similar topics

by: Stephen Oakes | last post by:
I am trying to upload an image to a server, but I get this warning: Warning: imagecreatefromjpeg(): 'filename' is not a valid JPEG file The error occurs when I am trying to create a thumbnail...
by: MB | last post by:
I am writing an FTP Client using the NIO packages because I want to use the non-blocking functionality. I have done this successfully except for the fact that after I "put" an image file to the...
by: John Pastrovick | last post by:
Is there a way to load an image locally (in the client) when a selection of a file is made using input type=file. The purpose is to allow selection of a file and put the image in the browser...
by: mattsthompson | last post by:
Im writing a DLL that extends IHttpHandler to intercept requests for a certain file extension and deliver watermarked images. I'm using LeadTools' .NET framework for the image manipulation and it...
by: Bill N. | last post by:
Using VB .Net 2003 Standard Edition. This simple form has a "File in Use" problem while the executable is running. Created this simple program to make sure that I hadn't done something in my...
by: Markus | last post by:
I'm adding to my script a section that allows a thumbnail to be created and saved. I get this error: Warning: imagejpeg() : Unable to open '../uploads/thumb/' for writing: Is a directory in...
by: MC | last post by:
I have a couple of customers who are using a program that deserializes an XML file, and on some files, the program fails to see the content of the file -- treats it as zero length and reports "root...
by: gerardianlewis | last post by:
Any help appreciated. (VB.NET under XP and Vista, SP1 installed) My code, inherited from a VB6 version of an app that ran under W98, loads an image from a file into a PictureBox. The user may...
by: defn noob | last post by:
from Tkinter import * import os master = Tk() w = Canvas(master, width=800, height=600) print os.path.exists('C:/me/saftarn/desktop/images/blob4.jpg') im = PhotoImage(file =...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.