Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

android - Can't save my view to image, but can save other views

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...