保存多个图像视图作为单个文件 [英] save multiple image views as a single file

查看:150
本文介绍了保存多个图像视图作为单个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,人们相对布局具有完全的三ImageView的()的。我想所有三个imageviews保存为单个.png文件到存储设备上的一个按钮的点击。

In my application , one Relative Layout has totally three ImageView()'s . I want to save all the three imageviews as a single .png file to the device storage on a single button click.

我的code:

布局XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/make" >

 <ImageView
     android:id="@+id/imageView1"
     android:layout_width="wrap_content"
     android:layout_height="300dp"
     android:layout_above="@+id/button1"
     android:layout_alignParentLeft="true"
     android:layout_alignParentRight="true"
     android:layout_alignParentTop="true"
     android:src="@drawable/am0" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="60dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:text="Save Meme"
    android:textStyle="bold"
    android:textColor="@color/wt" />

<ImageView
    android:id="@+id/top"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="64dp"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/down"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imageView1"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="74dp"
    android:src="@drawable/ic_launcher" />

活动code:

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);


    setContentView(R.layout.sm);

    main1 = (ImageView) findViewById(R.id.imageView1);
    top = (ImageView) findViewById(R.id.top);
    down = (ImageView) findViewById(R.id.down);

    Bundle rec = getIntent().getExtras();

    int rec1 = getIntent().getExtras().getInt("ams0");
    Bitmap bmp = (Bitmap) rec.getParcelable("bm0");
    Bitmap bmp1 = (Bitmap) rec.getParcelable("bm1");


    main1.setImageResource(rec1);
    top.setImageBitmap(bmp);
    down.setImageBitmap(bmp1);


}

如何将图像视图保存为文件?

How do I save the image views as a file ?

推荐答案

尝试使用Сanvas

Bitmap mainBitmap = ((BitmapDrawable)main1.getDrawable()).getBitmap().copy(Bitmap.Config.ARGB_8888, true); 
Canvas canvas = new Canvas(mainBitmap);
canvas.drawBitmap(bmp.copy(Bitmap.Config.ARGB_8888, true), 1, 1, null);
canvas.drawBitmap(bmp1.copy(Bitmap.Config.ARGB_8888, true), 1, 1, null);

OutputStream os = null;
try {
      os = new FileOutputStream("/sdcard/DCIM/Camera/myImages.png");
      mainBitmap.compress(Bitmap.CompressFormat.PNG, 50, os);
} catch (IOException e) {
      e.printStackTrace();
}

这篇关于保存多个图像视图作为单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆