Avatar billede swiffer Nybegynder
17. februar 2003 - 18:27 Der er 1 kommentar og
1 løsning

Få fat i bredde/højde på en flashfil?

Her kan man få en masse info ud af en swf-fil:
http://www.4guysfromrolla.com/webtech/tips/t102001-1.shtml

Jeg kan ikke overskue siden, men hvordan tilpasser jeg scriptet, så jeg kun får bredden og højden? Alt det andet er jo bare spild af serverkraft. Jeg vil gerne have det ud af det der funktion-klasse halløj, så jeg kun har det "rene" script.

På forhånd tak :)
Avatar billede hnteknik Novice
17. februar 2003 - 18:43 #1
Er det sådan noget ???
Henrik

dim stfilename                                                   
astfilename = "c:\myflashfile.swf"                                 
                                                                   
<!--#include file="swfparser.asp" --> 
//----SWFParser.asp------
<script language="JScript" runat="Server">
// the following code is modified from openswf.org to work in JScript

var m_bitPos = 0;
var m_bitBuf = 0;
var m_fileBuf = 0;

function InitBits()
{
    m_bitPos = 0;
    m_bitBuf = 0;
}

function GetRect()
// gets my four coordinates
{
    InitBits();
    nBits = GetBits(5);
    xmin = GetSBits(nBits);
    xmax = GetSBits(nBits);
    ymin = GetSBits(nBits);
    ymax = GetSBits(nBits);
}

function GetSBits(n)
// Get n bits from the string with sign extension.
{
    // Get the number as an unsigned value.
    v = GetBits(n);

    // Is the number negative?
    if (v & (1 << (n - 1)))
    {
        // Yes. Extend the sign.
        v |= -1 << n;
    }

    return v;
}

function GetBits (n)
// Get n bits from the stream.
{
    v = 0;
    s = 0;
    while (true)
    {
        //response.write("n:" + n + "<br>")
        //response.write("s:" + s + "<br>")
        //response.write("m_bitPos:" + m_bitPos + "<br>")
        s = n - m_bitPos;
        if (s > 0)
        {
            // Consume the entire buffer
            v |= m_bitBuf << s;
            n -= m_bitPos;

            // Get the next buffer
            m_bitBuf = ReturnBin(objStream.read(1));
            m_bitPos = 8;
        }
        else
        {
            // Consume a portion of the buffer
            v |= m_bitBuf >> -s;
            m_bitPos -= n;
            m_bitBuf &= 0xff >> (8 - m_bitPos); // mask off the consumed bits

            return v;
        }
    }
}
</script>

<%
' the ConvertBin function and use of the objStream started
' from this article on 4 Guys From Rolla:
' http://www.4guysfromrolla.com/webtech/tips/t041701-1.shtml

Function ConvertBin(Binary)
    'This function converts a binary byte into an ASCII byte.
    for i = 1 to LenB(Binary)
        strChar = chr(AscB(MidB(Binary,i,1)))
        ConvertBin = ConvertBin & strChar
    Next
End Function
Function ReturnBin(Binary)
    'This function converts a binary byte into an ASCII byte.
    for i = 1 to LenB(Binary)
        strChar = AscB(MidB(Binary,i,1))
        ReturnBin = ReturnBin & strChar
    Next
End Function

  dim objStream
  dim strTag, strFilepath, i, strChar
  dim isFlash
  isFlash = false
  strFilepath = astfilename

  'Create the Stream object
  set objStream = Server.CreateObject("ADODB.Stream")
  objStream.Type = adTypeBinary

    'Open the stream
    objStream.Open
    objStream.LoadFromFile strFilepath

    'Start from the beginning of the file
    objStream.Position = 0

    'Read the first three characters of the file
    strTag = ConvertBin(objStream.Read(3))
    if ucase(strTag) = "FWS" then isFlash=true

    ' read the next (fourth) position to get the version number
    ' return it as a Byte and not as a converted character
    dim intVersion
    intVersion = ReturnBin(objStream.Read(1))

    ' time to get the height and width
    dim curval, readbyte
    dim xmax, xmin, ymax, ymin, swfheight, swfwidth

    ' jump to the 9th position (don't forget that 0 is a position, too!)
    objStream.Position = 8

    ' jump into the JScript with GetRect() that will get the four
coordinates
    GetRect()

    ' SWF files calculate width and height in TWIPS (1/20th of a point)
    ' Therefore, we divide by 20 to get the number of pixels
    swfwidth = (xmax - xmin) / 20
    swfheight = (ymax - ymin) / 20

    'Display the results
    'response.write("Filename: " & strFilepath & "<br>" & vbCrLF)
    'response.write("Is it a flash file: " & isFlash & "<br>" & vbCrLF)
    'response.write("Flash version: " & intVersion & "<br>" & vbCrLF)
    'response.write("Width: " & swfwidth & "<br>" & vbCrLF)
    'response.write("Height: " & swfheight & "<br>" & vbCrLF)

    objStream.Close
  Set objStream = Nothing    'Clean up...
%>
Avatar billede hnteknik Novice
17. februar 2003 - 18:47 #2
Ups

dim astfilename
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester