需要常量表达式

时间:2015-05-17 00:45:12

标签: vba excel-vba excel

我想知道可以在括号中的静态数组中设置文本,如下面的代码。

private void GenerateSingleImageVideo()
    { 
        string imagePath = textBoxImagePath.Text;
        Bitmap thisBitmap;

        //generate bitmap from image file
        using (Stream BitmapStream = System.IO.File.Open(imagePath, FileMode.Open))
        {
            Image img = Image.FromStream(BitmapStream);
            thisBitmap = new Bitmap(img);
        }

        //convert the bitmap to a byte array
        byte[] byteArray = BitmapToByteArray(thisBitmap);

        //creates the writer of the file (to save the video)
        var writer = new AviWriter(textBoxFileName.Text + ".avi")
        {
            FramesPerSecond = int.Parse(textBoxFrameRate.Text),
            EmitIndex1 = true
        };

        var stream = writer.AddVideoStream();
        stream.Width = thisBitmap.Width;
        stream.Height = thisBitmap.Height;
        stream.Codec = KnownFourCCs.Codecs.Uncompressed;
        stream.BitsPerPixel = BitsPerPixel.Bpp32;

        int numberOfFrames = ((int.Parse(textBoxFrameRate.Text)) * (int.Parse(textBoxVideoLength.Text)));
        int count = 0;

        while (count <= numberOfFrames)
        {
            stream.WriteFrame(true, byteArray, 0, byteArray.Length);
            count++;
        }
        writer.Close();
        MessageBox.Show("Done");


    }

    private byte[] BitmapToByteArray(Bitmap img)
    {
        ImageConverter converter = new ImageConverter();
        return (byte[])converter.ConvertTo(img, typeof(byte[]));
    }

2 个答案:

答案 0 :(得分:1)

是的,有可能

Sub Sample()
    Const Costs = 1
    Const Revenues = 2

    Dim myarray(1 To 10, Costs To Revenues)

    myarray(1, Costs) = "Sid"
    myarray(1, Revenues) = "Rout"

    MsgBox myarray(1, Costs)
    MsgBox myarray(1, Revenues)
End Sub

答案 1 :(得分:0)

AFAIK在VBA中为数组使用初始值设定项的唯一方法是使用Array函数。请注意,它必须声明为Variant:

Sub ArrayDemo()

    Dim strings As Variant
    strings = Array("one", "two", "three")

    Dim counter As Integer
    For counter = LBound(strings) To UBound(strings)
        Debug.Print strings(counter)
    Next counter

End Sub