I put each line every point of x, y coordinates to list
The final list the size of the hundreds of W, the convention has more than 1000 W
This leads to frequent GC, easily jammed
After get all the points corresponding to the coordinates of the turning RGBA_8888 bitmap
Then show to the ImageView
This is Bresenham line drawing algorithm
X0, y0 line starts at the coordinates of the
X1, y1 line at the end of the coordinates of the
Private void getPXpoint (int x0, int y0, int x1, int y1) throws OutOfMemoryError {
If (x0 & lt; 0 | | x0 & gt; Screen_width * 3)
return;
Int x=x0;
Int y=y0;
Int w=x1 - x0;
Int h=y1 - y0;
Int dx1=w & lt; 0? 1: (w & gt; 0? 1:0);
Int dy1=h & lt; 0? 1: (h & gt; 0? 1:0);
Int dx2=w & lt; 0? 1: (w & gt; 0? 1:0);
Int dy2=0;
Int fastStep=Math. Abs (w);
Int slowStep=Math. Abs (h);
If (fastStep & lt;={slowStep)
FastStep=Math. Abs (h);
SlowStep=Math. Abs (w);
Dx2=0;
Dy2=h & lt; 0? 1: (h & gt; 0? 1:0);
}
Int numerator=fastStep & gt;> 1;
For (int I=0; i <=fastStep; I++) {
Point Point=new Point (x, y);
Points. The add (point);//each point of the x, y coordinates save
The numerator +=slowStep;
If (numerator & gt;={fastStep)
Numerator -=fastStep;
X +=dx1;
Y +=dy1;
} else {
X +=dx2;
Y +=dy2;
}
}
}
CodePudding user response:
1. Used on besides?CodePudding user response: