将imageView保存为线性布局作为图像

时间:2015-12-26 09:29:02

标签: android performance android-layout android-intent bitmap

我需要结合使用imageView和线性布局来保存共享意图内容的图像。 Imageview来自列表项ImageAdaptor。我正在尝试创建动态布局并将其保存为位图,然后将其传递给共享意图。

enter image description here

图片给出了我的要求。

下面是我的动态布局创建代码,

            LinearLayout sharelayout = new LinearLayout(context);
            ImageView tv1 = new ImageView(context);
            holder.image.setDrawingCacheEnabled(true);
            holder.image.buildDrawingCache(true);
            tv1.setImageBitmap(holder.image.getDrawingCache());
            LayoutInflater vi = (LayoutInflater) context
                    .getSystemService(context.LAYOUT_INFLATER_SERVICE);

            LinearLayout bottom = (LinearLayout) vi.inflate(
                    R.layout.bottom_share, null);
            sharelayout.setLayoutParams(new LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

            sharelayout.setOrientation(LinearLayout.VERTICAL);
            sharelayout.addView(tv1);
            sharelayout.addView(bottom);

            sharelayout.setDrawingCacheEnabled(true);
            sharelayout
                    .setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
            sharelayout.buildDrawingCache(true);
            Bitmap bitmap = Bitmap.createBitmap(sharelayout
                    .getDrawingCache());

            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.setPackage("com.whatsapp");
            // Add text and then Image URI
            // shareIntent.putExtra(Intent.EXTRA_TEXT,
            // vals.getTime()+" "+vals.getPostUrl().toString()+"?utm_source=ws");
            shareIntent.putExtra(Intent.EXTRA_STREAM,
                    getImageUri(context, bitmap));
            shareIntent.setType("image/jpeg");
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            try {
                context.startActivity(shareIntent);
            } catch (android.content.ActivityNotFoundException ex) {

            }

代码在Bitmap bitmap = Bitmap.createBitmap(sharelayout.getDrawingCache())中给出异常;

我想与附加的线性布局共享Image。有没有更好的方法来实现这一目标?

0 个答案:

没有答案