none
Correcting the BMP RRS feed

  • Question

  • hi all, before I explain the problem, you may download this sample files

    I want to fix the bitmap image that inverted diagonally, In that sample files, there are 2 Files, Incorrect.bmp and Correct.bmp, I want to fix the Incorrect.bmp to be like Correct.bmp, I really don't know what I must to do and what the code I need. I hope you can help me...

    Sorry if My English so bad.

    Thanks



    • Edited by ChronO2Jam Tuesday, February 7, 2012 6:38 AM
    Monday, February 6, 2012 3:21 PM

Answers

  • Imports System.IO
    Imports System.Drawing.Imaging
    Imports System.Runtime.InteropServices
    Public Class Form1
      Dim MS As New MenuStrip
      Dim FileBtn As New ToolStripButton("File")
      Dim PB As New PictureBox
      Protected Overrides Sub OnLoad(e As System.EventArgs)
        MyBase.OnLoad(e)
        AddHandler FileBtn.Click, AddressOf FileBtn_Click
        MS.Items.Add(FileBtn)
        MS.Parent = Me
        PB.Parent = Me
        PB.BringToFront()
        PB.Dock = DockStyle.Fill
      End Sub
      Private Sub FileBtn_Click(sender As Object, e As EventArgs)
        Dim OFD As New OpenFileDialog
        If Not OFD.ShowDialog = DialogResult.OK Then Return
        Dim ojs As New ojsFile
        'Provided for future ojs files with more than one frame
        PB.Image = ojs.GetFrames(OFD.FileName)(0)
        PB.ClientSize = PB.Image.Size
        Me.ClientSize = New Size(PB.ClientSize.Width, MS.Height + PB.ClientSize.Height)
      End Sub
    End Class
    Public Class ojsFile
      Friend Signature As Int32
      Friend FrameCnt As Int16
      Friend Transparent As Int16
      Class Frame
        Friend X As Int16
        Friend Y As Int16
        Friend W As Int16
        Friend H As Int16
        Friend Reserved0 As Int32
        Friend BmpSize As Int32
        Friend Reserved1 As Int32
        Friend Bmp As Bitmap
        Sub GetFrame(BR As BinaryReader)
          X = BR.ReadInt16
          Y = BR.ReadInt16
          W = BR.ReadInt16
          H = BR.ReadInt16
          Reserved0 = BR.ReadInt32
          BmpSize = BR.ReadInt32
          Reserved1 = BR.ReadInt16
          Bmp = New Bitmap(W, H, PixelFormat.Format16bppRgb555)
          Dim BmpData As BitmapData = Bmp.LockBits(New Rectangle(0, 0, W, H), ImageLockMode.WriteOnly, Bmp.PixelFormat)
          Marshal.Copy(BR.ReadBytes(BmpSize), 0, BmpData.Scan0, BmpSize)
          Bmp.UnlockBits(BmpData)
        End Sub
      End Class
      Function GetFrames(FileName As String) As Bitmap()
        Dim Bmps() As Bitmap
        Using BR As New BinaryReader(New FileStream(FileName, FileMode.Open))
          Signature = BR.ReadInt32
          FrameCnt = BR.ReadInt16
          Transparent = BR.ReadInt16
          Dim Frames(FrameCnt - 1) As Frame
          ReDim Bmps(FrameCnt - 1)
          For I As Integer = 0 To FrameCnt - 1
            Frames(I) = New Frame
            Frames(I).GetFrame(BR)
            Bmps(I) = Frames(I).Bmp
          Next
        End Using
        Return Bmps
      End Function
    End Class

    Try opening it with this program:




    Tuesday, February 7, 2012 7:03 PM

All replies

  • The stride is incorrect.  It probably can't be fixed as info was lost when it was loaded.
    Monday, February 6, 2012 4:12 PM
  • The stride is incorrect.  It probably can't be fixed as info was lost when it was loaded.
     This file actually is in OJS File using BMP Constructor like my last thread, and I trying read directly using BMP Constructor, but its give strange image like that... Its must be other way to fix it, cause some software is can read image correctly...
    Tuesday, February 7, 2012 6:32 AM
  • The stride is incorrect.  It probably can't be fixed as info was lost when it was loaded.

     This file actually is in OJS File using BMP Constructor like my last thread, and I trying read directly using BMP Constructor, but its give strange image like that... Its must be other way to fix it, cause some software is can read image correctly...
    You need to either use the software that reads it correctly or write software that parses the file correctly.
    Tuesday, February 7, 2012 6:38 AM
  • Imports System.IO
    Imports System.Drawing.Imaging
    Imports System.Runtime.InteropServices
    Public Class Form1
      Dim MS As New MenuStrip
      Dim FileBtn As New ToolStripButton("File")
      Dim PB As New PictureBox
      Protected Overrides Sub OnLoad(e As System.EventArgs)
        MyBase.OnLoad(e)
        AddHandler FileBtn.Click, AddressOf FileBtn_Click
        MS.Items.Add(FileBtn)
        MS.Parent = Me
        PB.Parent = Me
        PB.BringToFront()
        PB.Dock = DockStyle.Fill
      End Sub
      Private Sub FileBtn_Click(sender As Object, e As EventArgs)
        Dim OFD As New OpenFileDialog
        If Not OFD.ShowDialog = DialogResult.OK Then Return
        Dim ojs As New ojsFile
        'Provided for future ojs files with more than one frame
        PB.Image = ojs.GetFrames(OFD.FileName)(0)
        PB.ClientSize = PB.Image.Size
        Me.ClientSize = New Size(PB.ClientSize.Width, MS.Height + PB.ClientSize.Height)
      End Sub
    End Class
    Public Class ojsFile
      Friend Signature As Int32
      Friend FrameCnt As Int16
      Friend Transparent As Int16
      Class Frame
        Friend X As Int16
        Friend Y As Int16
        Friend W As Int16
        Friend H As Int16
        Friend Reserved0 As Int32
        Friend BmpSize As Int32
        Friend Reserved1 As Int32
        Friend Bmp As Bitmap
        Sub GetFrame(BR As BinaryReader)
          X = BR.ReadInt16
          Y = BR.ReadInt16
          W = BR.ReadInt16
          H = BR.ReadInt16
          Reserved0 = BR.ReadInt32
          BmpSize = BR.ReadInt32
          Reserved1 = BR.ReadInt16
          Bmp = New Bitmap(W, H, PixelFormat.Format16bppRgb555)
          Dim BmpData As BitmapData = Bmp.LockBits(New Rectangle(0, 0, W, H), ImageLockMode.WriteOnly, Bmp.PixelFormat)
          Marshal.Copy(BR.ReadBytes(BmpSize), 0, BmpData.Scan0, BmpSize)
          Bmp.UnlockBits(BmpData)
        End Sub
      End Class
      Function GetFrames(FileName As String) As Bitmap()
        Dim Bmps() As Bitmap
        Using BR As New BinaryReader(New FileStream(FileName, FileMode.Open))
          Signature = BR.ReadInt32
          FrameCnt = BR.ReadInt16
          Transparent = BR.ReadInt16
          Dim Frames(FrameCnt - 1) As Frame
          ReDim Bmps(FrameCnt - 1)
          For I As Integer = 0 To FrameCnt - 1
            Frames(I) = New Frame
            Frames(I).GetFrame(BR)
            Bmps(I) = Frames(I).Bmp
          Next
        End Using
        Return Bmps
      End Function
    End Class

    Try opening it with this program:




    Tuesday, February 7, 2012 7:03 PM