Results 1 to 7 of 7

Thread: [Resolved] - PictureBox to Binary file

  1. #1

    Thread Starter
    Lively Member harishs's Avatar
    Join Date
    Jul 2005
    Location
    Bombay, India
    Posts
    118

    Resolved [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

  2. #2
    Frenzied Member
    Join Date
    May 2003
    Location
    Sydney
    Posts
    1,123

    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?

  3. #3
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    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:
    1. Private Type BmpHead
    2.     BmpFilename As String
    3.     BmpData As String
    4. End Type
    5.  
    6. Dim BitmapInfo As BmpHead
    7.  
    8.  
    9. Private Sub Command1_Click()
    10. Dim bmp As String
    11. Dim BmpData As String
    12.  
    13.     bmp = "C:\test.bmp" 'Load in bitmap
    14.     BitmapInfo.BmpFilename = bmp ' Store the filename
    15.     'Read in the test.bmp data
    16.     Open bmp For Binary As #1
    17.         BmpData = Space(LOF(1))
    18.         Get #1, , BmpData
    19.     Close #1
    20.    
    21.     'Store the bmp data into BitmapInfo
    22.     BitmapInfo.BmpData = BmpData
    23.     BmpData = "" 'Clear data
    24.     'Delete the original bitmap file
    25.    
    26.     Kill BitmapInfo.BmpFilename
    27.    
    28.     'Save our custom filetype
    29.     Open "C:\somefile.cus" For Binary As #1
    30.         Put #1, , BitmapInfo 'Save BitmapInfo
    31.     Close #1
    32.    
    33.     'Clean up BitmapInfo
    34.     BitmapInfo.BmpFilename = ""
    35.     BitmapInfo.BmpData = ""
    36.     'Now reaload anything
    37.    
    38.     Open "C:\somefile.cus" For Binary As #1
    39.         Get #1, , BitmapInfo 'Get custom format data
    40.     Close #1
    41.    
    42.     Me.Caption = BitmapInfo.BmpFilename 'just shows the filename
    43.     'Extact the bitmap inside of BitmapInfo to the path above
    44.    
    45.     Open BitmapInfo.BmpFilename For Binary As #1
    46.         Put #1, , BitmapInfo.BmpData
    47.     Close #1
    48.     'Now reload and display on forum
    49.    
    50.     Me.Picture = LoadPicture(BitmapInfo.BmpFilename)
    51.     'Now readload out custom filetype
    52.  
    53. End Sub
    When your dreams come true.
    On error resume pulling hair out.

  4. #4

    Thread Starter
    Lively Member harishs's Avatar
    Join Date
    Jul 2005
    Location
    Bombay, India
    Posts
    118

    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

  5. #5
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: PictureBox to Binary file

    Glad we chould provide you with some help.
    When your dreams come true.
    On error resume pulling hair out.

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: PictureBox to Binary file

    I might have totally misunderstood this question, but why not simply use the SavePicture function?
    VB Code:
    1. SavePicture Picture1.Picture, "C:\SomePic.bmp"

  7. #7

    Thread Starter
    Lively Member harishs's Avatar
    Join Date
    Jul 2005
    Location
    Bombay, India
    Posts
    118

    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
  •  



Click Here to Expand Forum to Full Width