当前位置: 首页>>代码示例>>C#>>正文


C# Binary.WriteInt16方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:kghost,项目名称:th123_toolset,代码行数:85,代码来源:Program.cs


注:本文中的Binary.WriteInt16方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。