473,385 Members | 1,907 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,385 software developers and data experts.

I have a picturebox that the image will change with ever record the user inquires on.

If drPhoto.HasRows = True Then
While (drPhoto.Read() = True)
Dim i As Integer
For i = 0 To drPhoto.FieldCount - 1
If i = 0 Then
Dim texta As String = Convert.ToString(drPhoto.GetValue(i))
End If
If i = 1 Then
Dim MS As System.IO.MemoryStream = New System.IO.MemoryStream()
Dim binData() As System.Byte = CType(drPhoto.GetValue(i), System.Byte())
MS.Write(binData, 0, binData.Length)
imagesrc = System.Drawing.Image.FromStream(MS)
If System.IO.File.Exists(ImagePath & "\imagesrc.bmp") = True Then
System.IO.File.Delete(ImagePath & "\imagesrc.bmp")
imagesrc.Save(ImagePath & "\imagesrc.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
Else
imagesrc.Save(ImagePath & "\imagesrc.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
End If
End If
Next
End While
Else
ptbEMPPhoto.Image = System.Drawing.Image.FromFile(ImagePath & "\noimage.bmp")
Exit Sub
End If

Dim imgOrg As Bitmap
Dim imgShow As Bitmap
Dim g As Graphics
Dim divideBy, divideByH, divideByW As Double
imgOrg = DirectCast(Bitmap.FromFile(ImagePath & "\imagesrc.bmp"), Bitmap)

divideByW = imgOrg.Width / ptbEMPPhoto.Width
divideByH = imgOrg.Height / ptbEMPPhoto.Height
If divideByW > 1 Or divideByH > 1 Then
If divideByW > divideByH Then
divideBy = divideByW
Else
divideBy = divideByH
End If
imgShow = New Bitmap(CInt(CDbl(imgOrg.Width) / divideBy), CInt(CDbl(imgOrg.Height) / divideBy))
imgShow.SetResolution(imgOrg.HorizontalResolution, imgOrg.VerticalResolution)
g = Graphics.FromImage(imgShow)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(imgOrg, New Rectangle(0, 0, CInt(CDbl(imgOrg.Width) / divideBy), CInt(CDbl(imgOrg.Height) / divideBy)), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel)
g.Dispose()
Else
imgShow = New Bitmap(imgOrg.Width, imgOrg.Height)
imgShow.SetResolution(imgOrg.HorizontalResolution, imgOrg.VerticalResolution)
g = Graphics.FromImage(imgShow)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(imgOrg, New Rectangle(0, 0, imgOrg.Width, imgOrg.Height), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel)
g.Dispose()
End If

ptbEMPPhoto.Image = imgShow

in the code where the image is going to be deleted i get the message "being used by another process" how can close the file so that i may delete it?
Apr 12 '12 #1
2 1540
unload the picture in your picturebox before you delete..
Apr 15 '12 #2
Killer42
8,435 Expert 8TB
What version of VB is that? The System.IO stuff looks suspiciously like VB.Net - if so, you're likely to get more helpful responses in the VB.Net forum.
Apr 22 '12 #3

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

Similar topics

5
by: Jeff | last post by:
I've seen a couple of posts on the Internet with others having this problem, however, no one seems to have a good answer. I am working on a C# Smart Device application and have been able to...
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...
2
by: **Developer** | last post by:
During debug I noticed that a picturebox image does not have a Location Is the image object always located at the upper left of the clientsize of the picturebox. If the picturebox clientsize...
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...
1
by: Krushangi | last post by:
Hi Code for: How to change picturebox during Runtime. I want this Code in C#.net I have one picturebox Image and i want to change it during MouseUp Event at Runtime. Tell me how can i give...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.