大学时代的作品《UMU 游戏之争上游》的副产品,mif2bmp 改进版,用 GdiPlus 来产生 png 格式图片。

  mif2png.exe 下载:http://umu.ys168.com/,Tools 目录里。或 http://download.csdn.net/detail/umu/3843545。

  以前有文章分析 mif 格式,不过很早了懒得找,直接开源吧,先发头部结构体:

#pragma pack(1)
struct MifHeader
{
    DWORD version;
    DWORD width;
    DWORD height;
    DWORD type;
    DWORD frame_count;
};
#pragma pack()

以下代码是 C# 写的 Paint.NET 文件类型插件 MifFileType.cs

using System;
using System.Collections.Generic;
using System.Text;
using PaintDotNet;
using PaintDotNet.Data;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;

namespace MifFileType
{
    public class MifFileType : FileType
    {
        public MifFileType()
            : base("MIF Files", FileTypeFlags.SupportsLoading | FileTypeFlags.SupportsLayers, new String[] { ".mif" })
        {
        }

protected override Document OnLoad(Stream input)
        {
            if (input.Length < 20)
            {
                MessageBox.Show("Invalid MIF File", "UMU Corporation - MifFileTypePlugIn", MessageBoxButtons.OK, MessageBoxIcon.Error);

Bitmap b = new Bitmap(800, 600);
                return Document.FromImage(b);
            }

try
            {
                BinaryReader br = new BinaryReader(input);

int MifVersion = br.ReadInt32();
                int FrameWidth = br.ReadInt32();
                int FrameHeight = br.ReadInt32();
                int MifType = br.ReadInt32();
                int FrameCount = br.ReadInt32();

int ImageWidth = FrameWidth;
                int ImageHeight = FrameHeight * FrameCount;

bool Valid = true;
                long Prefix;

if (MifType == 3)
                {
                    Prefix = 20;
                }
                else if (MifType == 7)
                {
                    Prefix = 20 + 4 * FrameCount;
                }
                else
                {
                    MessageBox.Show("Invalid MIF File", "UMU Corporation - MifFileTypePlugIn", MessageBoxButtons.OK, MessageBoxIcon.Error);

Bitmap b = new Bitmap(800, 600);
                    return Document.FromImage(b);
                }

if (MifVersion == 0)
                {
                    if (Prefix + ImageWidth * ImageHeight * 3 != input.Length)
                    {
                        Valid = false;
                    }
                }
                else if (MifVersion == 1)
                {
                    if (Prefix + ImageWidth * ImageHeight * 3 > input.Length)
                    {
                        Valid = false;
                    }
                }

if (!Valid)
                {
                    MessageBox.Show("Invalid MIF File", "UMU Corporation - MifFileTypePlugIn", MessageBoxButtons.OK, MessageBoxIcon.Error);

Bitmap b = new Bitmap(800, 600);
                    return Document.FromImage(b);
                }

Bitmap bmp = new Bitmap(ImageWidth, ImageHeight);

for (int CurrentFrame = 0; CurrentFrame < FrameCount; ++CurrentFrame)
                {
                    if (MifType == 7)
                    {
                        input.Seek(4, SeekOrigin.Current);
                    }

UInt16[] rgb16 = new UInt16[FrameWidth * FrameHeight];

for (int i = 0; i < FrameHeight * FrameWidth; ++i)
                    {
                        rgb16[i] = br.ReadUInt16();
                    }

Byte[] a8 = new Byte[FrameWidth * FrameHeight];

for (int i = 0; i < FrameHeight * FrameWidth; ++i)
                    {
                        a8[i] = br.ReadByte();
                    }

for (int y = 0; y < FrameHeight; ++y)
                    {
                        for (int x = 0; x < FrameWidth; ++x)
                        {
                            int a = a8[x + y * FrameWidth];
                            int r = (rgb16[x + y * FrameWidth] & 0xF800) >> 8;
                            int g = (rgb16[x + y * FrameWidth] & 0x07E0) >> 3;
                            int b = (rgb16[x + y * FrameWidth] & 0x001F) << 3;

if (a == 32)
                            {
                                a = 255;
                            }
                            else if (a > 0)
                            {
                                a <<= 3;
                            }

bmp.SetPixel(x, FrameHeight * CurrentFrame + y, Color.FromArgb(a, r, g, b));
                        }
                    }
                }

br.Close();
                return Document.FromImage(bmp);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "UMU Corporation - MifFileTypePlugIn", MessageBoxButtons.OK, MessageBoxIcon.Warning);

Bitmap bmp = new Bitmap(800, 600);
                //Document doc = Document.FromImage(bmp);
                //doc.Tag = "UMU Corporation - MifFileTypePlugIn";
                //return doc;
                return Document.FromImage(bmp);
            }
        }
    }

public class MifFileTypeFactory : IFileTypeFactory
    {
        public FileType[] GetFileTypeInstances()
        {
            return new FileType[] { new MifFileType() };
        }
    }

mif2png(QQGame 专用 mif 格式转 png 格式)相关推荐

  1. MapInfo格式到ArcInfo格式的转换

    MapInfo中的地图可以有两种格式:Tab格式(表格式).Mif格式(交换格式). ArcInfo中的地图也支持多种格式:Shape格式.Coverage.E00(交换格式).... 由Tab-&g ...

  2. 将腾讯视频Qlv格式转为MP4格式(亲测可用)

    编写不易,如有转载,请声明出处:http://blog.csdn.net/zxc514257857/article/details/70160183   腾讯视频Qlv格式是一种腾讯专用的特殊的加密格 ...

  3. word学习/word如何显示空格/LaTeX格式转为Word格式/ latex中的公式格式如何转换成word中的公式格式/excel复制到word表格过大超出

    以windows的word365为例进行讲解,主要分为显示,公式,表格,图片,审阅以及写作方式(含Latex格式转换). 常用快捷键: f4: cmd + y 查找: cmd + shift + h ...

  4. 基于RDKit的Python脚本:SDF格式转SMILES格式

    RDKit: Open-Source Cheminformatics Software http://www.rdkit.org/ 简化分子线性输入规范(SMILES)是一种用ASCII字符串明确描述 ...

  5. Python使用scipy包将稀疏矩阵保存为Mtx格式和npz格式文件实战

    Python使用scipy包将稀疏矩阵保存为Mtx格式和npz格式文件实战 目录 Python将稀疏矩阵保存为Mtx格式和npz格式文件实战 #导入包和仿真数据

  6. R语言ggplot2可视化:应用pivot_longer函数将数据从宽格式转换为长格式、为dataframe的每一列绘制密度图和直方图(堆叠)

    R语言ggplot2可视化:应用pivot_longer函数将数据从宽格式转换为长格式.为dataframe的每一列绘制密度图和直方图(堆叠) 目录 R语言ggplot2可视化:应用pivot_lon ...

  7. YUV视频格式到RGB32格式转换的速度优化 上篇(转)

    YUV视频格式到RGB32格式转换的速度优化 上篇                     HouSisong@GMail.com    2007.10.30   tag: YUV,YCbCr,YUV ...

  8. Convert PLY to VTK Using PCL 1.6.0 or PCL 1.8.0 使用PCL库将PLY格式转为VTK格式

    PLY格式是比较流行的保存点云Point Cloud的格式,可以用MeshLab等软件打开,而VTK是医学图像处理中比较常用的格式,可以使用VTK库和ITK库进行更加复杂的运算处理.我们可以使用Par ...

  9. Linux下时间戳格式和标准时间格式的转换

    转载地址:http://yinqingsong520.blog.163.com/blog/static/392100201010252595916/  做个备忘! 在LINUX系统中,有许多场合都使用 ...

最新文章

  1. 《2019人工智能发展报告》出炉:清华大学-中国工程院知识智能联合研究中心、中国人工智能学会联名发布!...
  2. golang 判断字符串是不是数字
  3. C++ eof()函数陷阱
  4. SpringBoot使用CommandLineRunner和ApplicationRunner项目初始化事件
  5. 荒岛余生为什么没有打开包裹_您会带到荒岛什么办公桌设置?
  6. 数据仓库介绍与实时数仓案例
  7. vue 将字符串最后一个字符给替换_初尝VUE
  8. python画相关性可视化图_Python可视化matplotlibseborn16-相关性热图
  9. idle显示出错信息 python_Life is short,you need Python——Python入门
  10. 从16位到32位再到64位,为何16年过去,依然没有128位系统出现?
  11. 2021年最新程序员培训机构排名,学习前避坑必看
  12. 协会元宇宙产业园基地孵化器授牌案例:循环经济元宇宙加速基地
  13. 网络重置后,WiFi模块没了,网络适配器感叹号
  14. ubuntu 开机显示recovering journal死机的解决方法
  15. ubuntu20.04安装向日葵
  16. U3d引擎与资源管理
  17. 知道三个金,三个火,三水~~都念什么吗?
  18. 求素数/质数 简单Java算法
  19. 区块链与金融基础设施——兼论Facebook Libra
  20. 火星特约 | Uniswap的UNI对DEX格局的影响

热门文章

  1. 根据hash值找到bt种子的磁力下载链…
  2. ADC 转换:神舟IV实验
  3. 全球主要国家( 61国)名义实际汇率逐月指数(1994-2017)
  4. java版Spring Cloud+Vue 前后端分离+b2b2c多商家入驻电子商务源码
  5. 使用期望等待一次性事件
  6. H3C IRF2典型应用(1)
  7. 软件测试 | 测试开发 | 智能音箱语音交互系统简介与测试初探
  8. 浅谈tcp协议与tcp_tw
  9. Race Conditions/条件竞争
  10. 几种光学毫米波产生方式的优缺点