读取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数据库: ...
随机推荐
- MySQL SQL中的安全问题
一.SQL注入是一个很常见的问题:利用的原理是SQL语句中的 "or"操作符或者"/*"和"#"注释符.前者利用逻辑运算,或者利用MySQL ...
- C#高级编程笔记 Day 8, 2016年9月 28日 (数组)
1.数组的初始化 声明了数组后,就必须为数组分配内存,以保存数组的所有元素.数组是引用类型,所以必须给它分配堆上的内存,为此,应使用 new 运算符,指定数组中元素的类型和数量来初始化数组的变量.若使 ...
- 打造smali代码库辅助分析
打造smali代码库辅助分析 在分析Android应用程序的时候,我们往往会插入代码重打包apk来辅助我们分析的工作 一个比较取巧的方法就是先用java写好代码以及相关的调用之后, 然后直接扣出代码 ...
- 十二. 一步步破解JEB 2.0demo版二
编写脚本批量还愿JEB 加密字符串 解密完后效果如下: 脚本源码: https://github.com/bingghost/JebPlugins 思路: 下面的该封装的基本都封装了,过程如下: 1. ...
- MariaDB 多主一从 搭建测试
背景: 目前MySQL依然只支持一个Slave从一个Master复制数据,虽然也可以做到一主多备(M->S),双主复制(M<->M)等架构,但是局限性依然很大.由于项目的要求,需要各 ...
- 问题:QXcbConnection: Could not connect to display
Wkhtmltopdf 失败 (错误代码: -6). 消息: The switch --header-spacing, is not support using unpatched qt, and w ...
- linux6的yum源
[base]name=CentOS-$releasever-Basebaseurl=http://centos.ustc.edu.cn/centos/6/os/x86_64/gpgcheck=1gpg ...
- Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]
今天遇到了Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]这个错误,一直也没有百度,不料想却弄了一个 ...
- sql 删除表中某字段的重复数据
重复字段:BarCode SELECT * FROM dbo.AssetBarCode WHERE BarCode IN (SELECT BarCode FROM dbo.AssetBarCode G ...
- Android笔记:HTTP相关
发送HTTP请求 HttpURLConnection.HttpClient XML解析 Pull 解析.SAX 解析.DOM 解析 解析JSON 格式数据 官方提供的JSONObject.谷歌的开源库 ...