gpt4 book ai didi

android - 如何将图像放在另一个 ImageView (已经是一组图像)上并将其保存为组合图像?

转载 作者:行者123 更新时间:2023-11-29 20:07:07 29 4
gpt4 key购买 nike

如何将一张图片放在另一个imageview(已经是set image)上并保存为组合图?

在 MoveBitmap 类下移动位图但没有返回我只想返回一个位图

i want to Achieve that :put an image on image (which already set in imageview) and then want to make movable inner image (second image) and save these both as combined image ..... i m confused how to accomplish that .... can anyone tell me ?

移动位图的类

    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));

}
}

最佳答案

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;
}

关于android - 如何将图像放在另一个 ImageView (已经是一组图像)上并将其保存为组合图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35504916/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com