|
-
Sep 15th, 2011, 05:10 PM
#1
Thread Starter
Lively Member
[RESOLVED] convert BMP to JPG (VaryQualityLevel)
Hi there all Good People,
Please, please, please, please would anybody help me with this one? 
I'm using an example code from msdn in my project to convert a BMP file to JPG file.
the code comes from here: http://msdn.microsoft.com/en-us/libr...90%29.aspx#Y74
this code allows you to pick quality/compresion level of the output JPG file.
this is how it looks like:
Code:
Private Sub VaryQualityLevel()
' Get a bitmap.
Dim bmp1 As New Bitmap("c:\TestPhoto.jpg")
Dim jgpEncoder As ImageCodecInfo = GetEncoder(ImageFormat.Jpeg)
' Create an Encoder object based on the GUID
' for the Quality parameter category.
Dim myEncoder As System.Drawing.Imaging.Encoder = System.Drawing.Imaging.Encoder.Quality
' Create an EncoderParameters object.
' An EncoderParameters object has an array of EncoderParameter
' objects. In this case, there is only one
' EncoderParameter object in the array.
Dim myEncoderParameters As New EncoderParameters(1)
Dim myEncoderParameter As New EncoderParameter(myEncoder, 50&)
myEncoderParameters.Param(0) = myEncoderParameter
bmp1.Save("c:\TestPhotoQualityFifty.jpg", jgpEncoder, myEncoderParameters)
myEncoderParameter = New EncoderParameter(myEncoder, 100&)
myEncoderParameters.Param(0) = myEncoderParameter
bmp1.Save("c:\TestPhotoQualityHundred.jpg", jgpEncoder, myEncoderParameters)
' Save the bitmap as a JPG file with zero quality level compression.
myEncoderParameter = New EncoderParameter(myEncoder, 0&)
myEncoderParameters.Param(0) = myEncoderParameter
bmp1.Save("c:\TestPhotoQualityZero.jpg", jgpEncoder, myEncoderParameters)
End Sub 'VaryQualityLevel
...
Private Function GetEncoder(ByVal format As ImageFormat) As ImageCodecInfo
Dim codecs As ImageCodecInfo() = ImageCodecInfo.GetImageDecoders()
Dim codec As ImageCodecInfo
For Each codec In codecs
If codec.FormatID = format.Guid Then
Return codec
End If
Next codec
Return Nothing
End Function
Now... for some reason it locks the original file ("c:\TestPhoto.jpg" in the example above), so you cannot use it for some time - sometimes many minutes. If you try to delete the file you get an error message saying it is being used by another process. You cannot overwrite it/rename it/move it... If I close my program and reopen it immediatelly the file becames available again, so closing the program somehow kills the process, but I have no idea what kind of process it might be.
What is missing in the above code? How do I identify and kill this process? How do I make the original file available again?
Any ideas?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|