本文整理匯總了C#中Binary.WriteInt16方法的典型用法代碼示例。如果您正苦於以下問題:C# Binary.WriteInt16方法的具體用法?C# Binary.WriteInt16怎麽用?C# Binary.WriteInt16使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Binary
的用法示例。
在下文中一共展示了Binary.WriteInt16方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ProcessCV2
static void ProcessCV2(string inputName)
{
string outputName = Path.ChangeExtension(inputName, "cv2");
try
{
CV2Reader cv2;
using (FileStream ofs = new FileStream(outputName, FileMode.Open, FileAccess.Read))
{
cv2 = new CV2Reader(ofs);
if (cv2.Header.bpp == 8)
{
throw new Exception(inputName + " : do NOT support Palette !!");
}
}
using (FileStream ifs = new FileStream(inputName, FileMode.Open, FileAccess.Read))
{
Bitmap image = cv2.Image;
Bitmap inputImage = (Bitmap)Image.FromStream(ifs);
using (FileStream ofs = new FileStream(outputName, FileMode.Create, FileAccess.Write))
{
Binary ob = new Binary(ofs);
cv2.Header.Serialize(ob);
System.Console.WriteLine(inputName + " --> " + outputName);
for (int x = 0; x < cv2.Header.Height; x++)
for (int y = 0; y < cv2.Header.PaddedWidth; y++)
{
if (y < cv2.Header.Width)
{
Color c = inputImage.GetPixel(y, x);
switch (cv2.Header.bpp)
{
case 8:
throw new Exception(inputName + " : do NOT support Palette !!");
case 16:
{
short b = (short)((c.R>>3) << 11 | (c.G>>2) << 5 | (c.B>>3));
ob.WriteInt16(b);
break;
}
case 24:
{
int b = 255<<24 | c.R << 16 | c.G << 8 | c.B;
ob.WriteInt32(b);
break;
}
case 32:
{
int b = c.A << 24 | c.R << 16 | c.G << 8 | c.B;
ob.WriteInt32(b);
break;
}
default:
throw new Exception(inputName + " : unknown bpp !!");
}
}
else
{
switch (cv2.Header.bpp)
{
case 8:
throw new Exception(inputName + " : do NOT support Palette !!");
case 16:
ob.WriteInt16(0);
break;
case 24:
ob.WriteInt32(0);
break;
case 32:
ob.WriteInt32(0);
break;
default:
throw new Exception(inputName + " : unknown bpp !!");
}
}
}
}
}
File.Delete(inputName);
}
catch (Exception e)
{
System.Console.Error.Write(e.Message);
}
}