Basic Objective
A windows BMP file is a common image format that Java does not handle. While BMP images are used only on windows machines, they are reasonably common. Reading these shows how to read complex structures in Java and
how to alter they byte order from the big endian order used by Java to the little endian order used by the windows and the intel processor.
--------------------------------------------------------
//
//This code was taken and cleaned up from a
//Javaworld tips and tricks column
//
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.MemoryImageSource;
import java.io.FileInputStream;
import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
//
//really just a collection of methods to read a BMP file
//
public class BMPLoader
{
// build an int from a byte array - convert little to big endian
public static int constructInt(byte[] in, int offset) {
int ret = ((int) in[offset + 3] & 0xff);
ret = (ret << 8) | ((int) in[offset + 2] & 0xff);
ret = (ret << 8) | ((int) in[offset + 1] & 0xff);
ret = (ret << 8) | ((int) in[offset + 0] & 0xff);
return (ret);
}
// build an int from a byte array - convert little to big endian
// set high order bytes to 0xfff
public static int constructInt3(byte[] in, int offset) {
int ret = 0xff;
ret = (ret << 8) | ((int) in[offset + 2] & 0xff);
ret = (ret << 8) | ((int) in[offset + 1] & 0xff);
ret = (ret << 8) | ((int) in[offset + 0] & 0xff);
return (ret);
}
// build an int from a byte array - convert little to big endian
public static long constructLong(byte[] in, int offset) {
long ret = ((long) in[offset + 7] & 0xff);
ret |= (ret << 8) | ((long) in[offset + 6] & 0xff);
ret |= (ret << 8) | ((long) in[offset + 5] & 0xff);
ret |= (ret << 8) | ((long) in[offset + 4] & 0xff);
ret |= (ret << 8) | ((long) in[offset + 3] & 0xff);
ret |= (ret << 8) | ((long) in[offset + 2] & 0xff);
ret |= (ret << 8) | ((long) in[offset + 1] & 0xff
- 2001-10-04在VC中自建操作BMP位图文件的类
- 2000-08-18asp动态生成wbmp图片的程序
- 2002-09-22VC小技巧,窗体中显示bmp图象
- 2006-05-01[GD]生成bmp格式的图片(imagebmp)
- 2001-10-04在VC中自建操作BMP位图文件的类
- 2001-10-16转换一批.bmp 文件为 .jpg
- 2004-02-14在BMP文件中隐藏信息
- 2005-07-27BMP位图操作(象素操作)
- 2001-10-04BMP位图文件结构及VC操作
- 2005-08-07VC怎样把一副自己画的图存成BMP格式
热点搜索
热点文章






