读取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数据库: ...
随机推荐
- PHP通用的XSS攻击过滤函数,Discuz系统中 防止XSS漏洞攻击,过滤HTML危险标签属性的PHP函数
XSS攻击在最近很是流行,往往在某段代码里一不小心就会被人放上XSS攻击的代码,看到国外有人写上了函数,咱也偷偷懒,悄悄的贴上来... 原文如下: The goal of this function ...
- javascript数据结构-介绍
github博客地址 名词解释 数据结构是计算机存储.组织数据的方式.数据结构是指相互之间存在一种或多种特定关系的数据元素的集合.通常情况下,精心选择的数据结构可以带来更高的运行或者存储效率.数据结构 ...
- 倾力总结40条常见的移动端Web页面问题解决方案
1.安卓浏览器看背景图片,有些设备会模糊. 用同等比例的图片在PC机上很清楚,但是手机上很模糊,原因是什么呢? 经过研究,是devicePixelRatio作怪,因为手机分辨率太小,如果按照分辨率 ...
- TCP/IP四层模型
转自:http://www.cnblogs.com/BlueTzar/articles/811160.html ISO制定的OSI参考模型的过于庞大.复杂招致了许多批评.与此对照,由技术人员自己开发的 ...
- 自定义el函数
1.1.1 自定义EL函数(EL调用Java的函数) 第一步:创建一个Java类.方法必须是静态方法. public static String sayHello(String name){ retu ...
- 【转】AWK 简明教程
本文转自:http://coolshell.cn/articles/9070.html 有一些网友看了前两天的<Linux下应该知道的技巧>希望我能教教他们用awk和sed,所以,出现了这 ...
- 【python】isinstance可以接收多个类型,hasattr,getattr,setattr
来源:廖雪峰 可以判断一个变量是否是某些类型中的一种,比如下面的代码就可以判断是否是str或者unicode: >>> isinstance('a', (str, unicode)) ...
- springMVC 学习(一)
本文主要介绍springmvc的框架原理,并通过一个入门程序展示环境搭建,配置以及部署调试. springmvc是spring框架的一个模块,springmvc和spring无需通过中间整合层进行整合 ...
- Oracle行转列、列转行的Sql语句总结(转)
多行转字符串 这个比较简单,用||或concat函数可以实现 select concat(id,username) str from app_userselect id||username str f ...
- Google赛马问题
http://coolshell.cn/articles/1202.html 据说,这是Google的面试题.面试题目如下: 一共有25匹马,有一个赛场,赛场有5个赛道,就是说最多同时可以有5匹马一起 ...