Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加完整导图截图功能和导出文本功能 #10

Open
onexuan opened this issue Sep 16, 2021 · 5 comments
Open

增加完整导图截图功能和导出文本功能 #10

onexuan opened this issue Sep 16, 2021 · 5 comments

Comments

@onexuan
Copy link

onexuan commented Sep 16, 2021

可以增加完整导图截图功能和导出文本功能

文本功能如下:

地球
    海洋
         北冰洋
         大西洋
         太平洋
    陆地
         亚洲
         欧洲
@guaishouN
Copy link
Owner

可以增加完整导图截图功能和导出文本功能

文本功能如下:

地球
    海洋
         北冰洋
         大西洋
         太平洋
    陆地
         亚洲
         欧洲

如果作为一个通用的结构图控件,这方面你有具体的方案没有?比如json、xml...,一般用法有哪些?
因为我之前项目没有做复杂功能,编辑功能都是应别人请求做的

@onexuan
Copy link
Author

onexuan commented Sep 17, 2021

我是试了序列化对象再转成hex string,这样app容易序列化与反序列化,但如果离开app,就只能导致出文本格式了,方便用户看文本。试过NodeModel导成Gson,会FC
编辑功能是有必要的

@onexuan
Copy link
Author

onexuan commented Sep 17, 2021

我试过截view图,但文字比较小还有只有某个区域,得做区域截图并做全域滚动,再把图拼接。导出图片也是一种格式导出

@hardlove
Copy link

生成截图的功能我这边已经实现,可以参考:

 /**
     * 加载静态xml布局资源生成Bitmap
     *
     * @param context
     * @param layoutRes xml 布局资源ID
     * @param onInitCallBack 数据初始化回调
     */
    fun convertViewToBitmap(
        context: Context,
        @LayoutRes layoutRes: Int,
        onInitCallBack: (View)-> Unit
    ): Bitmap {
        val root = LayoutInflater.from(context).inflate(layoutRes, null)
        onInitCallBack(root)
        //测量
        val width = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
        val height = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
        root.measure(width, height)
        val measuredWidth = root.measuredWidth
        val measuredHeight = root.measuredHeight

        //再次测量(避免子View无法正常显示)
        root.measure(View.MeasureSpec.makeMeasureSpec(measuredWidth, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(measuredHeight, View.MeasureSpec.EXACTLY))

        //布局
        root.layout(0, 0, measuredWidth, measuredHeight)
        val bitmap = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888)
        val canvas = Canvas(bitmap)
        root.draw(canvas)
        return bitmap
    }
val bitmap =
                                                BitmapUtils.convertViewToBitmap(activity,
                                                        R.layout.save_xmind_layout) { rootView ->
                                                    val gysoTreeView =
                                                            rootView.findViewById<GysoTreeView>(
                                                                    R.id.tree_view)

                                                    val saveAdapter =
                                                            XMindTreeViewAdapter()
                                                    gysoTreeView.adapter = saveAdapter

                                                    gysoTreeView.setTreeLayoutManager(
                                                            getTreeLayoutManager())

                                                    saveAdapter.treeModel =
                                                            adapter.treeModel
                                                    saveAdapter.bindBaseTreeView(
                                                            gysoTreeView)
                                                    saveAdapter.getTreeViewEditor()
                                                            .focusMidLocation(false)
                                                }

目前还有给棘手的问题就是,如何把数据存储起来,序列化会直接报错,这比较麻烦,不知道大家有什么好办法没?

@onexuan
Copy link
Author

onexuan commented Feb 23, 2023

@hardlove

public static String writeTreeObject(Object object) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(object);
oos.close();
ByteString byteString = ByteString.of(out.toByteArray(),0,out.size());
return byteString.hex();
}

public static Object readTreeObject(String hex) throws Exception {
    ByteArrayInputStream in=new ByteArrayInputStream(ByteString.decodeHex(hex).toByteArray());
    ObjectInputStream oin = new ObjectInputStream(in);
    Object obj = oin.readObject();
    oin.close();
    return obj;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants