Вот мой текущий код:
public class MallMapActivity extends Activity {
private final static String tag = "MallMapActivity";
private ImageView iv;
private final static String FLOOR = "F";
private final String storagePath = Environment.getExternalStorageDirectory() + "/appdata23";
private final String localMapsPath = storagePath + "/localMaps";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
iv = (ImageView)findViewById(R.id.imageview);
//iv.setScaleType(ScaleType.FIT_XY);
final LinearLayout levelLayout = (LinearLayout) findViewById(R.id.level_layout);
int levelSize = 8;
for (int i = 0; i < levelSize; i++) {
Button levelButton = new Button(this.getApplicationContext());
if(i==0) {
levelButton.setText(new StringBuffer((i+1)+"").append(FLOOR).append("(start)"));
} else if (i==7) {
levelButton.setText(new StringBuffer((i+1)+"").append(FLOOR).append("(end)"));
} else {
levelButton.setText(new StringBuffer((i+1)+"").append(FLOOR));
}
levelButton.setTag((i+1) + FLOOR);
levelButton.setId(i);
levelButton.setLayoutParams(
new RadioGroup.LayoutParams(0, RadioGroup.LayoutParams.WRAP_CONTENT, 1));
levelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
int childCount = levelLayout.getChildCount();
int viewId = view.getId();
for (int j = 0; j < childCount; j++) {
Button btn = (Button)levelLayout.getChildAt(j);
if(viewId == j)
btn.setTextColor(Color.BLUE);
else
btn.setTextColor(Color.BLACK);
}
//sample data
double currentPixelX = 169d;
double currentPixelY = 347d;
Log.i(tag, " currentPixelX:" + currentPixelX);
Log.i(tag, " currentPixelY:" + currentPixelY);
int circleSize = 20;
Paint currentPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
currentPaint.setColor(Color.GREEN);
currentPaint.setAlpha(75);
String path = new StringBuffer(localMapsPath)
.append("/").append(view.getTag()).append(".png").toString();
File file = new File(path);
InputStream stream = null;
try {
stream = new FileInputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap mapBitmap = BitmapFactory.decodeStream(stream);
Canvas canvas = new Canvas(mapBitmap);
canvas.drawCircle(
Double.valueOf(currentPixelX).floatValue(),
Double.valueOf(currentPixelY).floatValue(),
circleSize, currentPaint);
iv.setImageBitmap(mapBitmap);
iv.invalidate();
}
});
levelLayout.addView(levelButton);
}
levelLayout.getChildAt(0).performClick();
}
}
Вот содержание ошибки:
ОБНОВЛЕНИЕ:
истинный); Холст холст = новый холст (newMapBitmap);
- чтобы сделать его изменяемым, я изменил код
- внесите это изменение: вы не можете рисовать на неизменяемом растровом изображении, вместо этого вы можете создать его
Bitmap mapBitmap = BitmapFactory.decodeStream(stream); Bitmap newMapBitmap = mapBitmap.copy(Bitmap.Config.ARGB_8888,mapBitmap.isMutable () возвращает ложное значение.