用aardio解析wbmp格式的图片,然后用gidp显示出来。
问题:gdip画出来的一个点大概占9个像素,用的
var pen_white = gdip.pen(0x00000000,1);
graphics.drawRectangle( pen_black, 1, 1, 1, 1);
import win.ui;
/*DSG{{*/
mainForm = win.form(text="wbmp";right=757;bottom=467)
mainForm.add(
btnGraphics={cls="button";text="GDI+";left=47;top=344;right=195;bottom=377;db=1;dr=1;z=1}
)
/*}}*/
function parseWbmpHex(data){
// 解析宽度
var width = 0;
var index = 5;
while (true) {
var byte = tonumber(string.slice(data,index,index+1), 16);
index += 2;
width = (width << 7) | (byte & 0x7F);
if (byte & 0x80 == 0) {
break;
}
}
// 解析高度
var height = 0;
while (true) {
var byte = tonumber(string.slice(data,index,index+1), 16);
index += 2;
height = (height << 7) | (byte & 0x7F);
if (byte & 0x80 == 0) {
break;
}
}
// 初始化图像数组
var imageArray = table.array(height, width, 0);
// 解析图像数据
var byteIndex = index;
for (y = 1; height; 1) {
for (x = 1; width; 8) {
var byte = tonumber(string.slice(data,byteIndex,byteIndex+1), 16);
byteIndex += 2;
for (bit = 0; 8; 1) {
if (x + bit <= width) {
// 通过位移操作得到每个像素
var pixel = (byte >> (7 - bit)) & 1;
// 0为白,1为黑
imageArray[y][x + bit] = 1 * pixel;
}
}
}
}
return imageArray;
}
// 加载WBMP文件并解析
var hex_data = tostring(string.hex(string.load("guid.wbmp"),''));
var imageArray = parseWbmpHex(hex_data);
import gdip;
mainForm.btnGraphics.oncommand = function(id,event){
var graphics = gdip.graphics(mainForm);
var pen_black = gdip.pen(0xFF000000,1);
var pen_white = gdip.pen(0x00000000,1);
for (x = 1; #imageArray; 1) {
for (y = 1; #imageArray[x]; 1) {
if(imageArray[x][y] == 0){
graphics.drawRectangle( pen_black, y, x, 1, 1);
}
else {
graphics.drawRectangle( pen_white, y, x, 1, 1);
}
}
}
pen_black.delete();
pen_white.delete();
}
mainForm.show(true);
return win.loopMessage();