hi all, I am new in here and I want asking, I have program that read the image from file with extension .ojn, I can show that image file into picturebox, Here my code to read the image:

VB.NET Syntax (Toggle Plain Text)

Dim path As String
    path = openfiledialog1.filename
    Using fs As New FileStream(path, FileMode.Open)
    Using rdr As New BinaryReader(fs)
    Dim Image As System.Drawing.Image = Nothing
    fs.Seek(268, System.IO.SeekOrigin.Begin)
    Dim BinaryReader As System.IO.BinaryReader = New System.IO.BinaryReader(fs)
    Dim ImageLength As System.Int32 = BinaryReader.ReadInt32
    fs.Seek(296, System.IO.SeekOrigin.Begin)
    Dim ImageOffset As System.Int32 = BinaryReader.ReadInt32
    fs.Seek(ImageOffset, System.IO.SeekOrigin.Begin)
    Dim Buffer(ImageLength - 1) As System.Byte
    Dim BytesRead As System.Int32 = 0
    BytesRead = fs.Read(Buffer, 0, Buffer.Length)
    If BytesRead = Buffer.Length Then
    Dim MemoryStream As System.IO.MemoryStream = New System.IO.MemoryStream(Buffer)
    Image = System.Drawing.Image.FromStream(MemoryStream).Clone
    PictureBox1.Image = Image
    End If
    End Using
    End Using
    Catch ex As Exception
    MsgBox(ex.Message , vbCritical, "Error!")
    End Try

268 is offset that contain image size (in byte) and 296 is offset that contains the image.

I want user can replace image on offset 296 and write size of selected image to 268.
Sorry If My English so bad, Thanks!

6 Years
Discussion Span
Last Post by lolafuertes

Probably you can do it using the BibaryWriter class instead of the BinaryReader.

But... there is always a but.

The magic is to know what info exists on the rest of the original header and file, and if this should be changed or moved due to the new size. IE some of the offsets info for other contents in the file, the other contents, etc.

The .ojn is normally used for open2jam songs, and you can find the header info here. Havein mind that if you change the picture size, all the rest of he contents probaly must change their contents or position in the file.

Hope this helps

Edited by lolafuertes: n/a


yea ojn is O2jam file that contain note, I already read it before, but its using java, I already contact the site owner (Chaosfox) but he dont have any idea about this... I just want write the image size to offset 268 and write the picture on offset 296


I would suggest:

1) Use a InFilestream for existing input file and an OutFilestream for a new (and distinct) output file.
2) Use an InBinaryreader for read the original file and an OutBinaryWriter to write the output file
3) For each byte read, write a byte in the OutBunaryWriter unless:
* The read byte is the 268: At this moment
a) write in the output the int value of the length of the new image (4 bytes)
b) get 4 bytes from the input needed to read the length of the old image.
c) Continue the for each

* The read byte is the 296: At this moment
a) Write in the output the image
b) Skip from the input as many bytes as the length of the old image

If you do not have in mind the other headers info and their meanings, probably you will corrupt the file, specially the note_offest (there are 3) and the cover offsets, except if the new image is exactly the same length than the old one.

Hope this helps.

Edited by lolafuertes: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.