|
-
Oct 28th, 2005, 02:39 AM
#1
Thread Starter
Lively Member
[Resolved] - PictureBox to Binary file
hi there,
I wanna know how to read picture file and write it to some binary file. actually i'm a newbee to read/write a binary file. say i'm having a picturebox and an command button, on click of command btn i hv to save picturebox file to a binary file. how to do reading it??, whats byte array??, how to write ??
also, i need to store the some data (say path of picture file) some where in a binary file only, can i do this, so while loading the binary file i'can get path of the picture file, and load the picture properly.
plz help soon
thanx in advance
harry
Last edited by harishs; Dec 2nd, 2005 at 06:18 AM.
Reason: problem solved
-
Oct 28th, 2005, 02:46 AM
#2
Frenzied Member
Re: PictureBox to Binary file
why would u want to write the path of the file into the same file. u wont be able to open it anyways without knowing the path, can u?
-
Oct 28th, 2005, 04:10 AM
#3
Hyperactive Member
Re: PictureBox to Binary file
I agree with the above.
But you chould write the file back out with your path follwed by the picture data it's self.
as follows below. note this is a quick example. so you need to tidy it up a little but it works.
VB Code:
Private Type BmpHead
BmpFilename As String
BmpData As String
End Type
Dim BitmapInfo As BmpHead
Private Sub Command1_Click()
Dim bmp As String
Dim BmpData As String
bmp = "C:\test.bmp" 'Load in bitmap
BitmapInfo.BmpFilename = bmp ' Store the filename
'Read in the test.bmp data
Open bmp For Binary As #1
BmpData = Space(LOF(1))
Get #1, , BmpData
Close #1
'Store the bmp data into BitmapInfo
BitmapInfo.BmpData = BmpData
BmpData = "" 'Clear data
'Delete the original bitmap file
Kill BitmapInfo.BmpFilename
'Save our custom filetype
Open "C:\somefile.cus" For Binary As #1
Put #1, , BitmapInfo 'Save BitmapInfo
Close #1
'Clean up BitmapInfo
BitmapInfo.BmpFilename = ""
BitmapInfo.BmpData = ""
'Now reaload anything
Open "C:\somefile.cus" For Binary As #1
Get #1, , BitmapInfo 'Get custom format data
Close #1
Me.Caption = BitmapInfo.BmpFilename 'just shows the filename
'Extact the bitmap inside of BitmapInfo to the path above
Open BitmapInfo.BmpFilename For Binary As #1
Put #1, , BitmapInfo.BmpData
Close #1
'Now reload and display on forum
Me.Picture = LoadPicture(BitmapInfo.BmpFilename)
'Now readload out custom filetype
End Sub
When your dreams come true.
On error resume pulling hair out.
-
Oct 28th, 2005, 05:11 AM
#4
Thread Starter
Lively Member
Re: PictureBox to Binary file
thanx friends,
very sorry to say, i was so much frustrated that i couldn't mark out the mistake that no need to keep the track of file name.
code given by you worked out for me...
anyways thanx alot..
harry
-
Oct 28th, 2005, 09:47 AM
#5
Hyperactive Member
Re: PictureBox to Binary file
Glad we chould provide you with some help.
When your dreams come true.
On error resume pulling hair out.
-
Oct 28th, 2005, 09:49 AM
#6
Re: PictureBox to Binary file
I might have totally misunderstood this question, but why not simply use the SavePicture function?
VB Code:
SavePicture Picture1.Picture, "C:\SomePic.bmp"
-
Nov 8th, 2005, 03:43 AM
#7
Thread Starter
Lively Member
Re: PictureBox to Binary file
hello friends,
very sorry for replying late, as i was on leave. actually the application which i'm making, it works with lots of images so saving all those images to a image file will be very bulky, so i'm using the funda of binary files.
can any body there tell me, what does this means :
put #1 , , someVariable
&
Get #1, , someVariable
i tried using it, but the data in the binary file is some what readable. am i going some wrong way?
plz help
thanx in advance
harry
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
|