public class FsnBizNet
{
private static int count;
public static int parseInt(IList<string> list)
{
int value = Convert.ToInt32(list[count + 1] + list[count], 2);
count += 2;
return value;
}
public static string parseString(IList<string> list)
{
string value = list[count + 3] + list[count + 2] + list[count + 1] + list[count];
count += 4;
return value;
}
public static List<string> readFileToBit(string filepath)
{
FileStream @in = new FileStream(filepath, FileMode.Open);
List<string> list = new List<string>();
long left = @in.Length;//文件大小
byte[] buffer = new byte[1024];
int start = 0;//读取位置
int length = 0; //实际返回结果长度
while (left > 0)
{
@in.Position = start;
length = 0;
if (left < buffer.Length)
length = @in.Read(buffer, 0, Convert.ToInt32(left));
else
length = @in.Read(buffer, 0, buffer.Length);
if (length == 0)
{
break;
}
start = start + length;
left = left - length;
for (int i = 0; i < length; i++)
{
string s = Convert.ToString(buffer[i] | 256, 2);
s = s.Substring(s.Length - 8);
list.Add(s);
}
}
@in.Close();
return list;
}
public static SnoHead getHead(IList<string> list)
{
count = 0;
FsnBizNet f = new FsnBizNet();
SnoHead sh = new FsnBizNet.SnoHead(f);
int[] headStart = new int[4];
for (int i = 0; i < 4; i++)
{
headStart[i] = parseInt(list);
}
sh.HeadStart = headStart;
int[] headString = new int[6];
for (int i = 0; i < 6; i++)
{
headString[i] = parseInt(list);
}
sh.HeadString = headString;
long counter = parseInt(list) + (parseInt(list) << 8);
sh.Counter = counter;
int[] headEnd = new int[4];
for (int i = 0; i < 4; i++)
{
headEnd[i] = parseInt(list);
}
sh.HeadEnd = headEnd;
return sh;
}
public static IDictionary getSnoExpImg(IList<string> list)
{
count = 0;
IDictionary map = new Hashtable();
// 设置日期时间
int data = parseInt(list);
int time = parseInt(list);
int y = data >> 9;
int m = (data - (y << 9)) >> 5;
int d = data - (y << 9) - (m << 5);
int hh = time >> 11;
int mm = (time - (hh << 11)) >> 5;
int ss = (time - (hh << 11) - (mm << 5)) << 1;
map["DateTime"] = y + 1980 + "-" + m + "-" + d + " " + hh + ":" + mm + ":" + ss;
// 设置货币真、假、残和旧币标志
map["TfFlag"] = parseInt(list);
// 设置货币错误码(3个)
string errorCode = "";
for (int i = 0; i < 3; i++)
{
int code = parseInt(list);
if (code < 13 && code > 0)
{
errorCode += code + ",";
}
}
if ("1".Equals(map["TfFlag"]))
{
errorCode = errorCode.Substring(0, errorCode.LastIndexOf(","));
}
else
{
errorCode = "0";
}
map["ErrorCode"] = errorCode;
// 设置币种标志(4个)
string moneyFlag = "";
for (int i = 0; i < 4; i++)
{
int flag = parseInt(list);
if (flag != 0)
{
moneyFlag += (char)flag;
}
}
map["MoneyFlag"] = moneyFlag;
// 设置年版或版本号标志
int ver = parseInt(list);
if (ver == 0)
{
ver = 1990;
}
if (ver == 1)
{
ver = 1999;
}
if (ver == 2)
{
ver = 2005;
}
if (ver == 9999)
{
ver = 0;
}
map["Ver"] = ver;
// 设置币值
map["Valuta"] = parseInt(list);
// 设置冠字号位数
map["CharNum"] = parseInt(list);
// 设置冠字号(12个)
string no = "";
for (int i = 0; i < 12; i++)
{
int No = parseInt(list);
if (No != 0)
{
no += (char)No;
}
}
map["Sno"] = no;
// 设置机具编号(24个)
string machineSNo = "";
for (int i = 0; i < 24; i++)
{
int Msno = parseInt(list);
if (Msno != 0)
{
machineSNo += (char)Msno;
}
}
map["MachineSno"] = machineSNo;
// 设置冠字号保留字
map["Reserve1"] = parseInt(list);
return map;
}
public static Bitmap getSnoImg(IList<string> list)
{
count = 0;
int num = parseInt(list);
int height = parseInt(list);
int width = parseInt(list);
int Reserve2 = parseInt(list);
// 根据读取的信息创建图像缓冲区
Brush bruch = Brushes.White;
Bitmap image = new Bitmap(width * num, height, PixelFormat.Format32bppRgb);
System.Drawing.Graphics g = Graphics.FromImage(image);
g.FillRectangle(bruch, 0, 0, width * num, height);
g.Dispose();
int i = 0;
while (list.Count - count > 0 && i < width * num)
{
string s = parseString(list);
for (int j = 0; j < height && j < s.Length; j++)
{
if (s[j] == '1')
{
int colorvalue =Convert.ToInt32(0x000000);
image.SetPixel(i, j, Color.FromArgb(colorvalue));
}
}
i++;
}
return image;
}
public static List<IDictionary> readFile(string path)
{
// bit-list
List<string> listBit = readFileToBit(path);
// 头文件
SnoHead sh = getHead(listBit.GetRange(0, 32-0));
// 冠字号信息条数
long counter = sh.Counter;
// 根据冠字号头文件判断是否存在图像,得出一条冠字号信息包含的byte数
int size = sh.HeadString[2] != 0x2D ? 1644 : 100;
if (counter * size + 32 == listBit.Count)
{
//string imagePath = Thread.CurrentThread.ContextClassLoader.getResource("").Path.Substring(1).Replace("%20", " ");
string imagePath = AppDomain.CurrentDomain.BaseDirectory.Substring(0).Replace("%20", " ");
imagePath = Path.Combine(imagePath,"image");
List<IDictionary> list = new List<IDictionary>();
for (int i = 0; i < counter; i++)
{
//listBit.ToArray().
IDictionary map = getSnoExpImg(listBit.GetRange(i * size + 32, i * size + 132 - (i * size + 32)));
if (size != 100)
{
Bitmap imageSno = getSnoImg(listBit.GetRange(i * size + 132, (i + 1) * size - (i * size + 132)));
imageSno.Save(Path.Combine(imagePath,i + ".bmp"), ImageFormat.Bmp);
map["ImageSno"] = "image/" + i + ".bmp";
}
else
{
map["ImageSno"] = null;
}
list.Add(map);
}
return list;
}
return null;
}
public class SnoHead
{
private readonly FsnBizNet outerInstance;
public SnoHead(FsnBizNet outerInstance)
{
this.outerInstance = outerInstance;
}
internal int[] headStart;
internal int[] headString;
internal long counter;
internal int[] HeadEnd_Renamed;
public virtual int[] HeadStart
{
get
{
return headStart;
}
set
{
this.headStart = value;
}
}
public virtual int[] HeadString
{
get
{
return headString;
}
set
{
this.headString = value;
}
}
public virtual long Counter
{
get
{
return counter;
}
set
{
this.counter = value;
}
}
public virtual int[] HeadEnd
{
get
{
return HeadEnd_Renamed;
}
set
{
HeadEnd_Renamed = value;
}
}
}
}
- CocosStudio文件解析工具CsdAnalysis
起因 因为工作需要,所以需要使用CocosStudio来制作界面动画什么的.做完了发现需要找里边对象的时候会有很长一串代码,感觉不是很爽.之前写OC代码的时候可以吧程序中的对象指针跟编辑器中的对象相对 ...
- 通过正则表达式实现简单xml文件解析
这是我通过正则表达式实现的xml文件解析工具,有些XHTML文件中包含特殊符号,暂时还无法正常使用. 设计思路:常见的xml文件都是单根树结构,工具的目的是通过递归的方式将整个文档树装载进一个Node ...
- 八、Android学习第七天——XML文件解析方法(转)
(转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 八.Android学习第七天——XML文件解析方法 XML文件:exten ...
- phpcms V9 首页模板文件解析
在了解了<phpcms V9 URL访问解析>之后,我们已经知道首页最终执行的是content模块下index控制器的init方法. 下面, 我们逐步分析过程如下: 第一.首页默认执行的是 ...
- (转)AVI文件格式解析+AVI文件解析工具
AVI文件解析工具下载地址:http://download.csdn.net/detail/zjq634359531/7556659 AVI(Audio Video Interleaved的缩写)是一 ...
- itextSharp 附pdf文件解析
一.PdfObject: pdf对象 ,有9种,对象是按照对象内涵来分的,如果按照对象的使用规则来说,对象又分为间接对象和直接对象.间接对象是PDF中最常用的对象,如前面对象集合里面的,所有对象都是间 ...
- 《热血传奇2》wix、wil文件解析Java实现
在百度上搜索java+wil只有iteye上一篇有丁点儿内容,不过他说的是错的!或者说是不完整的,我个人认为我对于热血传奇客户端解析还是有一定研究的,请移步: <JMir——Java版热血传奇2 ...
- paper 37 : WINCE的BIB文件解析
WINCE的BIB文件解析 BIB的全称为Binary Image Builder,在Wince编译过程中的最后MakeImage阶段会用到BIB文件,BIB文件的作用是指示构建系统如何构建二进制映像 ...
- 如何让你的Apache支持include文件解析和支持shtml的相关配置
源地址:http://www.itokit.com/2011/0430/65992.html Apache支持include文件解析shtml首先要应该修改Apache配置文件httpd.conf . ...
随机推荐
- HttpContext的dynamic包装器DynamicHttpContext (附原代码)
项目背景:在.net framework下使用asp.net webform,特别是aspx+ajax+ashx中,ashx后台代码获取传入参数的时候,需要很多[“…”],我用dynamic对他进行包 ...
- Parameter index out of range (2 > number of parameters, which is 1)
今天在实现一个功能时遇到一个问题,解决了很久.结果是#{}与${}使用错误的原因.但是具体原因还不是很清楚,写此篇总结,知道的可以交流. 具体描述为:通过教师的头衔(1高级讲师2首席讲师)及名称进行模 ...
- Jquery仿彩票更换数字动画效果
<script type="text/javascript" src="jquery-1.11.3.min.js"></script> ...
- 【Python】实现简单循环
# -*- coding:utf-8 -*- #猜数字游戏 lucky_num = 6 count = 0 while count < 3: input_num = int(raw_input( ...
- 【LeetCode】Sort Colors
Sort Colors Given an array with n objects colored red, white or blue, sort them so that objects of t ...
- Linux内核学习总结
1.<简单C程序生成的汇编代码分析> http://www.cnblogs.com/snowfox2016/p/5225937.html 2.<时间片轮转多道程序代码分析>(未 ...
- iOS 企业包碰到的问题
在这里 就不讲 iOS 企业包 怎么申请了 网上链接很多 也简单 真找不到靠谱的, 就用这个链接 教程 http://www.cnblogs.com/xiaoc1314/p/5595312.html ...
- 函数中的static静态变量
静态变量仅在局部函数域中存在且只被初始化一次,当程序执行离开此作用域时,其值不会消失,会使用上次执行的结果. <?php function testStatic($start,$end){ st ...
- 黑马----JAVA内部类
黑马程序员:Java培训.Android培训.iOS培训..Net培训 黑马程序员--JAVA内部类 一.内部类分为显式内部类和匿名内部类. 二.显式内部类 1.即显式声明的内部类,它有类名. 2.显 ...
- Python 基础之在ubuntu系统下安装双版本python
前言:随着python升级更新,新版本较于老版本功能点也有不同地方,作为一个初学者应该了解旧版本的规则,也要继续学习新版本的知识.为了能更好去学习python,我在ubuntu安装python2和py ...