java 图片 转像素,在java中将像素数据转换为图像

本文介绍如何将一个包含0和1的文本文件转换为640x480像素的二值图像。0代表黑色背景,1代表白色像素。首先通过BufferedReader读取文件,然后使用二维布尔数组存储数据。在绘制图像时,用黑色填充背景,再用白色绘制1对应的像素点。
摘要由CSDN通过智能技术生成

Hi

I have data of an image of size 640 * 480 pixels, the data is in the format of 0s and 1s, in a txt file. Therefore there are 640*480=307200 characters (0s and 1s) in a text file. The catch is that 0 means that there was nothing in the original image (say black background) and 1 means there is (say a user is standing and it is pertaining to the user blob) and hence its NOT to be mistaken with RGB or byte data.

I need to read and convert this into an image of size 640*480 pixels in java,where pixels indicated by 0 may be set to one color (say black) and 1 to other (say white).

How do I do it??? thanks for help.

解决方案

First, you need to read it in. If you know it's width, you can do something like this:

BufferedReader in = new BufferedReader(new FileReader("myfile.txt"));

boolean[][] mask = new boolean[640][480];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值