I have a ImageView which shows a picture that has been taken from the camera. The effect i am trying to create is I want a image to appear over the ImageView with the OnTouchEvent. So say I have five images I am wanting it to have five OnTouchEvent's and for each touch on the screen a new image would appear over the top of the previouslly displayed image (they are transparent png's).
I have looked through this question Adding an Image to a Canvas in Android but can't get my head around it.
So basically I am wanting it so when you are viewing the Activity with the Image in the ImageView
you can touch the screen which will then add a png over the top of the picture in the ImageView
and so on for say 6 or 7 images. Each one gets added sepertaly so it would take 6 touchs of the screen to add 6 png's over the current Image in the Imageview
UPDATE Thanks to Graeme
The code below has been updated I am just getting an error on nextBitmap
which is nextBitmap cannot be resolved
I think this is because I need to set this somewhere to go through the images that will be added like make an array?
Update 2
I now know that I need to some how add a string nextBitmap
with the Images in so that it will loop throw them when the screen is touched, anyone got any ideas?
public class BeatEmUp extends Activity {
Bitmap myBitmap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.beatemup);
String myRef = this.getIntent().getStringExtra("filepath");
File imgFile = new File(myRef);
Log.e("No ref", myRef);
if(imgFile.exists()) {
final Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
final ImageView myImage = (ImageView) findViewById(R.id.beatemup);
myImage.setImageBitmap(myBitmap);
myImage.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
myBitmap = getBitmapOverlay(myBitmap, nextBitmap, 0, 0);
myImage.setImageBitmap(myBitmap);
}
});
}
}
public static Bitmap getBitmapOverlay(Bitmap bmp1, Bitmap bmp2, int left, int top) {
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, 0, 0, null);
canvas.drawBitmap(bmp2, left, top, null);
return bmOverlay;
}
}