zoukankan      html  css  js  c++  java
  • WPF 创建空白图片

    本文告诉大家如何在 WPF 创建空白图片,可以创建1像素图片

    可以使用 BitmapSource 的 Create 方法创建空白图片

                // 限制不能创建小于2x2的图片
                const int width = 2;
                const int height = width;
                
                BitmapSource.Create(width, height, 96, 96,
                    PixelFormats.Indexed1,
                    new BitmapPalette(new List<Color> { Colors.Transparent }),
                    new byte[width * height], 1);
    

    上面这个方法只有创建 2x2 的图片,而创建1像素图片可以使用下面方法

                const int width = 1;
                const int height = width;
                const double dpi = 96;
                // R G B 三个像素
                const int colorLength = 3;
    
                var image = BitmapSource.Create(width, height, dpi, dpi, PixelFormats.Bgr24, null, new byte[colorLength],
                    colorLength);
    

    空白图片保存到文件,使用png和jpg等几个格式里面,文件的大小如下

    .png byte count = 119
    .jpg byte count = 631
    .bmp byte count = 58
    .gif byte count = 41
    

    也就是说存放为 gif 对于这张图片最省文件体积

    以下是 bmp 文件的二进制

    0x42,0x4D,0x3A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC4,0x0E,0x00,0x00,0xC4,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    

    本文代码放在 github 欢迎小伙伴访问

  • 相关阅读:
    LaTeX技巧如何拆分源文件并且分别编译
    latex 批量注释
    解决 winedit 打开tex文件 reading error
    Latex beamer
    myeclipse项目上出现红色叹号
    个人简介
    Ubnt EdgeRouter ER-4 路由器的交换功能
    限制黑产尝试登陆WordPress后台
    查找汉字笔顺笔画
    WordPress主题:高级资源类博客主题RiPro主题V6.5
  • 原文地址:https://www.cnblogs.com/lindexi/p/13656976.html
Copyright © 2011-2022 走看看