通过数组初始化位图

📅 2025-09-08 🏷️ 👁️ 4 阅读
using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices; using (var bitmap = new Bitmap(4, 2, PixelFormat.Format8bppIndexed)) { //bitmap.Palette.Entries[0] = Color.Red; //bitmap.Palette.Entries[1] = Color.Black; var data = bitmap.LockBits(new Rectangle(0, 0, 4, 2), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); var bytes = new byte[] { 1, 1, 1, 1, 2, 3, 2, 4 }; // 复制数据到位图 Marshal.Copy(bytes, 0, data.Scan0, bytes.Length); // 解锁位图 bitmap.UnlockBits(data); bitmap.Save("D:/output.bmp", ImageFormat.Bmp); }
← WPF Image 绑定图片速度最快的方式 MVVM通过ItemsSource获取CollectionView 并排序和筛选 →

评论 (0)

评论提交后需要审核通过才会显示

← 返回文章列表