|
Again, nowhere in your code do you call Dispose() on the Graphics object you're creating. You MUST ALWAYS call .Dispose() on a Graphics object when you're done using it, otherwise you get odd behavior, kind of like changes not being saved, when manipulating images and your app is suddenly leaking GDI Handles and will eventually crash the system! BTW, you also have to .Dispose() Font objects when you're done with them too.
Since you're only using the Graphics object when a property item contains a certain value, I suggest not creating any Graphics or Font objects unless you need them:
Imports System.Drawing.Imaging
.
.
.
For Each img As Image In _images
Dim changed As Boolean = False
Dim pi() As Drawing.Imaging.PropertyItem = img.PropertyItems
For Each pItem As Drawing.Imaging.PropertyItem In pi
If pItem.Id = 36867 Then
Dim bytes() As Byte = pItem.Value
Dim f As New Font(FontFamily.GenericSerif, 35.0F, FontStyle.Regular, GraphicsUnit.Point)
Dim graph As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(img)
Dim enc As New System.Text.UTF8Encoding
graph.DrawString(enc.GetString(bytes), f, Brushes.Yellow, CSng(img.Width) - 400.0F, CSng(img.Height) - 50.0F)
graph.Dispose()
f.Dipose()
' Create a JPEG Encoder and set it's Compression quality
Dim jpegCodec As ImageCodecInfo = GetEncoderInfo("image/jpeg")
Dim encoderParams As New EncoderParameters(1)
encoderParams.Param[0] = New EncoderParameter(Encoder.Quality, 100)
' Save the image using the new encoder
img.Save(_imagesHash.Item(img).ToString() & ".jpg", jpegCodec, encoderParams)
Exit For
End If
Next
Next
.
.
.
Public Shared Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders()
For i As Integer = 0 To codecs.Length
If codecs[i].MimeType = mimeType Then
Return codecs[i]
End If
Next
Return Nothing
End Sub
The reason why it's size changes is because you didn't specify the format to use when the image is saved. In your case, the image is saved as PNG format, not JPG. The filename you give doesn't determine the format of the image written. If you want to save an image in JPG format, you have to tell it to do so. If you want to control the compression used on the JPG image, you have to add EncoderParameters to spell out how the JPG should be handled. Those above has been modified to do this.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks a lot for making my code much more better
|
|
|
|
|
I am inserting text files into MySQL using vb.net. However, when I insert the files into the database it only insert every other file. For example, it will insert one file then the next row will be zeros. Does any one know why it might be doing this. Here is some code:
Dim myConnString AsString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=192.168.1.27;" & _
"DATABASE=testship;" & _
"USER=?;" & _
"PASSWORD=?;" & _
"OPTION=3;"
Dim MyConnection AsNew Odbc.OdbcConnection(myConnString)
MyConnection.Open()
Dim MyCommand AsNew Odbc.OdbcCommand("INSERT INTO ls_orderitems (OrderDate, OrderCustomer, OrderAcctNum, OrderType, OrderSoNum, OrderItemPartNum, OrderItemPartDesc, OrderItemQty, OrderItemQtyRec, OrderItemQtyDtRec, OrderItemBO, OrderItemBODt,OrderItemCanceled, OrderItemCanceledDt, OrderItemNotes, OrderItemPONum, OrderItemRetailPrice, OrderItemSalePrice, Status, InsertDate) VALUES ('" & OrderDate & "','" & OrderCustomer & "','" & OrderAcctNum & "','" & OrderType & "','" & OrderSoNum & "','" & OrderItemPartNum & "','" & OrderItemPartDesc & "','" & OrderItemQty & "','" & OrderItemQtyRec & "','" & OrderItemQtyDtRec & "','" & OrderItemBO & "','" & OrderItemBODt & "','" & OrderItemCanceled & "','" & OrderItemCanceledDt & "','" & OrderItemNotes & "','" & OrderItemPONum & "','" & OrderItemRetailPrice & "','" & OrderItemSalePrice & "','" & Status & "','" & InsertDate & "')")
MyCommand.Connection = MyConnection
MyCommand.ExecuteNonQuery()
MyConnection.Close()
jds1207
|
|
|
|
|
jds1207 wrote: I am inserting text files into MySQL using vb.net. However, when I insert the files into the database it only insert every other file. For example, it will insert one file then the next row will be zeros
???
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Well, from the description of the problem, there's something wrong with either the code that reads the files, or the code that validates the data, or the code that inserts the file into the database. And what have we told you about using parameterized queries?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Oh! oh!! I know! I know! ** Sticks hand high in the air** We should use parameterised queries! We should use them becuase it makes the application safe from people trying to inject into it!
|
|
|
|
|
Colin Angus Mackay wrote: Oh! oh!! I know! I know! ** Sticks hand high in the air**
Ah, yes! The Scottish guy in the back there...
Colin Angus Mackay wrote: We should use parameterised queries! We should use them becuase it makes the application safe from people trying to inject into it!
Very good! You get a Gold Star for the day!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Sounds nice but I am having trouble getting my parameterised query to work using MySQL. However, the code that I am currently using to insert is working fine now. Also, I found out why the empty rows are being inserted into the db. The file that I am cleaning is being cleaned and making the file double spaced. I could use a helping hand with this issue. Here is the code that I used to clean the file:
'Read file line by line
Dim file_name As String = "c:\Scanning files\lsprint_MO.txt"
Dim Temp_file As String = "c:\Scanning files\lsprint_MO_temp.txt"
Dim textline As String
If System.IO.File.Exists(file_name) = True Then
Dim objReader As New System.IO.StreamReader(file_name)
Do While objReader.Peek() <> "-1"
textline = String.Concat(objReader.ReadLine(), ControlChars.NewLine)
If textline.IndexOf("xxxxxxx") = 17 Then
Console.WriteLine(textline)
WriteFile(Temp_file, textline)
End If
Loop
objReader.Close()
My.Computer.FileSystem.DeleteFile(file_name)
End If
Any ideas would help!
|
|
|
|
|
jds1207 wrote: The file that I am cleaning is being cleaned and making the file double spaced.
It's called Validation and you're not doing anything to verify that what you're reading is valid. You're just assuming that what you have in your variables is good and that's why your database is comming up with zeros.
You're going about reading a text file the hard way.
Dim sourceFilename As String = "C:\Scanning files\lsprint_MO.txt"
Dim tempFilename As String = "C:\Scanning files\lsprint_MO_temp.txt"
Dim textline As String
If System.Io.File.Exists(sourceFilename) Then
Try
Dim sr As New StreamReader(sourceFilename)
Do
textline = sr.ReadLine()
' Why are you using String.Concat?? Your building a line and adding
' blank lines to the textline string. Why??
' Parse your line here and make sure that the values you got are VALID!
' If not, jump to some other method to report or log the problem.
' If we get here, the data looks good. Add it to the database.
' Call your database code here and pass the "cleaned" values to it.
Loop Until textline Is Nothing
Catch ex As Exception
' Something happened during the file read or database call.
' Log the error or report it somehow and forget the rest of the file.
Finally
If Not sr Is Nothing Then
sr.Close()
End If
End Try
It would also help to see a sample of the file you're trying to read and parse.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks! That worked fine.
|
|
|
|
|
Hi All,
Can anyone please tell me what does the Err.LastDllError() return?
|
|
|
|
|
|
What does the Err.LastDllError return?
|
|
|
|
|
hellow m making my project for Classes which stores student's personal, Fees ,Marks details.In this when staff membe checks for student's fees it should display it in balance amount ,Paid amount,and fees for the course.then when he checks for student's marks details all the marks should be displayed along with graphical view...
Glad to join you. Want you to help me.Mayuri
|
|
|
|
|
Mayuri Gaikwad wrote: Want you to help me.
With what? You haven't asked a question yet...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Sir,
I am converting a ActiveX(DSO Framer)control into .Net assembly.
1. I was able to import it as assembly using "Tlbimp" utility,
2. I could able to convert the content in to Intermediate Language form by using utility "Ildasm" utility. But
3. When I tried to edit the content for verification by using the utility "Ilasm" its giving error as below
Errors /* No entry point declared for executable
Could not create output file, error code=0x80004005
***** FAILURE *****
Please give me what to do now. Please.
and
Creating PE file
Error: No entry point declared for executable
Could not create output file, error code=0x80004005
***** FAILURE *****
*/
Please check these errors and give me a good solution please, I am struck here please. Thank you.
Regards,
S/W Engineer
Akebono Soft Technologies
aleem_abdul@akebonosoft.com.
|
|
|
|
|
indian143 wrote: I am converting a ActiveX(DSO Framer)control into .Net assembly.
Not possible unless you write all the code yourself.
indian143 wrote: 1. I was able to import it as assembly using "Tlbimp" utility,
No, you were able to have TlbImp create a wrapper assembly around your ActiveX component. This means that you still have to install both the DSOFramer control AND the .NET wrapper class you just made on the clients machine. So, you didn't take away the installation requirements, you actually added to it.
indian143 wrote: 2. I could able to convert the content in to Intermediate Language form by using utility "Ildasm" utility. But
Not possible since this control wasn't written in any managed language. You can use this tool to see the IL code in the wrapper, not the control it wraps.
indian143 wrote: 3. When I tried to edit the content for verification by using the utility "Ilasm" its giving error as below
What you're trying to do is not possible. We've already told you half a dozen times, you either have to write a replacement control from scratch or find a replacement control that offers the functionality you want. You can NOT convert this control to a .NET assembly, you can only wrap it in one.
-- modified at 11:55 Thursday 11th January, 2007
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi
it's a small thing but it's bad problem ,,
I'm using vb.net 2005 , when I go to run the project from the design mode it's OK , but when I go to run the EXE of the project , I found that the splash screen is appearing and then the StartUp form is running behinde other windows openning programs ,
this problem isn't appear when I run the program from it's source on vb.net envirnment , but on Exe , it's appear .....
any body response me quickly please ??
jooooo
|
|
|
|
|
I had this problem too, although it happened for me both when I ran the project through vb and when I ran the exe. I solved it like this:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
'Hide the form while splash screen is visible<br />
Me.Hide()<br />
<br />
'Insert your form loading code...<br />
<br />
'Reveal the form when loading is complete<br />
Me.Show()<br />
End Sub
Hope this helps.
|
|
|
|
|
Thanks my friend , but the problem wasn't solved ,
Now for a period I will cancel splash screen until I can find any thing else
jooooo
|
|
|
|
|
since you are using vb.net..you could set the properties to topmost = true
or in the form load...
Me.TopMost = True where me is the name of the form..hope this help for you..
|
|
|
|
|
|
Hi,
I want to get into programming using Visual Basic / VB.NET.
Would appreciate any technical material, papers and tutorials to help me get started well.
I would appreciate any easy to follow video or tutorials to help me get into the VB programming world.
Thank you.
Emmanuel Awortwi
emmanuelawortwi@yahoo.com
+233-24-4951875
|
|
|
|
|
Hi Emmanuel,
First off it is best to only bother with VB.NET (VB6 = old). The best tool is Microsoft's .NET Studio. If you can obtain it, it contains its own documentation with step-by-step walkthroughs for all kinds of operations. With these walkthroughs you can create simple projects that you can then experiment with and expand.
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
When I tried to edit the .il file it is giving the following error.
No entry point declared for executable
Could not create output file, error code=0x80004005
***** FAILURE *****
Please give me what to do now. Please.
C:\WINNT\Microsoft.NET\Framework\v1.1.4322>ilasm D:\Aleem\DSOControl1\DSOControl1.il
Microsoft (R) .NET Framework IL Assembler. Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
Assembling 'D:\Aleem\DSOControl1\DSOControl1.il' , no listing file, to EXE --> 'D:\Aleem\DSOControl1\DSOControl1.EXE'
Source file is ANSI
Creating PE file
Error: No entry point declared for executable
Could not create output file, error code=0x80004005
***** FAILURE *****
C:\WINNT\Microsoft.NET\Framework\v1.1.4322>
S/W Engineer
Akebono Soft Technologies
aleem_abdul@akebonosoft.com.
|
|
|
|
|