android - 如何在android中创建图像 ScrollView 的位图?

标签 android android-bitmap

我已经在 ,android 中制作了一个幻灯片演示。我将图像绑定(bind)到我的 LinearLayout 运行时,现在我想将整个可 ScrollView 保存到位图,我尝试了很多但都提供了仅将当前可见屏幕保存到位图的解决方案,任何人都可以帮助我如何保存整个可 ScrollView 在位图中查看(屏幕不可见),我的代码如下:

xml

<HorizontalScrollView
    android:id="@+id/horizontal_scroll_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="55dp"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="55dp"
    android:scrollbars="none" >

    <ScrollView
        android:id="@+id/scroler"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:scrollbars="none" >

        <LinearLayout
            android:id="@+id/mygallery"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" />
    </ScrollView>
</HorizontalScrollView>

Java

View insertPhoto(int i) {
    LinearLayout layout = new LinearLayout(getApplicationContext());
    layout.setLayoutParams(new LayoutParams(252, 252));
    layout.setGravity(Gravity.FILL);

    final ImageView imageView = new ImageView(getApplicationContext());
    imageView1 = new ImageView(getApplicationContext());
    imageView.setLayoutParams(new LayoutParams(250, 250));
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);

    imageLoader.displayImage("file://" + dataT.get(i).sdcardPath,
            imageView, new SimpleImageLoadingListener() {

                public void onLoadingStarted(String imageUri, View view) {
                    imageView.setImageResource(R.drawable.no_media);
                    super.onLoadingStarted(imageUri, view);
                }
            });
    layout.addView(imageView);
    return layout;
}

使用它我制作了垂直方向的胶片。现在我想要这个胶片的位图来保存它。

最佳答案

public static Bitmap loadBitmapFromView(View v) {
        Bitmap b = null;
            v.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            b = Bitmap.createBitmap(v.getMeasuredWidth(),
                    v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
            Canvas c = new Canvas(b);
            v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
            v.draw(c);
        saveImageToInternalStorage(b);
        return b;
    }

关于android - 如何在android中创建图像 ScrollView 的位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29506160/

相关文章:

android - 防止共享我的应用程序的安全性

android - ListAdapter 和后台线程

java - BitmapFactory.decodeFile 返回 null

android - 如何缩放(缩放和移动)到 PhotoVIew 中位图的 x、y 坐标?

android - 将 Android 位图转换为 OpenCV Mat 并向后转换

android - 每当发生变化时如何阻止android重新绘制整个屏幕?

android - 对 Google GCM XMPP 感到困惑

android - 如何在android中将图像转换为视频

java - 如何使用 FCM 管理聊天应用程序的推送通知

Android:如何使用 Canvas /绘制位图缩放位图以适合屏幕大小?