80,351
社区成员
发帖
与我相关
我的任务
分享
public class Buf {
final int DeviceWidth;
final int DeviceHeight;
boolean[][] matrix;
public Buf(int w, int h)
{
this.DeviceWidth = w;
this.DeviceHeight = h;
matrix = new boolean[w][h];
}
public void getPXpoint(int x0, int y0, int x1, int y1)
{
// 确保 x0, y0, x1, y1不超出DeviceWidth, DeviceHeight
// 不知道原代码为何检测 x0 > screen_width * 3
// Bresenham 画线算法
// ...
for (int i = 0; i <= fastStep; i++) {
//Point point = new Point(x, y); 删除此行
//points.add(point); 删除此行
matrix[x][y] = true; //*** 唯一的改动在这里,不用Point, 直接设置相应的坐标 ***
//....
}
}
public void paint1()
{
for(int x=0; x<DeviceWidth; x++)
{
for(int y=0; y<DeviceHeight; ++)
{
if(matrix[x][y])
{
paint(x,y);// 如果绘图函数支持直接传入x,y
}
}
}
}
public void paint2()
{
Point p = new Point(0,0); //只创建这一个Point
for(int x=0; x<DeviceWidth; x++)
{
for(int y=0; y<DeviceHeight; y++)
{
if(matrix[x][y])
{
p.x = x;
p.y = y;
paint(p);// 如果绘图函数只支持Point
}
}
}
}
public static void main(String[] args) {
Buf buf = new Buf(1920, 1080);
buf.getPXpoint(x0, y0, x1, y1);
buf.getPXpoint(x1, y1, x2, y2);
// ....
buf.paint1(); // Or buf.paint2();
}
}
最大4K屏 3840*2160
RGB拆分R、G、B,等于是再*3
需求是这样的
根据当前屏幕分辨率申请一块BUF,比如1920*1080*3(RGB),然后不考虑RGB,
相当于屏幕有(1920*3)*1080那么大,在上面的内存区画斜线,每一根斜线只有一个字节的大小,
颜色值是0或者255(黑白),那这条线根据算法画线就有1080个点
然后就是3条斜线(3个字节)组成一条RGB线,再然后转4字节的ARGB_8888,画满全屏内存区就有1920*3*1080条线
每条线有1080个点,分段操作的话,也是要等好久才[/quote]