exporting next image from listbox - vb.net

I am trying to build an ImageConverter for my cousin (he needs that for his job) to export images in the following formats : 1. 2500x2500 , 2.1500x1500 and 3.800x800.
I only managed to export only one picture at a time in this formats , but he usually has over 50 pictures to convert in this formats daily , so I added a listbox so he can drag and drop his images in the listbox .I did managed that , but I don't know how to export the pictures that are loaded in the listbox , it needs to export one by one . The code I am using to export the images with "Export button" is here :
If (Not System.IO.Directory.Exists("C:\Users\Administrator\Desktop\" + KryptonTextBox1.Text)) Then
System.IO.Directory.CreateDirectory("C:\Users\Administrator\Desktop\" + KryptonTextBox1.Text)
Dim picturepath As String
picturepath = "C:\Users\Administrator\Desktop\" + KryptonTextBox1.Text
pathtxt.Text = picturepath
End If
Dim fileName As String = KryptonListBox1.SelectedItem.ToString()
Dim pathname As String = OpenFileDialog1.FileName
picturename = Path.GetFileNameWithoutExtension(fileName)
BildNametxt.Text = picturename
'converting picture in 2500x2500 format
Try
If (Not System.IO.Directory.Exists(pathtxt.Text + "\Amazon")) Then
System.IO.Directory.CreateDirectory(pathtxt.Text + "\Amazon")
Else
PictureBox2500.BackgroundImage.Save(pathtxt.Text + "\Amazon" + "\" + picturename + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Try
If (Not System.IO.Directory.Exists(pathtxt.Text + "\1500")) Then
System.IO.Directory.CreateDirectory(pathtxt.Text + "\1500")
Else
PictureBox1500.BackgroundImage.Save(pathtxt.Text + "\1500" + "\" + picturename + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Try
If (Not System.IO.Directory.Exists(pathtxt.Text + "\800")) Then
System.IO.Directory.CreateDirectory(pathtxt.Text + "\800")
Else
PictureBox800.BackgroundImage.Save(pathtxt.Text + "\800" + "\" + picturename + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
MessageBox.Show("Images succesfully converted!")
resizedimage2500.Dispose()
resizedimage1500.Dispose()
resizedimage800.Dispose()
So how can I do the same thing with the loaded listbox ? Any help is apreciated ! Thanks in advance

Related

Show a popup after exporting in Excel in vb.net

Hi I've a procedure in my web site for exporting a datatable in xlsx with closedxml library and I want show a popup after finishing export but the popup not showed. Can anyone tell me how to show the popup ? This is my code
Protected Sub ExportExcel(dt, strTable)
Using wb As New XLWorkbook()
Dim ws = wb.Worksheets.Add(dt, "foglio1")
ws.Columns("I").Style.NumberFormat.Format = "#,##0.00"
Response.Clear()
Response.Buffer = True
Response.Charset = "UTF-8"
Response.ContentEncoding = System.Text.Encoding.Unicode
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("content-disposition", "attachment;filename=" & strTable & ".xlsx" )
try
Using MyMemoryStream As New MemoryStream()
wb.SaveAs(MyMemoryStream)
MyMemoryStream.WriteTo(Response.OutputStream)
Response.Flush()
Response.Close()
End Using
catch
finally
Dim scriptString as String = "<script language=JavaScript>"
scriptString += "alert('Export completed !" & strUser & "!');"
scriptString += "window.location.href='http://localhost/default.aspx';<"
scriptString += "/"
scriptString += "script>"
If(Not ClientScript.IsClientScriptBlockRegistered(Me.GetType(), "clientScript"))
ClientScript.RegisterClientScriptBlock(Me.GetType(), "clientScript",scriptString)
end If
end try
End Using
End Sub

Screen capture code runs OK in WinForms but not as a service

I want to create a Windows service to screen capture but it's not working.
The process reaches the ScrenCapture.Start() but it does not do anything and does not throw an error.
If I test it in a Windows form the same code works well:
Code:
Imports Microsoft.Expression.Encoder.ScreenCapture
Imports isc.isc_utility
Public Class isc_utility_screen_capture
Dim ScrenCapture As ScreenCaptureJob = New ScreenCaptureJob()
Shared SrvDir As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location())
Function StartRecording(ByVal FileName As String)
Dim Dir = SrvDir
Dim FileToRecord As String
FileToRecord = Dir + "\" + FileName + ".wmv"
Try
ScrenCapture.OutputScreenCaptureFileName = FileToRecord
ScrenCapture.CaptureMouseCursor = True
ScrenCapture.Start()
WriteEventLogInformation("Capturing Video.... " + FileName + " " + Date.Now)
Return FileName
Catch ex As Exception
WriteEventLogError(ex.Message)
Return "-1"
End Try
End Function
Function StopRecording()
Try
ScrenCapture.Stop()
Return 1
Catch ex As Exception
WriteEventLogError(ex.Message)
Return -1
End Try
End Function
End Class
What could be happening?

How to do DB backup with VistaDB?

I'm trying to do a XML export of the database with VistaDB.
Unfortuanently, I'm lost.
Here's my code so far:
Dim instance As IVistaDBDatabase
Dim value As System.Int64
SaveFileDialog2.InitialDirectory = "C:\"
Select Case SaveFileDialog2.ShowDialog()
Case Windows.Forms.DialogResult.OK
Try
instance.ExportXml(SaveFileDialog2.FileName, VistaDBXmlWriteMode.All)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Select
All I get is object not set to instance of an object (or something like that).
Can anyone provide so guidance?
I was able to figure it out with help from an old code package.
Here is the proper code:
Dim vdbDatabase As IVistaDBDatabase = Nothing
Dim filenameDB As String = SaveFileDialog2.FileName
Dim filenameXML As String = SaveFileDialog2.FileName
Select Case SaveFileDialog2.ShowDialog()
Case System.Windows.Forms.DialogResult.OK
Try
' Call the method that will open the connection to the database and return an open IVistaDBDatabase object for the database to us
vdbDatabase = DDA.VistaDBEngine.Connections.OpenDDA.OpenDatabase("C:\Ledger.vdb5", VistaDBDatabaseOpenMode.NonexclusiveReadOnly, Nothing)
' Clear the XML Transfer List - this is the list used by the Import/Export methods
vdbDatabase.ClearXmlTransferList()
' Loop through the tables in the database and add them to the XmlTransferList
For Each tableName As String In vdbDatabase.GetTableNames()
vdbDatabase.AddToXmlTransferList(tableName)
Next
' Call the ExportXML method with the name of the XML file and the WriteMode value indicating what to Export
vdbDatabase.ExportXml(filenameXML, VistaDBXmlWriteMode.All)
' If the database is open - close it
If Not vdbDatabase.IsClosed Then
vdbDatabase.Close()
End If
MsgBox("Database Export complete.", MsgBoxStyle.Information)
Catch ex As Exception
WriteErrorEvent("Error exporting Database in addin", ex)
MsgBox("An error occured attempting to export the Database. Error Message:" & vbCrLf & vbCrLf & ex.ToString, MsgBoxStyle.Exclamation)
Finally
' If we have a vdbDatabase object
If Not (vdbDatabase Is Nothing) Then
' If it is open, close it
If Not vdbDatabase.IsClosed Then
vdbDatabase.Close()
End If
' Dispose of the object
vdbDatabase.Dispose()
End If
End Try
End Select
A Little late but i've made a small change to your code, so you can see the exact time of your backup.
Dim vdbDatabase As IVistaDBDatabase = Nothing
Dim filenamedb As String = vdbDatabase
Dim filenameXML As String = "MyDataBaseName_" + Now.ToString("dd-MM-yyyy_hh-mm-ss") + ".Xml"
Dim path As String
path = System.IO.Path.GetFullPath(filenameXML)
Try
vdbDatabase = DDA.VistaDBEngine.Connections.OpenDDA.OpenDatabase("DataDirectory|MyDataBase.vdb5", VistaDBDatabaseOpenMode.NonexclusiveReadOnly, Nothing)
vdbDatabase.ClearXmlTransferList()
For Each tableName As String In vdbDatabase.GetTableNames()
vdbDatabase.AddToXmlTransferList(tableName)
Next
vdbDatabase.ExportXml(filenameXML, VistaDBXmlWriteMode.All)
If Not vdbDatabase.IsClosed Then
vdbDatabase.Close()
End If
MsgBox("Backup is in " + path, MsgBoxStyle.Information)
Catch ex As Exception
MsgBox("An error occured attempting to export the Database. Error Message:" & vbCrLf & vbCrLf & ex.ToString, MsgBoxStyle.Exclamation)
Finally
If Not (vdbDatabase Is Nothing) Then
If Not vdbDatabase.IsClosed Then
vdbDatabase.Close()
End If
vdbDatabase.Dispose()
End If
End Try

saving multiple image to local folder using its default filename in vb.net

I was trying to save multiple image to a local folder in one go in vb. Right now, i am able to save one image at a time to a specified folder. In my code, i have set up a file name for the image to use when uploaded. What I needed is to save the image with it's original file name and file type. My program should also allow user to save multiple images in one go.
I am Using VB 2013 Ultimate
this is the code for searching.
Try
a.Filter = "Image files | *.*"
If a.ShowDialog() = Windows.Forms.DialogResult.OK Then
PictureBox1.Image = Image.FromFile(a.FileName)
PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
and this is my code for saving
If (Not System.IO.Directory.Exists("d:/Site Images/" & Label33.Text & "/")) Then
System.IO.Directory.CreateDirectory("d:/Site Images/" & Label33.Text & "/")
End If
'Dim address = ("d:/Site Images/" & a.FileName & ".jpg")
PictureBox1.Image.Save("d:/Site Images/" & Label33.Text & "/" & "a.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
thanks for the help.
A sample snippet
Dim a As New OpenFileDialog
a.Filter = "Jpeg Files|*.jpg"
a.ShowDialog()
For i As Integer = 0 To a.FileNames.Count - 1
Try
Dim img As Image = Image.FromFile(a.FileNames(i))
img.Save("Your Saving Path")
Catch ex As Exception
End Try
Next

Image location won't write to file and Image won't load from file location

well I want to make the program write a an image location to a text file, and then when the user presses the "load" button, it reads that image location and sets it as the Image of the PictureBox, but so far I have had no success at all.
Private Sub Btn_Save_Click(sender As Object, e As EventArgs) Handles Btn_Save.Click
Dim path As String = My.Computer.FileSystem.SpecialDirectories.MyPictures + "\Card Library\Configs\" + "config_card.aygo"
Dim path2 As String = My.Computer.FileSystem.SpecialDirectories.MyPictures + "\Card Library\Configs\" + "set_cardimg.aygo"
' Create or overwrite the file.
Dim fs As FileStream = File.Create(path)
Dim fs2 As FileStream = File.Create(path2)
' Add text to the file.
Dim info As Byte() =
New UTF8Encoding(True).GetBytes(
"----------Saved Card Settings----------" + vbNewLine +
"Level: " + My.Settings.Level.ToString + vbNewLine +
"NoMonster: " + My.Settings.NoMonster.ToString + vbNewLine +
"Spell: " + My.Settings.Spell.ToString + vbNewLine +
"Trap: " + My.Settings.Trap.ToString + vbNewLine +
"XYZLevel: " + My.Settings.XyzLevel.ToString + vbNewLine +
"ATKValue: " + My.Settings.ATKValue.ToString + vbNewLine +
"DEFValue: " + My.Settings.DEFValue.ToString + vbNewLine +
"AttributeID: " + My.Settings.AttributeID.ToString + vbNewLine +
"CardID: " + My.Settings.CardID.ToString)
fs.Write(info, 0, info.Length)
fs.Close()
Dim info2 As Byte() =
New UTF8Encoding(True).GetBytes(CardImage.InitialImage.ToString)
fs2.Write(info2, 0, info2.Length)
fs2.Close()
MsgBox("Configuration saved successfully!", vbInformation)
End Sub
Private Sub Btn_Load_Click(sender As Object, e As EventArgs) Handles Btn_Load.Click
Dim path As String = My.Computer.FileSystem.SpecialDirectories.MyPictures + "\Card Library\Configs\" + "config_card.aygo"
Try
My.Settings.Level = CInt(GetSettingItem(path, "level"))
My.Settings.NoMonster = CInt(GetSettingItem(path, "nomonster"))
My.Settings.Spell = CBool(GetSettingItem(path, "spell"))
My.Settings.Trap = CBool(GetSettingItem(path, "trap"))
If My.Settings.NoMonster = 1 Then
If My.Settings.Spell = True Then
CardFt.Card_Spell()
Else
If My.Settings.Trap = True Then
CardFt.Card_Trap()
Else
CardFt.Card_Legendary()
End If
End If
End If
My.Settings.XyzLevel = CInt(GetSettingItem(path, "xyzlevel"))
If My.Settings.XyzLevel = 1 Then
CardFt.Card_XYZ()
End If
My.Settings.ATKValue = GetSettingItem(path, "atkvalue")
ATKText.Text = GetSettingItem(path, "atkvalue")
My.Settings.DEFValue = GetSettingItem(path, "defvalue")
DEFText.Text = GetSettingItem(path, "defvalue")
My.Settings.AttributeID = CInt(GetSettingItem(path, "attributeid"))
If My.Settings.AttributeID = 1 Then
AttributeLayer.Image = My.Resources.Earth
ElseIf My.Settings.AttributeID = 2 Then
AttributeLayer.Image = My.Resources.Water
ElseIf My.Settings.AttributeID = 3 Then
AttributeLayer.Image = My.Resources.Fire
ElseIf My.Settings.AttributeID = 4 Then
AttributeLayer.Image = My.Resources.Wind
ElseIf My.Settings.AttributeID = 5 Then
AttributeLayer.Image = My.Resources.Dark
ElseIf My.Settings.AttributeID = 6 Then
AttributeLayer.Image = My.Resources.Light
ElseIf My.Settings.AttributeID = 7 Then
AttributeLayer.Image = My.Resources.Divine
End If
My.Settings.CardID = CInt(GetSettingItem(path, "cardid"))
CardFt.Card_Loader()
If My.Computer.FileSystem.FileExists(My.Computer.FileSystem.SpecialDirectories.MyPictures + "\Card Library\Configs\" + "set_cardimg.aygo") Then
Try
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.MyPictures + "\Card Library\Configs\" + "set_cardimg.aygo")
Catch ex As Exception : End Try
End If
Dim bitmap As New Bitmap(My.Computer.FileSystem.SpecialDirectories.MyPictures + "Card Library\Configs\" + "set_cardimg.aygo")
CardImage.Image = CType(bitmap, System.Drawing.Image)
Catch ex As Exception
MsgBox("An error occured while loading the configuration file: " & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.ToString, vbExclamation)
My.Computer.Clipboard.SetText(ex.ToString)
End Try
End Sub
The error that I get from this is:
System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap..ctor(String filename)
at AnimeYuGiOhCardMaker.CardMaker.Btn_Load_Click(Object sender, EventArgs e) in C:\Users\Compusys\Documents\Visual Studio 2012\Projects\Anime Yu-Gi-Oh Card Maker\Anime Yu-Gi-Oh Card Maker\Form1.vb:line 521
Now then, when the Save Button is being pressed It does not write the image location to file however it writes the following:
System.Drawing.Bitmap
This is why I get the error above.
The actual error is from here:
Dim bitmap As New Bitmap(My.Computer.FileSystem.SpecialDirectories.MyPictures + "Card Library\Configs\" + "set_cardimg.aygo")
CardImage.Image = CType(bitmap, System.Drawing.Image)
The error occurs even with an actual file path.
I tried a few different ways but none of them worked. Any help would be really appreciated. Thanks.
--
Dom
The original question has changed several times, including the exception. The current state of the question has several problems, the main one being this:
If My.Computer.FileSystem.FileExists(My.Computer.FileSystem.SpecialDirectories.MyPictures + "\Card Library\Configs\" + "set_cardimg.aygo") Then
Try
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.MyPictures _
+ "\Card Library\Configs\" + "set_cardimg.aygo")
' EMPTY CATCH !!!!!!
Catch ex As Exception : End Try
End If
Dim bitmap As New Bitmap(My.Computer.FileSystem.SpecialDirectories.MyPictures _
+ "Card Library\Configs\" + "set_cardimg.aygo")
CardImage.Image = CType(bitmap, System.Drawing.Image)
set_cardimg.aygo is just a config file which contains some text. it is not a valid image file, so you cannot create a bitmap from it.
You should open that file, read the contents into a variable, then if it is a valid location, create the bitmap from it, or better just set the picturebox .Location and let it load the image without you creating a bitmap first.