`
wangshu3000
  • 浏览: 131773 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

关于BMP图片格式(部分垃圾代码)

阅读更多
java 代码
  1. 做了个刷投票的程序 识别随即码图片的地方用到了BMP图片识别 需要识别出BMP图片里的数字   
  2. 网站的BMP图片格式比较规则  20 * 45 的大小 每个数字大小是 10 * 8  左侧空 5 像素 右侧 5 像素   
  3. 研究BMP图片格式发现 BMP主要包括 3 部分 头 颜色表 图像数据区    
  4. 图像结构如下 类似C++里的结构体   
  5. public   class  BMPHeader {   
  6. public   byte [] bm =  new   byte [ 2 ]; // 2位 BM   
  7.   
  8. public   byte [] size =  new   byte [ 4 ]; // 4位 2038 (f6 07)   
  9.   
  10. public   byte [] save =  new   byte [ 4 ]; // 4位 00   
  11.   
  12. public   byte [] dataPos =  new   byte [ 4 ]; // 4位 图像数据区位置   
  13.   
  14. // (3604)文件头信息块大小,图像描述信息块的大小,图像颜色表的大小,保留(为01)   
  15.   
  16. public   byte [] desSize =  new   byte [ 4 ]; // 4位图像描述信息块大小28h   
  17.   
  18. public   byte [] width =  new   byte [ 4 ]; // 4位 宽度   
  19.   
  20. public   byte [] hight =  new   byte [ 4 ]; // 4位 高度   
  21.   
  22. public   byte [] plane =  new   byte [ 2 ]; // 2位 plane为0100   
  23.   
  24. public   byte [] bytes =  new   byte [ 2 ]; // 2位 图像的位数 0800   
  25.   
  26. public   byte [] zip =  new   byte [ 4 ]; // 4位 压缩方式00不压缩   
  27.   
  28. public   byte [] picSize =  new   byte [ 4 ]; // 4位 c0 03 = 960 图像区数据的大小   
  29.   
  30. public   byte [] shuiPing =  new   byte [ 4 ]; // 4位 水平每米有多少像素   
  31.   
  32. public   byte [] cuiZhi =  new   byte [ 4 ]; // 4位 垂直每米有多少像素   
  33.   
  34. public   byte [] colorNum =  new   byte [ 4 ]; // 4位 此图像所用的颜色数   
  35.   
  36. // 图像数据从436-7f5   
  37. public   byte [] colorTab =  new   byte [ 1028 ];   
  38.   
  39. public   byte [] bmpData =  new   byte [ 960 ];   
  40. }   
  41. 颜色表ColorTab应该为 1024 长 不知道为什么会是 1028  没算明白这里   
  42. 图像数据区是 960 位 每一位都是一个颜色点 保存颜色表中的索引数据  16 进制  3 行表示图像中的一行   
  43. 从下往上排列  45 = 16 * 3 - 3  有 3 位补零 因为bmp要保证每行数据点要为 4 的整数倍   
  44. 得到数据内容就可以根据行列坐标定位每一点的颜色 从而判断出图像中的数字   
  45. import  java.io.File;   
  46. import  java.io.FileInputStream;   
  47. import  java.io.FileNotFoundException;   
  48. import  java.io.IOException;   
  49.   
  50. public   class  BMPTest {   
  51. private   byte [][] parse960ToLine( byte [] bmpData) {   
  52.     int  lineSize =  48 ;   
  53.     int  columnIndex =  0 ;   
  54.     int  rowIndex =  0 ;   
  55.     byte [][] bmp =  new   byte [ 20 ][ 48 ];   
  56.     for  ( int  i =  0 ; i < bmpData.length; i++) {   
  57.     bmp[rowIndex][columnIndex] = bmpData[i];   
  58.     columnIndex++;   
  59.      if  (columnIndex ==  48 ) {   
  60.      rowIndex++;   
  61.      columnIndex =  0 ;   
  62.     }   
  63.    }   
  64.     return  bmp;   
  65. }   
  66.   
  67. private   short  parse1Num( byte [][] theByte) {   
  68.     if  (theByte[ 0 ][ 0 ] ==  0  && theByte[ 0 ][ 1 ] ==  0  && theByte[ 0 ][ 2 ] ==  0   
  69.      && theByte[ 0 ][ 3 ] ==  0  && theByte[ 0 ][ 4 ] ==  0   
  70.      && theByte[ 0 ][ 5 ] ==  0  && theByte[ 0 ][ 6 ] ==  0   
  71.      && theByte[ 0 ][ 7 ] ==  0  && theByte[ 7 ][ 0 ] ==  0   
  72.      && theByte[ 7 ][ 1 ] ==  0  && theByte[ 1 ][ 1 ] ==  0   
  73.      && theByte[ 1 ][ 2 ] ==  0  && theByte[ 2 ][ 2 ] ==  0   
  74.      && theByte[ 2 ][ 3 ] ==  0  && theByte[ 3 ][ 3 ] ==  0   
  75.      && theByte[ 3 ][ 4 ] ==  0  && theByte[ 4 ][ 4 ] ==  0 ) {   
  76.      return   2 ;   
  77.    }  else   if  (theByte[ 0 ][ 0 ] ==  3  && theByte[ 0 ][ 1 ] ==  0   
  78.      && theByte[ 0 ][ 2 ] ==  0  && theByte[ 0 ][ 3 ] ==  0   
  79.      && theByte[ 0 ][ 4 ] ==  0  && theByte[ 1 ][ 0 ] ==  0   
  80.      && theByte[ 1 ][ 1 ] ==  0  && theByte[ 1 ][ 2 ] ==  3   
  81.      && theByte[ 9 ][ 1 ] ==  0  && theByte[ 9 ][ 2 ] ==  0   
  82.      && theByte[ 9 ][ 3 ] ==  0  && theByte[ 9 ][ 4 ] ==  0   
  83.      && theByte[ 9 ][ 5 ] ==  0  && theByte[ 8 ][ 0 ] ==  0   
  84.      && theByte[ 8 ][ 1 ] ==  0  && theByte[ 8 ][ 5 ] ==  0   
  85.      && theByte[ 8 ][ 6 ] ==  0 ) {   
  86.      return   3 ;   
  87.    }  else   if  (theByte[ 0 ][ 1 ] ==  0  && theByte[ 0 ][ 2 ] ==  0   
  88.      && theByte[ 0 ][ 3 ] ==  0  && theByte[ 0 ][ 4 ] ==  0   
  89.      && theByte[ 0 ][ 5 ] ==  0  && theByte[ 0 ][ 6 ] ==  0   
  90.      && theByte[ 0 ][ 3 ] ==  0  && theByte[ 1 ][ 3 ] ==  0   
  91.      && theByte[ 2 ][ 3 ] ==  0  && theByte[ 3 ][ 3 ] ==  0   
  92.      && theByte[ 4 ][ 3 ] ==  0  && theByte[ 5 ][ 3 ] ==  0   
  93.      && theByte[ 6 ][ 3 ] ==  0  && theByte[ 7 ][ 3 ] ==  0   
  94.      && theByte[ 8 ][ 3 ] ==  0  && theByte[ 9 ][ 3 ] ==  0   
  95.      && theByte[ 0 ][ 4 ] ==  0  && theByte[ 1 ][ 4 ] ==  0   
  96.      && theByte[ 2 ][ 4 ] ==  0  && theByte[ 3 ][ 4 ] ==  0   
  97.      && theByte[ 4 ][ 4 ] ==  0  && theByte[ 5 ][ 4 ] ==  0   
  98.      && theByte[ 6 ][ 4 ] ==  0  && theByte[ 7 ][ 4 ] ==  0   
  99.      && theByte[ 8 ][ 4 ] ==  0  && theByte[ 9 ][ 4 ] ==  0 ) {   
  100.      return   1 ;   
  101.    }  else   if  (theByte[ 0 ][ 5 ] ==  0  && theByte[ 1 ][ 5 ] ==  0   
  102.      && theByte[ 2 ][ 5 ] ==  0  && theByte[ 3 ][ 5 ] ==  0   
  103.      && theByte[ 4 ][ 5 ] ==  0  && theByte[ 5 ][ 5 ] ==  0   
  104.      && theByte[ 6 ][ 5 ] ==  0  && theByte[ 7 ][ 5 ] ==  0   
  105.      && theByte[ 8 ][ 5 ] ==  0  && theByte[ 9 ][ 5 ] ==  0   
  106.      && theByte[ 0 ][ 6 ] ==  0  && theByte[ 1 ][ 6 ] ==  0   
  107.      && theByte[ 2 ][ 6 ] ==  0  && theByte[ 3 ][ 6 ] ==  0   
  108.      && theByte[ 4 ][ 6 ] ==  0  && theByte[ 5 ][ 6 ] ==  0   
  109.      && theByte[ 6 ][ 6 ] ==  0  && theByte[ 7 ][ 6 ] ==  0   
  110.      && theByte[ 8 ][ 6 ] ==  0  && theByte[ 9 ][ 6 ] ==  0 ) {   
  111.      return   4 ;   
  112.    }  else   if  (theByte[ 5 ][ 0 ] ==  0  && theByte[ 6 ][ 0 ] ==  0   
  113.      && theByte[ 7 ][ 0 ] ==  0  && theByte[ 8 ][ 0 ] ==  0   
  114.      && theByte[ 9 ][ 0 ] ==  0  && theByte[ 5 ][ 1 ] ==  0   
  115.      && theByte[ 6 ][ 1 ] ==  0  && theByte[ 7 ][ 1 ] ==  0   
  116.      && theByte[ 8 ][ 1 ] ==  0  && theByte[ 9 ][ 1 ] ==  0   
  117.      && theByte[ 9 ][ 2 ] ==  0  && theByte[ 9 ][ 3 ] ==  0   
  118.      && theByte[ 9 ][ 4 ] ==  0  && theByte[ 9 ][ 5 ] ==  0   
  119.      && theByte[ 9 ][ 6 ] ==  0  && theByte[ 2 ][ 6 ] ==  0   
  120.      && theByte[ 3 ][ 6 ] ==  0  && theByte[ 4 ][ 6 ] ==  0   
  121.      && theByte[ 5 ][ 6 ] ==  0  && theByte[ 2 ][ 7 ] ==  0 ) {   
  122.      return   5 ;   
  123.    }  else   if  (theByte[ 2 ][ 0 ] ==  0  && theByte[ 3 ][ 0 ] ==  0   
  124.      && theByte[ 4 ][ 0 ] ==  0  && theByte[ 5 ][ 0 ] ==  0   
  125.      && theByte[ 6 ][ 0 ] ==  0  && theByte[ 7 ][ 0 ] ==  0   
  126.      && theByte[ 1 ][ 1 ] ==  0  && theByte[ 2 ][ 1 ] ==  0   
  127.      && theByte[ 3 ][ 1 ] ==  0  && theByte[ 4 ][ 1 ] ==  0   
  128.      && theByte[ 5 ][ 1 ] ==  0  && theByte[ 6 ][ 1 ] ==  0   
  129.      && theByte[ 7 ][ 1 ] ==  0  && theByte[ 8 ][ 1 ] ==  0 ) {   
  130.      return   6 ;   
  131.    }  else   if  (theByte[ 9 ][ 0 ] ==  0  && theByte[ 9 ][ 1 ] ==  0   
  132.      && theByte[ 9 ][ 2 ] ==  0  && theByte[ 9 ][ 3 ] ==  00   
  133.      && theByte[ 9 ][ 4 ] ==  0  && theByte[ 9 ][ 5 ] ==  0   
  134.      && theByte[ 9 ][ 6 ] ==  0  && theByte[ 9 ][ 7 ] ==  0   
  135.      && theByte[ 8 ][ 7 ] ==  0  && theByte[ 8 ][ 6 ] ==  0   
  136.      && theByte[ 7 ][ 6 ] ==  0  && theByte[ 7 ][ 7 ] ==  0   
  137.      && theByte[ 6 ][ 6 ] ==  0  && theByte[ 6 ][ 5 ] ==  0   
  138.      && theByte[ 5 ][ 5 ] ==  0  && theByte[ 5 ][ 4 ] ==  0   
  139.      && theByte[ 4 ][ 4 ] ==  0 ) {   
  140.      return   7 ;   
  141.    }  else   if  (theByte[ 2 ][ 0 ] ==  0  && theByte[ 3 ][ 0 ] ==  0   
  142.      && theByte[ 7 ][ 0 ] ==  0  && theByte[ 1 ][ 1 ] ==  0   
  143.      && theByte[ 2 ][ 1 ] ==  0  && theByte[ 3 ][ 1 ] ==  0   
  144.      && theByte[ 4 ][ 1 ] ==  0  && theByte[ 0 ][ 2 ] ==  0   
  145.      && theByte[ 0 ][ 3 ] ==  0  && theByte[ 0 ][ 4 ] ==  0   
  146.      && theByte[ 1 ][ 5 ] ==  0  && theByte[ 1 ][ 6 ] ==  0   
  147.      && theByte[ 1 ][ 6 ] ==  0  && theByte[ 4 ][ 2 ] ==  0   
  148.      && theByte[ 5 ][ 2 ] ==  0  && theByte[ 6 ][ 2 ] ==  0 ) {   
  149.      return   8 ;   
  150.    }  else   if  (theByte[ 1 ][ 6 ] ==  0  && theByte[ 2 ][ 6 ] ==  0   
  151.      && theByte[ 3 ][ 6 ] ==  0  && theByte[ 4 ][ 6 ] ==  0   
  152.      && theByte[ 5 ][ 6 ] ==  0  && theByte[ 6 ][ 6 ] ==  0   
  153.      && theByte[ 2 ][ 7 ] ==  0  && theByte[ 3 ][ 7 ] ==  0   
  154.      && theByte[ 4 ][ 7 ] ==  0  && theByte[ 5 ][ 7 ] ==  0   
  155.      && theByte[ 6 ][ 7 ] ==  0  && theByte[ 7 ][ 7 ] ==  0   
  156.      && theByte[ 5 ][ 5 ] ==  0  && theByte[ 4 ][ 2 ] ==  0   
  157.      && theByte[ 4 ][ 3 ] ==  0  && theByte[ 4 ][ 4 ] ==  0   
  158.      && theByte[ 2 ][ 1 ] ==  0 ) {   
  159.      return   9 ;   
  160.    }  else  {   
  161.      return   0 ;   
  162.    }   
  163. }   
  164.   
  165. private  String parse4Num( byte [][] theByte) {   
  166.     int  x =  0 ;   
  167.     int  y =  0 ;   
  168.    String num;   
  169.     byte [][] numByte =  new   byte [ 10 ][ 8 ];   
  170.     for  ( int  i =  5 ; i <  15 ; i++) {   
  171.      for  ( int  j =  5 ; j <  13 ; j++) {   
  172.      numByte[x][y] = theByte[i][j];   
  173.      y++;   
  174.     }   
  175.     x++;   
  176.     y =  0 ;   
  177.    }   
  178.    num =  ""  + parse1Num(numByte);   
  179.    x =  0 ;   
  180.    y =  0 ;   
  181.    numByte =  new   byte [ 10 ][ 8 ];   
  182.     for  ( int  i =  5 ; i <  15 ; i++) {   
  183.      for  ( int  j =  14 ; j <  22 ; j++) {   
  184.      numByte[x][y] = theByte[i][j];   
  185.      y++;   
  186.     }   
  187.     x++;   
  188.     y =  0 ;   
  189.    }   
  190.    num += parse1Num(numByte);   
  191.    x =  0 ;   
  192.    y =  0 ;   
  193.    numByte =  new   byte [ 10 ][ 8 ];   
  194.     for  ( int  i =  5 ; i <  15 ; i++) {   
  195.      for  ( int  j =  23 ; j <  31 ; j++) {   
  196.      numByte[x][y] = theByte[i][j];   
  197.      y++;   
  198.     }   
  199.     x++;   
  200.     y =  0 ;   
  201.    }   
  202.    num += parse1Num(numByte);   
  203.    x =  0 ;   
  204.    y =  0 ;   
  205.    numByte =  new   byte [ 10 ][ 8 ];   
  206.     for  ( int  i =  5 ; i <  15 ; i++) {   
  207.      for  ( int  j =  32 ; j <  40 ; j++) {   
  208.      numByte[x][y] = theByte[i][j];   
  209.      y++;   
  210.     }   
  211.     x++;   
  212.     y =  0 ;   
  213.    }   
  214.    num += parse1Num(numByte);   
  215.     return  num;   
  216. }   
  217.   
  218. /**  
  219. * @param args  
  220. * @throws IOException  
  221. */   
  222. public   static   void  main(String[] args) {   
  223.    BMPTest t =  new  BMPTest();   
  224.    t.handler( "D:\\eclipse2\\workspace\\BMPTest\\classes\\9834.bmp" );   
  225. }   
  226.   
  227. public   void  handler(String fileName) {   
  228.    File bmpFile =  new  File(fileName);   
  229.    FileInputStream fis;   
  230.    BMPHeader header =  new  BMPHeader();   
  231.    BMPTest bt =  new  BMPTest();   
  232.     try  {   
  233.     fis =  new  FileInputStream(bmpFile);   
  234.     fis.read(header.bm);   
  235.     fis.read(header.size);   
  236.     fis.read(header.save);   
  237.     fis.read(header.dataPos);   
  238.     fis.read(header.desSize);   
  239.     fis.read(header.width);   
  240.     fis.read(header.hight);   
  241.     fis.read(header.plane);   
  242.     fis.read(header.bytes);   
  243.     fis.read(header.zip);   
  244.     fis.read(header.picSize);   
  245.     fis.read(header.shuiPing);   
  246.     fis.read(header.cuiZhi);   
  247.     fis.read(header.colorNum);   
  248.     fis.read(header.colorTab);   
  249.     fis.read(header.bmpData);   
  250.    }  catch  (FileNotFoundException e) {   
  251.     e.printStackTrace();   
  252.    }  catch  (IOException e) {   
  253.     e.printStackTrace();   
  254.    }   
  255.    System.out.println( "The Picture is:"   
  256.      + bt.parse4Num(bt.parse960ToLine(header.bmpData)));   
  257. }   
  258. }   

随机码图片格式确定 每位数字的位置都是确定的。。 现在网站上的随机码换成彩色的了

分享到:
评论

相关推荐

    壁纸更换器源代码vb

    可支持多种图片格式 (GIF/JPG/BMP/TIFF) ' 3。远程配置文件、图片远程路径 可支持多种读取方法或协议 (HTTP/FTP/共享路径/本地路径) ' 4。后台运行,占用系统资源小。(物理内存约 600KB,虚拟内存约 1400KB) '...

    自编桌面壁纸自动换~比微软的好!!自编VB更改系统墙纸!附带源码!

    可支持多种图片格式 (GIF/JPG/BMP/TIFF) ' 3。远程配置文件、图片远程路径 可支持多种读取方法或协议 (HTTP/FTP/共享路径/本地路径) ' 4。后台运行,占用系统资源小。(物理内存约 600KB,虚拟内存约 1400KB) '...

    EXCEL集成工具箱V8.0完整增强版(精简)

    允许一次性多图片格式(*.JPG/*.GIF/*.BMP/*.PNG),且支持模糊与非模糊方式导入图片,还可以在导入的图片上显示其文件名称以易于管理。 【批量导出图片】 将EXCEL中指定某列中的图片按显示图片大小导出到指定的...

    EXCEL集成工具箱V6.0

    允许一次性多图片格式(*.JPG/*.GIF/*.BMP/*.PNG),且支持模糊与非模糊方式导入图片,还可以在导入的图片上显示其文件名称以易于管理。 【批量导出图片】 将EXCEL中指定某列中的图片按显示图片大小导出到指定的...

    DotWe论坛程序AspxBBS4

    5.水印,上传图时可以加水印,后台可以设置选择文字水印或图片水印,上传bmp图片时系统会自动压缩成jpg格式。6.管理员权限可以自由定义,自由定义管理员名称和职位7.回贴时可以加入投票、评论、活动等功,阅读权限,...

    DotWe论坛(原AspxBBS) v5.1 万能虚拟形象系统

    水印,上传图时可以加水印,后台可以设置选择文字水印或图片水印,上传bmp图片时系统会自动压缩成jpg格式。  6.管理员权限可以自由定义,自由定义管理员名称和职位  7.回贴时可以加入投票、评论、活动等功,阅读...

    JAVA面试题最全集

    如何格式化日期 5.数组和集合 6.文件和目录(I/O)操作 如何列出某个目录下的所有文件 如何列出某个目录下的所有子目录 判断一个文件或目录是否存在 如何读写文件 7.Java多态的实现(继承、重载、覆盖) 8....

    计算机应用技术(实用手册)

    在用光盘安装系统时就需要对此部分进设置,第一驱动改为光驱引导(First Boot Device),否则光驱不会引导装系统。 Quick Power On Self Test(快速启动选择): 当设定为[Enabled](启动)时,这个项目在系统...

    Excel新增工具集

    6、群发同附件邮件:将同标题、同内容、同附件的共性邮件群发到多个邮箱与手机,与邮箱群发不同的是能“逐个群发”,不受群发数量限制,不会被对方看到多个地址,不会被过滤成垃圾邮件。 7、自动进入网易邮箱:凡是...

    青创分类信息发布系统程序 v4.0

    9、修复了图片上传功能,支持上传的文件格式有:图片文件(*.gif、*.jpg、*.png、*.bmp),动画FLASH文件(*.swf) ----------------------------------------------- 功能介绍: 1、系统基本设置管理 网站名称/标题...

Global site tag (gtag.js) - Google Analytics