示例#1
0
文件: Swf2.cs 项目: tdenc/nicorank
        public void SaveMp3(string filename)
        {
            FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write);

            for (int i = 0; i < tag_list_.Count; ++i)
            {
                if ((int)tag_list_[i].tag == (int)ObjectType.SoundStreamBlock)
                {
                    const int offset = 4;
                    data_stream_.Seek(tag_list_[i].position + offset, SeekOrigin.Begin);
                    StreamUtil.Copy(data_stream_, fs, (int)tag_list_[i].size - offset);
                }
            }
            fs.Close();
        }
示例#2
0
文件: Swf2.cs 项目: tdenc/nicorank
            public void Parse(Tags tags, BinaryReader reader, int size)
            {
                reader.BaseStream.Seek(tags.position, SeekOrigin.Begin);
                image_id_ = (int)reader.ReadUInt16();

                if ((int)tags.tag == (int)ObjectType.DefineBitsLossLess2)
                {
                    is_loss_less_ = true;

                    byte format = reader.ReadByte();
                    width_  = reader.ReadUInt16();
                    height_ = reader.ReadUInt16();

                    MemoryStream ms = new MemoryStream();

                    StreamUtil.Copy(reader.BaseStream, ms, size - 7);
                    ms.Seek(0, SeekOrigin.Begin);

                    ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream zis =
                        new ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream(ms);

                    MemoryStream ms2 = new MemoryStream();

                    byte[] b = new byte[1024];
                    int    s;
                    while ((s = zis.Read(b, 0, b.Length)) > 0)
                    {
                        ms2.Write(b, 0, s);
                    }
                    zis.Close();

                    ms2.Seek(0, SeekOrigin.Begin);
                    raw_data_ = new byte[ms2.Length];
                    ms2.Read(raw_data_, 0, raw_data_.Length);
                }
                else
                {
                    reader.BaseStream.Seek(tags.position, SeekOrigin.Begin);
                    image_id_ = (int)reader.ReadUInt16();
                    MemoryStream ms = new MemoryStream();
                    StreamUtil.Copy(reader.BaseStream, ms, size - 2);
                    image_ = new Bitmap(ms);
                }
            }
示例#3
0
文件: Swf2.cs 项目: tdenc/nicorank
        public void SaveJPG(string dir)
        {
            if (!dir.EndsWith("\\"))
            {
                dir += "\\";
            }
            Directory.CreateDirectory(dir);
            int count = 1;

            byte[] jpeg_tables = null;

            for (int i = 0; i < tag_list_.Count; ++i)
            {
                if ((int)tag_list_[i].tag == (int)ObjectType.DefineBitsJPEG || (int)tag_list_[i].tag == (int)ObjectType.DefineBitsJPEG2 ||
                    (int)tag_list_[i].tag == (int)ObjectType.DefineBitsJPEG3)
                {
                    FileStream fs = null;
                    try
                    {
                        fs = new FileStream(dir + count.ToString("0000") + ".jpg", FileMode.Create, FileAccess.Write);
                        if ((int)tag_list_[i].tag == (int)ObjectType.DefineBitsJPEG3)
                        {
                            // 最初の2バイトはタグなので無視
                            data_reader_.BaseStream.Seek(tag_list_[i].position + 2, SeekOrigin.Begin);
                            int image_data_size = data_reader_.ReadInt32();

                            StreamUtil.Copy(data_stream_, fs, image_data_size);
                        }
                        else
                        {
                            const int header_size = 20;
                            byte[]    pre_search  = new byte[6];
                            data_stream_.Seek(tag_list_[i].position, SeekOrigin.Begin);
                            data_stream_.Read(pre_search, 0, pre_search.Length);
                            int offset = 2;
                            if (pre_search[3] == 0xD9 && pre_search[5] == 0xD8)
                            {
                                offset += 4;
                            }
                            data_stream_.Seek(tag_list_[i].position + offset, SeekOrigin.Begin);
                            StreamUtil.Copy(data_stream_, fs, header_size);
                            if (tag_list_[i].tag == 6 && jpeg_tables != null)
                            {
                                fs.Write(jpeg_tables, 2, jpeg_tables.Length - 4); // 最初と最後2バイトずつは除く
                            }
                            StreamUtil.Copy(data_stream_, fs, (int)tag_list_[i].size - header_size - offset);
                        }
                        ++count;
                    }
                    finally
                    {
                        if (fs != null)
                        {
                            fs.Close();
                        }
                    }
                }
                else if ((int)tag_list_[i].tag == (int)ObjectType.JPEGTables)
                {
                    jpeg_tables = new byte[tag_list_[i].size];
                    data_stream_.Seek(tag_list_[i].position, SeekOrigin.Begin);
                    data_stream_.Read(jpeg_tables, 0, (int)tag_list_[i].size);
                }
            }
        }