Java Android-在位图上绘制
早上好。我正在写一个应用程序来显示和分析探地雷达地图。不幸的是,我得到的映射是txt文件,其中char0x00表示黑色,0xFF表示白色。该应用程序处于早期阶段,我已使用以下代码在屏幕上显示这些文件:Java Android-在位图上绘制,java,android,bitmap,android-canvas,Java,Android,Bitmap,Android Canvas,早上好。我正在写一个应用程序来显示和分析探地雷达地图。不幸的是,我得到的映射是txt文件,其中char0x00表示黑色,0xFF表示白色。该应用程序处于早期阶段,我已使用以下代码在屏幕上显示这些文件: public class DrawMap extends View { // ... public void onDraw(Canvas canvas) { super.onDraw(canvas); this.paint.setStyle(Pai
public class DrawMap extends View {
// ...
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
this.paint.setStyle(Paint.Style.FILL);
this.paint.setStrokeWidth(1);
for (int x = 0; x < this.map.getSize(); x++) {
for (int y = 0; y < this.map.getSize(); y++) {
char val = this.map.getPixel(x, y);
this.paint.setColor(Color.argb(0xff, val, val, val));
canvas.drawPoint(10+x, 10+y, this.paint);
}
}
}
}
公共类DrawMap扩展视图{
// ...
公共空白onDraw(画布){
super.onDraw(帆布);
this.paint.setStyle(paint.Style.FILL);
此。油漆。设置行程宽度(1);
对于(intx=0;x
由于地图的大小(宽度x高度)可能会有所不同,因此,首先在位图或类似的东西上绘制地图,然后根据屏幕大小显示地图会更容易。我不知道如何做到这一点。我需要你的帮助。试试这个:
int w = WIDTH_PX, h = HEIGHT_PX;
Bitmap.Config conf = Bitmap.Config.RGB_565;
Bitmap bmp = Bitmap.createBitmap(w, h, conf);
Canvas canvas = new Canvas(bmp);
// ready to draw on that bitmap through that canvas
资料来源:
希望有帮助 查看所有画布构造函数