本文整理匯總了C#中BitWriter類的典型用法代碼示例。如果您正苦於以下問題:C# BitWriter類的具體用法?C# BitWriter怎麽用?C# BitWriter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BitWriter類屬於命名空間,在下文中一共展示了BitWriter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Decode
public static byte[] Decode(byte[] data, int from, int to, int bitsInterval)
{
var copiedData = new byte[to - from + 1];
Array.Copy(data, from, copiedData, 0, copiedData.Length);
byte[] reverseBytes = Convert.ReverseBitsInBytes(copiedData);
using (var s = new MemoryStream(reverseBytes))
using (var reader = new BitReader(s))
{
using (var decoded = new MemoryStream())
using (var writer = new BitWriter(decoded))
{
int counter = 0;
while (reader.CanRead)
{
byte bit = reader.ReadBits(1);
writer.WriteBit(bit);
counter = (bit == 1) ? counter + 1 : 0;
if (counter == bitsInterval)
{
reader.ReadBits(1); // skip next 0 bit
counter = 0;
}
}
// !! do not flush last bits
return Convert.ReverseBitsInBytes(decoded.ToArray());
}
}
}
示例2: GammaCode
public static void GammaCode(ulong number, BitWriter writer)
{
// to allow zero
number += 1;
int size = 0;
ulong tmp = number;
while (tmp >= 1)
{
size++;
tmp /= 2;
}
int zeroes = size - 1;
for (int i = 0; i < zeroes; i++)
writer.Write(false);
for (int i = size - 1; i >= 0; i--)
{
bool bit = (number & (1UL << i)) != 0;
writer.Write(bit);
}
}
示例3: Encode
public static byte[] Encode(byte[] data, int bitsInterval)
{
byte[] reverseBytes = Convert.ReverseBitsInBytes(data);
using (var s = new MemoryStream(reverseBytes))
using (var reader = new BitReader(s))
{
using (var encoded = new MemoryStream())
using (var writer = new BitWriter(encoded))
{
int counter = 0;
while (reader.CanRead)
{
byte bit = reader.ReadBits(1);
writer.WriteBit(bit);
counter = (bit == 1) ? counter + 1 : 0;
if (counter == bitsInterval)
{
writer.WriteBit(0);
counter = 0;
}
}
writer.FlushBits();
return Convert.ReverseBitsInBytes(encoded.ToArray());
}
}
}
示例4: Serialize
public override void Serialize( Stream stream )
{
base.Serialize( stream );
var bw = new BitWriter();
bw.WriteInt32( Protocol );
bw.WriteInt32(AuthProtocol);
bw.WriteInt32(ServerChallenge);
bw.WriteInt32(ClientChallenge);
bw.WriteString( Name );
bw.WriteString( Password );
bw.WriteByte( ( byte )Players.Count );
foreach ( var player in Players )
{
bw.WriteByte( ( byte )CLC_Messages.clc_SplitPlayerConnect );
using ( var ms = new MemoryStream() )
{
Serializer.SerializeWithLengthPrefix( ms, player, PrefixStyle.Base128 );
bw.WriteBytes( ms.ToArray() );
}
}
// bLowViolence
bw.WriteBits( 0, 1 );
bw.WriteUInt16( ( ushort )Ticket.Length );
bw.WriteBytes( Ticket );
stream.Write( bw.Data, 0, bw.Data.Length - 1 );
}
示例5: Capture
/*
* 0 通道ID BYTE >0
1 拍攝命令 WORD
0 表示停止拍攝;0xFFFF 表示錄像;其它表示拍
照張數
3 拍照間隔/錄像時間 WORD 秒,0 表示按最小間隔拍照或一直錄像
5 保存標誌 BYTE
1:保存;
0:實時上傳
6 分辨率a BYTE
0x01:320*240;
0x02:640*480;
0x03:800*600;
0x04:1024*768;
0x05:176*144;[Qcif];
0x06:352*288;[Cif];
0x07:704*288;[HALF D1];
0x08:704*576;[D1];
7 圖像/視頻質量 BYTE 1-10,1 代表質量損失最小,10 表示壓縮比最大
8 亮度 BYTE 0-255
9 對比度 BYTE 0-127
10 飽和度 BYTE 0-127
11 色度 BYTE 0-255
*
* */
/// <summary>
/// 中心抓拍圖片
/// </summary>
/// <param name="ordinal"></param>
/// <param name="size"></param>
/// <param name="quality"></param>
/// <param name="count"></param>
/// <returns></returns>
public override byte[] Capture(uint ordinal, SizeType size, QualityType quality, byte count)
{
var mes = Message.Create(0x8801, this.terminalid + "", 0, null);
var ms = new MemoryStream();
BitWriter bw = new BitWriter(ms);
bw.Write((byte)1);//通道一
bw.Write((UInt16)count);//拍一張
bw.Write((UInt16)0);//拍照間隔
bw.Write((byte)0);//0實時上傳 1保存
byte pixel = 0x01;
switch (size) //分辨率 圖片大小
{
case SizeType.Big: pixel = 0x04; break; //
case SizeType.Normal: pixel = 0x08; break; //
case SizeType.Small: pixel = 0x01; break; //
}
bw.Write(pixel);//分辨率
byte level = 1;
switch (quality) //圖片質量
{
case QualityType.Height: level = 1; break;
case QualityType.Normal: level = 5; break;
case QualityType.Low: level = 10; break;
}
bw.Write(level);//圖片質量
bw.Write((byte)127);//亮度
bw.Write((byte)64);//對比度
bw.Write((byte)64);//飽和度
bw.Write((byte)127);//色度
mes.BodyBytes = ms.ToArray();
return mes.ToBytes();
}
示例6: Serialize
public void Serialize(BitWriter bw)
{
bw.Write(TeamNumber);
bw.Write(TeamColorId);
bw.Write(CustomColorId);
bw.Write(TeamFinishId);
bw.Write(CustomFinishId);
}
示例7: Serialize
public void Serialize(BitWriter bw)
{
bw.Write(Active);
bw.Write(ActorId);
Offset.Serialize(bw);
bw.Write(Mass);
Rotation.Serialize(bw);
}
示例8: Serialize
public void Serialize(BitWriter bw)
{
string.Join(",", Mutators).Serialize(bw);
bw.Write(Unknown1);
bw.Write(Unknown2);
GameName.Serialize();
Password.Serialize();
bw.Write(Unknown3);
}
示例9: Serialize
public void Serialize(BitWriter bw)
{
bw.Write(Unknown1);
bw.Write(AttackerActorId);
bw.Write(Unknown2);
bw.Write(VictimActorId);
AttackerVelocity.Serialize(bw);
VictimVelocity.Serialize(bw);
}
示例10: Encode
public void Encode(Stream reader, BitWriter writer)
{
if (!reader.CanRead || !reader.CanSeek)
throw new InvalidOperationException();
m_writer = writer;
Encode(reader);
}
示例11: Serialize
public void Serialize(BitWriter bw)
{
bw.Write(FieldOfView);
bw.Write(Height);
bw.Write(Pitch);
bw.Write(Distance);
bw.Write(Stiffness);
bw.Write(SwivelSpeed);
}
示例12: Compress
public static void Compress(string inputFile, string outputFile)
{
var coder = new Coder();
using (var reader = File.OpenRead(inputFile))
using (var writer = new BitWriter(outputFile))
{
coder.Encode(reader, writer);
}
}
示例13: Serialize
public void Serialize(BitWriter bw)
{
bw.Write(Sleeping);
Position.Serialize(bw);
Rotation.SerializeFixed(bw);
if (!Sleeping)
{
LinearVelocity.Serialize(bw);
AngularVelocity.Serialize(bw);
}
}
示例14: Serialize
public void Serialize(BitWriter bw)
{
bw.Write((byte)ThingLists.Count);
foreach (var thingList in ThingLists)
{
bw.Write((byte)thingList.Count);
foreach(var thing in thingList)
{
thing.Serialize(bw);
// "i >= 21" logic from Deserialize is handled automatically here. No special serialize logic needed.
}
}
}
示例15: BitWriterEmptyTest
public void BitWriterEmptyTest()
{
using (MemoryStream ms = new MemoryStream()) {
BitWriter bw = new BitWriter()
{
Output = ms,
CodeLength = 4,
};
bw.FlushBits();
bw.FlushBytes();
byte[] bytes = ms.ToArray();
Assert.AreEqual(0, bytes.Length);
}
}