读取bmp图片数据
public void getBMPImage(String source) throws Exception {
clearNData(); //清除数据保存区
FileInputStream fs = null;
try {
fs = new FileInputStream(source);
int bfLen = 14;
byte bf[] = new byte[bfLen];
fs.read(bf, 0, bfLen); // 读取14字节BMP文件头
int biLen = 40;
byte bi[] = new byte[biLen];
fs.read(bi, 0, biLen); // 读取40字节BMP信息头
// 源图宽度
nWidth = (((int) bi[7] & 0xff) << 24)
| (((int) bi[6] & 0xff) << 16)
| (((int) bi[5] & 0xff) << 8) | (int) bi[4] & 0xff;
// 源图高度
nHeight = (((int) bi[11] & 0xff) << 24)
| (((int) bi[10] & 0xff) << 16)
| (((int) bi[9] & 0xff) << 8) | (int) bi[8] & 0xff;
// 位数
nBitCount = (((int) bi[15] & 0xff) << 8) | (int) bi[14] & 0xff;
// 源图大小
int nSizeImage = (((int) bi[23] & 0xff) << 24)
| (((int) bi[22] & 0xff) << 16)
| (((int) bi[21] & 0xff) << 8) | (int) bi[20] & 0xff;
// 对24位BMP进行解析
if (nBitCount == 24){
int nPad = (nSizeImage / nHeight) - nWidth * 3;
nData = new int[nHeight * nWidth];
nB=new int[nHeight * nWidth];
nR=new int[nHeight * nWidth];
nG=new int[nHeight * nWidth];
byte bRGB[] = new byte[(nWidth + nPad) * 3 * nHeight];
fs.read(bRGB, 0, (nWidth + nPad) * 3 * nHeight);
int nIndex = 0;
for (int j = 0; j < nHeight; j++){
for (int i = 0; i < nWidth; i++) {
nData[nWidth * (nHeight - j - 1) + i] = (255 & 0xff) << 24
| (((int) bRGB[nIndex + 2] & 0xff) << 16)
| (((int) bRGB[nIndex + 1] & 0xff) << 8)
| (int) bRGB[nIndex] & 0xff;
nB[nWidth * (nHeight - j - 1) + i]=(int) bRGB[nIndex]& 0xff;
nG[nWidth * (nHeight - j - 1) + i]=(int) bRGB[nIndex+1]& 0xff;
nR[nWidth * (nHeight - j - 1) + i]=(int) bRGB[nIndex+2]& 0xff;
nIndex += 3;
}
nIndex += nPad;
}
// Toolkit kit = Toolkit.getDefaultToolkit();
// image = kit.createImage(new MemoryImageSource(nWidth, nHeight,
// nData, 0, nWidth));
/*
//调试数据的读取
FileWriter fw = new FileWriter("C:\\Documents and Settings\\Administrator\\My Documents\\nDataRaw.txt");//创建新文件
PrintWriter out = new PrintWriter(fw);
for(int j=0;j<nHeight;j++){
for(int i=0;i<nWidth;i++){
out.print((65536*256+nData[nWidth * (nHeight - j - 1) + i])+"_"
+nR[nWidth * (nHeight - j - 1) + i]+"_"
+nG[nWidth * (nHeight - j - 1) + i]+"_"
+nB[nWidth * (nHeight - j - 1) + i]+" ");
}
out.println("");
}
out.close();
*/
}
}
catch (Exception e) {
e.printStackTrace();
throw new Exception(e);
}
finally {
if (fs != null) {
fs.close();
}
}
// return image;
}
读取bmp图片数据的更多相关文章
- bmp图片数据提取
仿照别人的程序写的bmp数据提取C代码,并将提取的数据放到txt文档中 /* date : 2014/06/24 designer :pengxiaoen version : dev4.9.9.0 f ...
- [转]opengl入门例题(读取bmp图片,并显示)
#include<gl/glut.h> #define FileName "bliss.bmp" static GLint imagewidth; static GLi ...
- bmp图片格式及读取
C++读取bmp图片的例子 #include <windows.h> #include <stdio.h> #include <stdlib.h> #include ...
- bmp图片的有关操作
读取bmp图片 并生成新的bmp图片 #include "stdafx.h"#include <windows.h>#include <cmath>#inc ...
- MFC 对话框Picture Control(图片控件)中静态和动态显示Bmp图片
版权声明:本文为博主原创文章,转载请注明CSDN博客源地址! 共同学习,一起进步~ https://blog.csdn.net/Eastmount/article/details/26404733 ...
- OPENGL 显示BMP图片+旋转
VS2010/Windows 7/ 1. 需包含头文件 stdio.h, glaux.h, glut.h.需要对应的lib,并添加包含路径 2. 窗口显示用glut库的函数 3. bmp图片从本地读取 ...
- 利用COM组件IPicture读取jpg、gif、bmp图片文件数据和显示图片
1.读取图片数据 函数原型:bool LoadImage(const char *pName, unsigned char *pBitData); 函数功能,读取pName指向的图片文件的位图数据 b ...
- mp3 音频 音乐 tag ID3 ID3V1 ID3V2 标签 读取信息 获得图片 jpeg bmp 图片转换等
mp3 音频 音乐 tag ID3 ID3V1 ID3V2 标签 读取信息 获得图片 jpeg bmp 图片转换(上) MP3文件格式(二)---ID3v2 图:ID3V1标签结构 图:ID3V2标签 ...
- ios 向sqlite数据库插入和读取图片数据
向sqlite数据库插入和读取图片数据 (for ios) 假定数据库中存在表 test_table(name,image), 下面代码将图片文件test.png的二进制数据写到sqlite数据库: ...
随机推荐
- BZOJ2982——combination
1.题意:求 C(n,m) % 10007 ,10007是质数咯 n和m < 2000000000 2.分析:这个东西太大了,显然不能用n!的阶乘预处理的方式搞出来,也不能用递推公式搞出来 于是 ...
- angular自己最近学的一种筛选方法
投资状态vm.statusList = [ {name:"项目状态",value:-1}, {name:"上线",value:0}, {name:"投 ...
- php之获取程序源码的方法
文件hello.php和index.php在同一目录 hello.php <?php class hello{ public function __construct() { echo 'hel ...
- python Function
Python 2.7.10 (default, Oct 14 2015, 16:09:02) [GCC 5.2.1 20151010] on linux2 Type "copyright&q ...
- 【krpano】krpano xml资源解密(破解)软件说明与下载(v1.2)
欢迎加入qq群551278936讨论krpano技术以及获取最新软件. 该软件已经不再维护,现在已经被KRPano资源分析工具取代,详情参见 http://www.cnblogs.com/reac ...
- session超时时间设置方法
session超时时间设置方法 由于session值之前没有设置,以至于刚登录的网站,不到一分钟就超时了,总结了一下,原来是session过期的原因,以下是设置session时间的3个方法: 1. 在 ...
- sql之left join、right join、inner join的区别
sql之left join.right join.inner join的区别 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括 ...
- PHP 基础(赋值及函数)
开端<?php>结尾</php> 弱类型语言 定义变量的时候 不需要 声明 但是 每一个变量前 都必须 加$ 符号 储存文件按 统一放到 安装文件夹下面的 WA ...
- winfrom获取用户控件里的控件对象
如何获取用户控件里的控件对象呢,其实思路也是很简单的, 比如有一个panel 用户控件 里面有许多的其他控件. 那么要找出一个Label控件怎么找呢,好的.现在我们就开始 首先,一个foreach循环 ...
- ping命令执行过程详解
[TOC] ping命令执行过程详解 机器A ping 机器B 同一网段 ping通知系统建立一个固定格式的ICMP请求数据包 ICMP协议打包这个数据包和机器B的IP地址转交给IP协议层(一组后台运 ...