无法设置多个位图于一体的ImageView [英] unable to set multiple bitmap in one imageview

查看:126
本文介绍了无法设置多个位图于一体的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的活动我收到的位图,使多个位图,并显示在一个图像视图
I M获得多个图像,但不是在图像视图请帮我设置是否正确?

 私人位图Final_Murge_Bitmap()
        {
        Murge_Bitmap = NULL;
        尝试{        Murge_Bitmap = Bitmap.createBitmap(500,500,Bitmap.Config.ARGB_8888);
        帆布C =新的Canvas(Murge_Bitmap);
        c.drawBitmap(Murge_Bitmap,0,0,NULL);
        可绘制drawable1 =新BitmapDrawable(Bitmap_recieve);
        可绘制drawable2 =新BitmapDrawable(Bitmap_recieve);
        可绘制drawable3 =新BitmapDrawable(Bitmap_recieve);
        可绘制drawable4 =新BitmapDrawable(Bitmap_recieve);
        可绘制drawable5 =新BitmapDrawable(Bitmap_recieve);
        可绘制drawable6 =新BitmapDrawable(Bitmap_recieve);
        可绘制drawable7 =新BitmapDrawable(Bitmap_recieve);
        可绘制drawable8 =新BitmapDrawable(Bitmap_recieve);        drawable1.setBounds(220,220,501,501);
        drawable2.setBounds(330,330,400,400);
        drawable3.setBounds(160,150,200,200);
        drawable4.setBounds(140,120,200,200);
        drawable5.setBounds(120,100,400,400);
        drawable6.setBounds(100,80,500,500);
        drawable7.setBounds(80,70,200,200);
        drawable8.setBounds(60,60,200,200);        drawable1.draw(C);
        drawable2.draw(C);
        drawable3.draw(C);
        drawable4.draw(C);
        drawable5.draw(C);
        drawable6.draw(C);
        drawable7.draw(C);
        drawable8.draw(C);    }赶上(例外五)
    {
    }
    返回Murge_Bitmap;
    }}


解决方案

您可以做类似如下:

 公共位图drawMultipleBitmapsOnImageView(位图B){
        位图drawnBitmap = NULL;        尝试{
            drawnBitmap = Bitmap.createBitmap(400,400,Config.ARGB_8888);            帆布帆布=新的Canvas(drawnBitmap);
                     //只要改变对不同位图和坐标。
            canvas.drawBitmap(B,100,100,NULL);
            canvas.drawBitmap(B,200,300,空);
            canvas.drawBitmap(B,100,200,空);
            canvas.drawBitmap(B,300,350,空);        }赶上(例外五){
            e.printStackTrace();
        }
        返回drawnBitmap;
    }

您调用此方法如下所示:

  ImageView的myImageView =(ImageView的)findViewById(R.id.myImageView);
        位图的位图=((BitmapDrawable)myImageView.getDrawable())
                .getBitmap();
        位图B = drawMultipleBitmapsOnImageView(位图);        myImageView.setImageBitmap(二);

和请给我一些反馈。

希望有所帮助。

this is my activity in i am receiving bitmap and making multiple bitmap and show in one image view i m getting multiple image but not set properly in image view please help me ?

        private Bitmap Final_Murge_Bitmap() 
        {  
        Murge_Bitmap = null;
        try {

        Murge_Bitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(Murge_Bitmap);
        c.drawBitmap(Murge_Bitmap, 0, 0, null);
        Drawable drawable1 = new BitmapDrawable(Bitmap_recieve);
        Drawable drawable2 = new BitmapDrawable(Bitmap_recieve);
        Drawable drawable3 = new BitmapDrawable(Bitmap_recieve);
        Drawable drawable4 = new BitmapDrawable(Bitmap_recieve);
        Drawable drawable5 = new BitmapDrawable(Bitmap_recieve);
        Drawable drawable6 = new BitmapDrawable(Bitmap_recieve);
        Drawable drawable7 = new BitmapDrawable(Bitmap_recieve);
        Drawable drawable8 = new BitmapDrawable(Bitmap_recieve);

        drawable1.setBounds(220, 220, 501, 501);
        drawable2.setBounds(330, 330, 400, 400);
        drawable3.setBounds(160, 150, 200, 200);
        drawable4.setBounds(140, 120, 200, 200);
        drawable5.setBounds(120, 100, 400, 400);
        drawable6.setBounds(100, 80, 500, 500);
        drawable7.setBounds(80, 70, 200, 200);
        drawable8.setBounds(60, 60, 200, 200);

        drawable1.draw(c);
        drawable2.draw(c);
        drawable3.draw(c);
        drawable4.draw(c);
        drawable5.draw(c);
        drawable6.draw(c);
        drawable7.draw(c);
        drawable8.draw(c);

    } catch (Exception e)
    {
    }
    return Murge_Bitmap;
    }}

解决方案

you can do something like the following :

public Bitmap drawMultipleBitmapsOnImageView(Bitmap b) {
        Bitmap drawnBitmap = null;

        try {
            drawnBitmap = Bitmap.createBitmap(400, 400, Config.ARGB_8888);

            Canvas canvas = new Canvas(drawnBitmap);
                     // JUST CHANGE TO DIFFERENT Bitmaps and coordinates .
            canvas.drawBitmap(b, 100, 100, null);
            canvas.drawBitmap(b, 200, 300, null);
            canvas.drawBitmap(b, 100, 200, null);
            canvas.drawBitmap(b, 300, 350, null);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return drawnBitmap;
    }

you call this method like the following :

ImageView myImageView = (ImageView) findViewById(R.id.myImageView);
        Bitmap bitmap = ((BitmapDrawable) myImageView.getDrawable())
                .getBitmap();
        Bitmap b = drawMultipleBitmapsOnImageView(bitmap);

        myImageView.setImageBitmap(b);

and please give me some feedback .

Hope that helps .

这篇关于无法设置多个位图于一体的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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