Here's a part of my code, if I use the code in another activity in some other code, such as:
case R.id.buttonMinus:
it works just fine, it only saves the background of that particular button. If I use it in the graphview, it always ends up with "Error1".
(Graphview is a view that paints a graph into the canvas)
Also, I would like to display the picture on some different place in the app, I have been trying to do that by
myWebView.loadUrl(Environment.getExternalStorageDirectory()+ File.separator + "DivePlanner" + File.separator + "Dive.png");
but no luck
I have been stuck on this all day, if anyone can help, thanks in advance !
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();
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…