`

用java对图片进行绘画

阅读更多
package com.java.test_IO;

import java.io.RandomAccessFile;
/**
 * 表示一个已经存在的Bmp图片,
 * 并提供一些对该图片绘画的功能
 * @author teacher
 */
public class getClourlong {

	static int width;
	static int height;
	static RandomAccessFile ran;
	public getClourlong(String fl) throws Exception{
		ran = new RandomAccessFile(fl,"rw");
		ran.seek(18);
		width = width | ran.read();
		width = width | ran.read() << 8;
		width = width | ran.read() <<16;
		width = width | ran.read() <<24;
		
		height = height | ran.read();
		height = height | ran.read()<<8;
		height = height | ran.read()<<16;
		height = height | ran.read()<<24;
		
	}
	public static void reverse() throws Exception {
		int line = width*3 + (4 - (width*3%4));
		ran.seek(54);
		for (int i = 54; i < ran.length(); i++) {
			if((i+line)%line<=line){
				int m = ~(ran.read());//取反
				ran.seek(ran.getFilePointer()-1);//回到当前指针;
				ran.write(m);
			}
		}
		System.out.println("转换完毕!!");
	}	
	public static void main(String[] args) throws Exception{
		String str="/home/soft22/Desktop/ff.bmp";//图片地址
		getClourlong bp = new getClourlong(str);
		System.out.println(bp.width+","+bp.height);
		reverse();
	}

}

引用


转换后(左),原图(右)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics