首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从视图中保存照片拼贴

从视图中保存照片拼贴
EN

Stack Overflow用户
提问于 2015-01-17 13:13:13
回答 1查看 2.8K关注 0票数 1

我还有另一种看法:

代码语言:javascript
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="350dp"
    android:layout_height="350dp"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="140dp"
        android:layout_height="match_parent"
        android:layout_marginRight="2.5dp"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="2.5dp"
            android:layout_weight="1"
            android:longClickable="true"
            android:scaleType="matrix"
            android:src="@drawable/a1" />


        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="2.5dp"
            android:layout_weight="1"
            android:longClickable="true"
            android:scaleType="matrix"
            android:src="@drawable/a2" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_marginLeft="2.5dp"
            android:longClickable="true"
            android:scaleType="matrix"
            android:src="@drawable/a4" />
    </LinearLayout>
</LinearLayout>

看上去:

在此视图中,用户可以编辑此图片的查看(缩放、旋转)。

我得保存编辑好的照片拼贴。如何用缩放和旋转的照片保存视图?是否可以将位图中的编辑视图保存到应用程序缓存中?

谢谢你的帮助!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-17 13:32:51

是的,您可以简单地获取编辑图像的屏幕截图,并创建一个位图,该位图可以保存在任何您想要的位置。

下面是获取位图的函数

代码语言:javascript
复制
public Bitmap getBitMap() {
    try {
        yourEditedPhotoCollageLayout.buildDrawingCache();
        Bitmap bmp = Bitmap.createBitmap(yourEditedPhotoCollageLayout.getDrawingCache());
        return bmp;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

这样你就可以保存那个位图

代码语言:javascript
复制
private void saveBitmap(Bitmap bitmap) {
    try {
        File storageDir = createImageFile();
        String path = storageDir.toString();
        OutputStream out = new FileOutputStream(path);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.close();

        MyMediaConnectorClient client = new MyMediaConnectorClient(path);
        MediaScannerConnection scanner = new MediaScannerConnection(
                Context, client);
        client.setScanner(scanner);
        scanner.connect();

    } catch (IOException e) {
        Log.e("save image", "failed to save image", e);
    }
}
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27999801

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档