Click here to Skip to main content
16,016,527 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Trying to merge exel print jobs Pin
Dave Kreskowiak21-Jun-12 5:18
mveDave Kreskowiak21-Jun-12 5:18 
GeneralRe: Trying to merge exel print jobs Pin
Nick Otten21-Jun-12 21:26
Nick Otten21-Jun-12 21:26 
AnswerRe: Trying to merge exel print jobs Pin
Mycroft Holmes21-Jun-12 19:42
professionalMycroft Holmes21-Jun-12 19:42 
GeneralRe: Trying to merge exel print jobs Pin
Nick Otten21-Jun-12 21:32
Nick Otten21-Jun-12 21:32 
GeneralRe: Trying to merge exel print jobs Pin
Mycroft Holmes21-Jun-12 22:18
professionalMycroft Holmes21-Jun-12 22:18 
Questionbyte array to string Pin
jkirkerx20-Jun-12 18:06
professionaljkirkerx20-Jun-12 18:06 
SuggestionRe: byte array to string Pin
Sandeep Mewara20-Jun-12 19:36
mveSandeep Mewara20-Jun-12 19:36 
GeneralRe: byte array to string Pin
jkirkerx20-Jun-12 20:10
professionaljkirkerx20-Jun-12 20:10 
I figured out the loop count, forgot for increments the counter automatically, so I had double increments. So that function is fixed now, I get the correct value string.

Now I'm stuck on this this function, I'm pretty close now, just the width is wrong, double the correct value, should be 650x325. Without the input stream, how would you know.

Sorry to post so much code, Trying to convert this
Sub Page Load()
Dim swf As SwfParser = New SwfParser
Dim swfRect As Drawing.Rectangle = New Drawing.Rectangle
swfRect = swf.get_SWF_Dimensions("p:/flash/Bowling_Jazz_Collection.swf")

Dim iWidth As Integer = swfRect.Width 'suppose to be 625, but is 1300
Dim iHeight As Integer = swfRect.Height 'I got this right 325

swf = Nothing
End Sub
public class SwfParser
{
    public Rectangle GetDimensions(String filePath)
    {
        using (FileStream stream = File.OpenRead(filePath))
        {
            return GetDimensions(stream);
        }
    }

    public Rectangle GetDimensions(Stream stream)
    {        
        Stream inputStream = null;
        byte[] signature = new byte[8];
        byte[] rect = new byte[8];
        stream.Read(signature, 0, 8);
        if ("CWS" == System.Text.Encoding.ASCII.GetString(signature, 0, 3))
        {
            inputStream = new InflaterInputStream(stream);
        }
        else
        {
            inputStream = stream;
        }

        inputStream.Read(rect, 0, 8);
        int nbits = rect[0] >> 3;
        rect[0] = (byte)(rect[0] & 0x07);
        String bits = ByteArrayToBitString(rect);
        bits = bits.Remove(0, 5);
        int[] dims = new int[4];
        for (int i = 0; i < 4; i++)
        {
            char[] dest = new char[nbits];
            bits.CopyTo(0, dest, 0, bits.Length>nbits ? nbits : bits.Length);
            bits = bits.Remove(0, bits.Length > nbits ? nbits : bits.Length);
            dims[i] = BitStringToInteger(new String(dest)) / 20;
        }

        return new Rectangle(0, 0, dims[1] - dims[0], dims[3] - dims[2]);
    }

    private int BitStringToInteger(String bits)
    {
        int converted = 0;
        for (int i = 0; i < bits.Length; i++)
        {
            converted = (converted << 1) + (bits[i] == '1' ? 1 : 0);
        }
        return converted;
    }

    private String ByteArrayToBitString(byte[] byteArray)
    {
        byte[] newByteArray = new byte[byteArray.Length];
        Array.Copy(byteArray, newByteArray, byteArray.Length);
        String converted = "";
        for (int i = 0; i < newByteArray.Length; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                converted += (newByteArray[i] & 0x80) > 0 ? "1" : "0";
                newByteArray[i] <<= 1;
            }
        }
        return converted;
    }
}


This is my conversion
Public Class SwfParser

    Public Function get_SWF_Dimensions(ByVal filePath As String) As Rectangle

        Dim fileLength As Long = 0
        Dim stream As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
        Dim fsLen As Long = stream.Length

        Dim rec As Rectangle = getDimensions(stream)


    End Function
    Private Function getDimensions(ByVal stream As Stream) As Rectangle

        Dim inputStream As Stream = Nothing
        Dim signature() As Byte = New Byte(8) {}
        Dim rect() As Byte = New Byte(8) {}
        stream.Read(signature, 0, 8)

        If (System.Text.Encoding.ASCII.GetString(signature, 0, 3) = "CWS") Then
            inputStream = New InflaterInputStream(stream)
        Else
            inputStream = stream
        End If

        inputStream.Read(rect, 0, 8)
        Dim nbits As Integer = rect(0) >> 3
        rect(0) = rect(0) And &H7
        Dim bits As String = ByteArrayToBitString(rect)
        bits = bits.Remove(0, 5)
        Dim dims(4) As Integer

        For idx As Integer = 0 To 3
            // These 4 lines, I'm in doubt, I think I got it wrong
            Dim dest() As Char = New Char(nbits) {}
            bits.CopyTo(0, dest, 0, If(bits.Length > nbits, nbits, bits.Length))
            bits = bits.Remove(0, If(bits.Length > nbits, nbits, bits.Length))
            dims(idx) = BitStringToInteger(New String(dest)) / 20
        Next

        Return New Rectangle(0, 0, dims(1) - dims(0), dims(3) - dims(2))

    End Function
    Private Function BitStringToInteger(ByVal bits As String) As Integer

        Dim converted As Integer = 0

        For idx As Integer = 0 To bits.Length - 1
           // This Line, I'm not sure, I think I got it right 
           converted = (converted << 1) + If(bits(idx) = "1", 1, 0)
        Next

        Return converted

    End Function
    Private Function ByteArrayToBitString(ByVal byteArray() As Byte) As String

        Dim newByteArray() As Byte = New Byte(byteArray.Length - 1) {}

        Array.Copy(byteArray, newByteArray, byteArray.Length - 1)
        Dim converted As String = ""

        For idx As Integer = 0 To newByteArray.Length - 1
            For jdx As Integer = 0 To 7
                converted += If((newByteArray(idx) And &H80) > 0, "1", "0")
                newByteArray(idx) <<= 1
            Next
        Next

        Return converted

    End Function


End Class

GeneralRe: byte array to string Pin
Sandeep Mewara21-Jun-12 19:17
mveSandeep Mewara21-Jun-12 19:17 
GeneralRe: byte array to string Pin
jkirkerx21-Jun-12 20:31
professionaljkirkerx21-Jun-12 20:31 
AnswerRe: byte array to string Pin
Nick Otten21-Jun-12 2:43
Nick Otten21-Jun-12 2:43 
QuestionPassword Storage Class Pin
flinchy318-Jun-12 4:31
flinchy318-Jun-12 4:31 
AnswerRe: Password Storage Class Pin
908236518-Jun-12 6:26
908236518-Jun-12 6:26 
GeneralRe: Password Storage Class Pin
flinchy318-Jun-12 7:28
flinchy318-Jun-12 7:28 
GeneralRe: Password Storage Class Pin
908236519-Jun-12 5:29
908236519-Jun-12 5:29 
GeneralRe: Password Storage Class Pin
flinchy321-Jun-12 4:17
flinchy321-Jun-12 4:17 
GeneralRe: Password Storage Class Pin
908236521-Jun-12 5:30
908236521-Jun-12 5:30 
GeneralRe: Password Storage Class Pin
908236522-Jun-12 10:39
908236522-Jun-12 10:39 
GeneralRe: Password Storage Class Pin
flinchy328-Jun-12 1:20
flinchy328-Jun-12 1:20 
GeneralRe: Password Storage Class Pin
flinchy328-Jun-12 1:25
flinchy328-Jun-12 1:25 
QuestionHow to get session state in VB.NET desktop app Pin
ilgrongo18-Jun-12 3:38
ilgrongo18-Jun-12 3:38 
AnswerRe: How to get session state in VB.NET desktop app Pin
Dave Kreskowiak18-Jun-12 10:53
mveDave Kreskowiak18-Jun-12 10:53 
GeneralRe: How to get session state in VB.NET desktop app Pin
ilgrongo18-Jun-12 13:04
ilgrongo18-Jun-12 13:04 
GeneralRe: How to get session state in VB.NET desktop app Pin
Dave Kreskowiak18-Jun-12 14:51
mveDave Kreskowiak18-Jun-12 14:51 
GeneralRe: How to get session state in VB.NET desktop app Pin
ilgrongo18-Jun-12 19:52
ilgrongo18-Jun-12 19:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.