Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何将图像放在另一个imageview(已设置图像)上并将其保存为组合图像?_Android_Image_Bitmap - Fatal编程技术网

Android 如何将图像放在另一个imageview(已设置图像)上并将其保存为组合图像?

Android 如何将图像放在另一个imageview(已设置图像)上并将其保存为组合图像?,android,image,bitmap,Android,Image,Bitmap,如何将图像放在另一个imageview(已设置图像)上并将其保存为组合图像 下面MoveBitmap类移动位图但不返回任何内容我只想使返回位图 我想实现这一点 :将图像放在图像(已在imageview中设置)上,然后要制作可移动的内部图像(第二个图像),并将它们保存为组合图像。。。。。我不知道如何做到这一点。。。。有人能告诉我吗 移动位图的类 package "name"; import android.app.Activity; import android.content.Con

如何将图像放在另一个imageview(已设置图像)上并将其保存为组合图像

下面MoveBitmap类移动位图但不返回任何内容我只想使返回位图

我想实现这一点 :将图像放在图像(已在imageview中设置)上,然后要制作可移动的内部图像(第二个图像),并将它们保存为组合图像。。。。。我不知道如何做到这一点。。。。有人能告诉我吗

移动位图的类

    package "name";


import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;

public class MoveBitmap extends Activity {

    public class TouchView extends View {

        private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        private float x, y;
        boolean touching = false;

        Bitmap bm = BitmapFactory.decodeResource(
                getResources(),
                R.drawable.n);
        int bm_x = 0;
        int bm_y = 0;
        int bm_w = bm.getWidth();
        int bm_h = bm.getHeight();
        int bm_offsetx;
        int bm_offsety;
        boolean dm_touched = false;


        public TouchView(Context context) {

            super(context);
            // TODO Auto-generated constructor stub

        }

        @Override
        protected void onDraw(Canvas canvas) {
            // TODO Auto-generated method stub
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeWidth(1);
            paint.setColor(Color.WHITE);

            if(touching){
                canvas.drawRect(x, y, x+bm_w, y+bm_h, paint);
            }

            canvas.drawBitmap(bm, bm_x, bm_y, paint);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            // TODO Auto-generated method stub
            setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
                    MeasureSpec.getSize(heightMeasureSpec));
        }

        @Override

        public boolean onTouchEvent(MotionEvent event) {
            // TODO Auto-generated method stub
            int action = event.getAction();
            switch(action){
                case MotionEvent.ACTION_MOVE:
                    x = event.getX();
                    y = event.getY();
                    touching = true;

                    if(dm_touched){
                        bm_x = (int)x - bm_offsetx;
                        bm_y = (int)y - bm_offsety;
                    }

                    break;
                case MotionEvent.ACTION_DOWN:
                    x = event.getX();
                    y = event.getY();
                    touching = true;

                    //check if bm touched
                    if((x > bm_x)
                            && (x < bm_x+bm_w)
                            && (y > bm_y)
                            && (y < bm_y+bm_h)){
                        bm_offsetx = (int)x - bm_x;
                        bm_offsety = (int)y - bm_y;
                        dm_touched = true;
                    }

                    break;
                case MotionEvent.ACTION_UP:
                default:
                    dm_touched = false;
                    touching = false;
            }

            invalidate();
            return true;
        }
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new TouchView(this));

    }
}
包“名称”;
导入android.app.Activity;
导入android.content.Context;
导入android.graphics.Bitmap;
导入android.graphics.BitmapFactory;
导入android.graphics.Canvas;
导入android.graphics.Color;
导入android.graphics.Paint;
导入android.os.Bundle;
导入android.view.MotionEvent;
导入android.view.view;
公共类扩展活动{
公共类TouchView扩展了视图{
私有油漆=新油漆(油漆.防油漆别名标志);
私有浮动x,y;
布尔值=假;
位图bm=BitmapFactory.decodeResource(
getResources(),
R.drawable.n);
int bm_x=0;
int bm_y=0;
int bm_w=bm.getWidth();
int bm_h=bm.getHeight();
国际bm_offsetx;
int bm_offsety;
布尔值dm_=false;
公共触摸视图(上下文){
超级(上下文);
//TODO自动生成的构造函数存根
}
@凌驾
受保护的void onDraw(画布){
//TODO自动生成的方法存根
绘制.设置样式(绘制.样式.笔划);
油漆。设置行程宽度(1);
油漆。设置颜色(颜色。白色);
如果(触摸){
画布.drawRect(x,y,x+bm_w,y+bm_h,绘画);
}
画布.绘图位图(bm,bm_x,bm_y,paint);
}
@凌驾
测量时的保护空隙(内部宽度测量等级、内部高度测量等级){
//TODO自动生成的方法存根
设置测量尺寸(测量等级getSize(宽度测量等级),
测量等级getSize(高度测量等级));
}
@凌驾
公共布尔onTouchEvent(运动事件){
//TODO自动生成的方法存根
int action=event.getAction();
开关(动作){
case MotionEvent.ACTION\u移动:
x=event.getX();
y=event.getY();
触摸=真实;
如果(dm_触摸){
bm_x=(int)x-bm_offsetx;
bm_y=(int)y-bm_偏移量;
}
打破
case MotionEvent.ACTION\u DOWN:
x=event.getX();
y=event.getY();
触摸=真实;
//检查bm是否接触
如果((x>bm_x)
&&(xBMU y)
&&(y
您可以使用以下方法从视图中使用图形缓存:

public static Bitmap loadBitmapFromView(View v) {
    Bitmap bitmap;
    v.setDrawingCacheEnabled(true);
    bitmap = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false);
}
但是您需要有一个包含两个ImageView的布局(例如,框架布局)。第一个作为背景(初始图像),第二个作为可移动图像。然后以您需要的方式放置视图,然后使用FrameLayout作为视图,使用上面的函数制作一个屏幕截图

public Bitmap screenShot(View view) {
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
            view.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    view.draw(canvas);
    return bitmap;
}