package test;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.MemoryImageSource;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
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);
ret |= (ret << 8) | ((long) in[offset + 0] & 0xff);
return (ret);
}
// build an double from a byte array - convert little to big endian
public static double constructDouble(byte[] in, int offset) {
long ret = constructLong(in, offset);
return (Double.longBitsToDouble(ret));
}
// build an short from a byte array - convert little to big endian
public static short constructShort(byte[] in, int offset) {
short ret = (short) ((short) in[offset + 1] & 0xff);
ret = (short) ((ret << 8) | (short) ((short) in[offset + 0] & 0xff));
return (ret);
}
// internal class representing a bitmap header structure
// with code to read it from a file
static class BitmapHeader {
public int nsize;
public int nbisize;
public int nwidth;
public int nheight;
public int nplanes;
public int nbitcount;
public int ncompression;
public int nsizeimage;
public int nxpm;
public int nypm;
public int nclrused;
public int nclrimp;
// read in the bitmap header
public void read(ByteArrayInputStream fs) throws IOException
{
final int bflen = 14; // 14 byte BITMAPFILEHEADER
byte bf[] = new byte[bflen];
fs.read(bf, 0, bflen);
final int bilen = 40; // 40-byte BITMAPINFOHEADER
byte bi[] = new byte[bilen];
fs.read(bi, 0, bilen);
// Interperet data.
nsize = constructInt(bf, 2);
// System.out.println("File type is :"+(char)bf[0]+(char)bf[1]);
// System.out.println("Size of file is :"+nsize);
nbisize = constructInt(bi, 2);
// System.out.println("Size of bitmapinfoheader is :"+nbisize);
nwidth = constructInt(bi, 4);
// System.out.println("Width is :"+nwidth);
nheight = constructInt(bi, 8);
// System.out.println("Height is :"+nheight);
nplanes = constructShort(bi, 12); // (((int)bi[13]&0xff)<<8) |
// (int)bi[12]&0xff;
// System.out.println("Planes is :"+nplanes);
nbitcount = constructShort(bi, 14); // (((int)bi[15]&0xff)<<8) |
// (int)bi[14]&0xff;
// System.out.println("BitCount is :"+nbitcount);
// Look for non-zero values to indicate compression
ncompression = constructInt(bi, 16);
// System.out.println("Compression is :"+ncompression);
nsizeimage = constructInt(bi, 20);
// System.out.println("SizeImage is :"+nsizeimage);
nxpm = constructInt(bi, 24);
// System.out.println("X-Pixels per meter is :"+nxpm);
nypm = constructInt(bi, 28);
// System.out.println("Y-Pixels per meter is :"+nypm);
nclrused = constructInt(bi, 32);
// System.out.println("Colors used are :"+nclrused);
nclrimp = constructInt(bi, 36);
// System.out.println("Colors important are :"+nclrimp);
}
}
public static Image read(ByteArrayInputStream fs)
{
try {
BitmapHeader bh = new BitmapHeader();
bh.read(fs);
if (bh.nbitcount == 24)
return (readMap24(fs, bh));
if (bh.nbitcount == 32)
return (readMap32(fs, bh));
if (bh.nbitcount == 8)
return (readMap8(fs, bh));
fs.close();
} catch (IOException e) {
}
return (null);
}
/**
*
* readMap24 internal routine to read the bytes in a 24 bit bitmap
*
*
*
* Arguments:
*
* fs - file stream
*
* bh - header struct
*
* Returns:
*
* Image Object, be sure to check for (Image)null !!!!
*
*
*
*/
protected static Image readMap32(ByteArrayInputStream fs, BitmapHeader bh)
throws IOException
{
Image image;
// No Palatte data for 24-bit format but scan lines are
// padded out to even 4-byte boundaries.
int xwidth = bh.nsizeimage / bh.nheight;
int ndata[] = new int[bh.nheight * bh.nwidth];
byte brgb[] = new byte[bh.nwidth * 4 * bh.nheight];
fs.read(brgb, 0, bh.nwidth * 4 * bh.nheight);
int nindex = 0;
for (int j = 0; j < bh.nheight; j++)
{
for (int i = 0; i < bh.nwidth; i++)
{
ndata[bh.nwidth * (bh.nheight - j - 1) + i] = constructInt3(
brgb, nindex);
nindex += 4;
}
}
image = Toolkit.getDefaultToolkit().createImage
(new MemoryImageSource(bh.nwidth, bh.nheight,
ndata, 0, bh.nwidth));
fs.close();
return (image);
}
/**
*
* readMap24 internal routine to read the bytes in a 24 bit bitmap
*
*
*
* Arguments:
*
* fs - file stream
*
* bh - header struct
*
* Returns:
*
* Image Object, be sure to check for (Image)null !!!!
*
*
*
*/
protected static Image readMap24(ByteArrayInputStream fs, BitmapHeader bh)
throws IOException
{
Image image;
// No Palatte data for 24-bit format but scan lines are
// padded out to even 4-byte boundaries.
int npad = (bh.nsizeimage / bh.nheight) - bh.nwidth * 3;
int ndata[] = new int[bh.nheight * bh.nwidth];
byte brgb[] = new byte[(bh.nwidth + npad) * 3 * bh.nheight];
fs.read(brgb, 0, (bh.nwidth + npad) * 3 * bh.nheight);
int nindex = 0;
for (int j = 0; j < bh.nheight; j++)
{
for (int i = 0; i < bh.nwidth; i++)
{
ndata[bh.nwidth * (bh.nheight - j - 1) + i] = constructInt3(
brgb, nindex);
nindex += 3;
}
nindex += npad;
}
image = Toolkit.getDefaultToolkit().createImage
(new MemoryImageSource(bh.nwidth, bh.nheight,
ndata, 0, bh.nwidth));
fs.close();
return (image);
}
/**
*
* readMap8 internal routine to read the bytes in a 8 bit bitmap
*
*
*
* Arguments:
*
* fs - file stream
*
* bh - header struct
*
* Returns:
*
* Image Object, be sure to check for (Image)null !!!!
*
*
*
*/
protected static Image readMap8(ByteArrayInputStream fs, BitmapHeader bh)
throws IOException
{
Image image;
// Have to determine the number of colors, the clrsused
// parameter is dominant if it is greater than zero. If
// zero, calculate colors based on bitsperpixel.
int nNumColors = 0;
if (bh.nclrused > 0)
{
nNumColors = bh.nclrused;
}
else
{
nNumColors = (1 & 0xff) << bh.nbitcoun
没有合适的资源?快使用搜索试试~ 我知道了~
SWFupload_struts1.rar_java 批量上传_struts1批量下载_swfupload struts1
共38个文件
jar:10个
class:7个
java:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 3 浏览量
2022-09-24
06:15:39
上传
评论
收藏 1.32MB RAR 举报
温馨提示
java控件实现多个文档的批量上传,带时间显示
资源推荐
资源详情
资源评论
收起资源包目录
SWFupload_struts1.rar (38个子文件)
SWFupload_struts1
.settings
org.eclipse.core.resources.prefs 88B
src
test
BmpWrite24.java 5KB
BmpRead24.java 6KB
BMPLoader.java 11KB
com
techmore
struts
form
UploadForm.java 1KB
action
UploadFilesAction.java 4KB
.project 1KB
WebRoot
css
default.css 6KB
images
TestImageNoText_65x29.png 1KB
META-INF
MANIFEST.MF 39B
WEB-INF
web.xml 1KB
.struts-config.mex 636B
classes
test
BmpWrite24.class 3KB
BMPLoader.class 5KB
BmpRead24.class 3KB
BmpRead24$MyPanel.class 1KB
BMPLoader$BitmapHeader.class 1KB
com
techmore
struts
form
UploadForm.class 1KB
action
UploadFilesAction.class 5KB
struts-config.xml 961B
lib
commons-io-1.3.1.jar 82KB
commons-fileupload-1.2.jar 52KB
commons-beanutils.jar 160KB
jakarta-oro.jar 62KB
commons-validator.jar 74KB
commons-fileupload.jar 19KB
commons-logging.jar 33KB
struts.jar 474KB
antlr.jar 344KB
commons-digester.jar 147KB
js
swfupload.js 38KB
swfupload.swf 12KB
handlers.js 6KB
swfupload.queue.js 3KB
fileprogress.js 7KB
index.jsp 3KB
uploadfile
.mymetadata 324B
.classpath 1KB
.myeclipse
共 38 条
- 1
资源评论
周楷雯
- 粉丝: 78
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功