我们如何在Android中使用两个图像覆盖并节省IT

时间:2015-05-01 06:03:25

标签: android opengl-es android-studio

我们如何在Android中使用两个图像覆盖并节省IT 喜欢这个应用程序:https://lh3.ggpht.com/kqSKzLzKvtGZxw2DmSLTyVvRUaX1whq8z89X7Rj9XFGt2zOkMXWXyZyDkND3Yq56k80=h900-rw

1 个答案:

答案 0 :(得分:0)

您可以在Android中将布局保存为图像,例如:

RelativeLayout view;
    view.setDrawingCacheEnabled(true);
    view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    view.buildDrawingCache(true);
    Bitmap b = Bitmap.createBitmap(view.getDrawingCache());
    view.setDrawingCacheEnabled(false); // clear draFwing cache
    bmImage.setImageBitmap(b);
    saveImage();

    public void saveImage() {
            BitmapDrawable drawable = (BitmapDrawable) bmImage.getDrawable();
            Bitmap bitmap = drawable.getBitmap();
            File sdCardDirectory = Environment.getExternalStorageDirectory();
            File image = new File(sdCardDirectory, "my_card.png");
            boolean success = false;
            FileOutputStream outStream;
            try {
                outStream = new FileOutputStream(image);
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
                /* 100 to keep full quality of the image */
                outStream.flush();
                outStream.close();
                success = true;
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (success) {
                Toast.makeText(getApplicationContext(), "Image saved with success",
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(getApplicationContext(),
                        "Error during image saving", Toast.LENGTH_LONG).show();
            }
        }