by Gehan Fernando (47 Submissions)
Category: Graphics
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Tue 14th August 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)
VB.Net - Save Ur Images In Binary Format, No One Can Open Ur Image, Witout Ur Application.
API Declarations
REM mail me :- [email protected]
Private _path As String = ""
Private _tm As Long
Private _fstream As FileStream
Private _bwriter As BinaryWriter
Private _breader As BinaryReader
Private _mstream As MemoryStream
Private Sub BtnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLoad.Click
Me.Cursor = Cursors.WaitCursor
With OpenBinaryImage
.Title = "Save In Binary Format"
.AddExtension = False : .CheckFileExists = True
.CheckPathExists = True : .SupportMultiDottedExtensions = False
.Multiselect = False : .ShowHelp = False
.ShowReadOnly = False : .ValidateNames = True
.Filter = "Image Files (*.jpg,*.bmp,*.gif)|*.jpg;*.bmp;*.gif|Binary Image Files (*.bif)|*.bif"
.FileName = ""
.FilterIndex = 0
.ShowDialog(Me)
_path = .FileName.ToString()
End With
If _path <> "" Then
If String.Compare(Path.GetExtension(_path), ".jpg", True) = 1 And _
String.Compare(Path.GetExtension(_path), ".bmp", True) = 1 And _
String.Compare(Path.GetExtension(_path), ".gif", True) = 1 And _
String.Compare(Path.GetExtension(_path), ".bif", True) = 1 Then
MessageBox.Show("Invalid File Format Selected", "Binary Image", MessageBoxButtons.OK, MessageBoxIcon.Error)
OpenBinaryImage.Dispose()
Me.Cursor = Cursors.Default
Exit Sub
Else
REM If File Is {.jpg, .bmp, .gif }
If String.Compare(Path.GetExtension(_path), ".jpg", True) = 0 Or _
String.Compare(Path.GetExtension(_path), ".bmp", True) = 0 Or _
String.Compare(Path.GetExtension(_path), ".gif", True) = 0 Then
Try
PicBinary.Image = Image.FromFile(_path)
PicBinary.Refresh()
LblPath.Text = "" : LblPath.Text = _path
Catch ex As Exception
MessageBox.Show(ex.Message, "Binary Image", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Else
REM If File Is {.bif }
Try
_fstream = New FileStream(_path, FileMode.Open, FileAccess.Read)
_breader = New BinaryReader(_fstream)
Dim temp As Object
REM Read Path Value
LblPath.Text = _breader.ReadString()
REM Read Symbol Value
temp = _breader.ReadString() : temp = ""
REM Read Buffer Size
Dim buffl As Long = _breader.ReadUInt32()
Dim buff(buffl) As Byte
REM Read Image
buff = _breader.ReadBytes(buffl)
Array.Reverse(buff)
_mstream = New MemoryStream(buff, True)
_mstream.Write(buff, 0, buff.Length)
_mstream.Flush()
Dim img As New Bitmap(_mstream)
PicBinary.Image = img
_mstream.Close()
_mstream.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message, "Binary Image", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
_fstream.Dispose()
_breader.Close()
End Try
End If
End If
Else
OpenBinaryImage.Dispose()
End If
Me.Cursor = Cursors.Default
End Sub
Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
_path = ""
PicBinary.Image = Nothing
LblPath.Text = ""
End Sub
Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
Me.Cursor = Cursors.WaitCursor
If _path.ToString().Trim().Length = 0 Then
MessageBox.Show("Load Image Into Screen Before Save.", "Binary Image", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Cursor = Cursors.Default
Exit Sub
End If
If String.Compare(Path.GetExtension(_path), ".bif", True) = 0 Then
MessageBox.Show("File Already In Binary Format", "Binary Image", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Cursor = Cursors.Default
Exit Sub
End If
_tm = CType(Now().ToLocalTime().ToOADate(), Double) + (Now.Second + Now.Millisecond)
Try
_fstream = New FileStream(_path, FileMode.Open, FileAccess.Read)
Dim buff(_fstream.Length) As Byte
For i As Long = 0 To _fstream.Length - 1
buff(i) = _fstream.ReadByte()
Next
_fstream.Read(buff, 0, _fstream.Length)
_fstream.Flush()
_fstream.Close()
_bwriter = New BinaryWriter(File.Open("C:\" & _tm & ".bif", FileMode.CreateNew, FileAccess.Write))
_bwriter.Write("C:\" & _tm & ".bif")
_bwriter.Write("~`!@#$%^&*()_+-={}|:?><,./;'[]\ ~`!@#$%^&*()_+-={}|:?><,./;'[]\")
_bwriter.Write(buff.Length)
Array.Reverse(buff)
_bwriter.Write(buff)
MessageBox.Show("Image Conver To Binary Successfully.", "Binary Image", MessageBoxButtons.OK, MessageBoxIcon.Information)
Call BtnClear_Click(sender, e)
Catch ex As Exception
MessageBox.Show(ex.Message, "Binary Image", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
_fstream.Dispose()
_bwriter.Close()
End Try
Me.Cursor = Cursors.Default
End Sub
End Class
No comments have been posted about VB.Net - Save Ur Images In Binary Format, No One Can Open Ur Image, Witout Ur Application.. Why not be the first to post a comment about VB.Net - Save Ur Images In Binary Format, No One Can Open Ur Image, Witout Ur Application..