这是我的代码的一部分,如果我在其他代码中的另一个活动中使用该代码,例如:
case R.id.buttonMinus:
它工作得很好,它只保存该特定按钮的背景。如果我在图形视图中使用它,它总是以“Error1”结束。(Graphview 是将图形绘制到画布中的视图)
另外,我想在应用程序的某个不同位置显示图片,我一直在尝试通过
myWebView.loadUrl(Environment.getExternalStorageDirectory()+ File.separator + "DivePlanner" + File.separator + "Dive.png");
但没有运气
我整天都被困在这个问题上,如果有人可以提供帮助,请提前致谢!
buttonClick.performClick();
}
public void onClick(View v) {
String[] verlabels = new String[] {"0m", Float.toString(-max/2) + "m", Float.toString(-max) + "m"};
String[] horlabels = new String[] {"0 min",Float.toString((int)x[pocetBodu]/2)+" min",Float.toString((int)x[pocetBodu])+" min"};
GraphView graphView = new GraphView(this, y, "Dive Manager",horlabels, verlabels, GraphView.LINE,x,Pspotreba,pocetBodu,pocetUseku);
setContentView(graphView);
if(Save)
{
graphView.buildDrawingCache();
Bitmap bm=graphView.getDrawingCache();
OutputStream fOut = null;
Uri outputFileUri;
try {
File root = new File(Environment.getExternalStorageDirectory()+ File.separator + "DivePlanner" + File.separator);
root.mkdirs();
File sdImageMainDirectory = new File(root, "Dive.png");
outputFileUri = Uri.fromFile(sdImageMainDirectory);
fOut = new FileOutputStream(sdImageMainDirectory);
}
catch (Exception e) {
Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
}
try {
bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
Toast.makeText(this, "Ponor uložen", Toast.LENGTH_SHORT).show();
}
catch (Exception e) {
Toast.makeText(this, "Error1", Toast.LENGTH_SHORT).show();
}
}