好吧,我将首先介绍我的应用程序的基础知识。到目前为止,您使用相机拍摄照片,然后将其保存到文件夹中。照片拍完后,一个新的活动打开并在屏幕上显示ImageView
。可绘制图像数组
我想要达到的效果是沿着能够使用onClick事件在ImageView
中的图片顶部创建png图层的行。所以说我有5个透明PNG的,我想要有5个onClick事件,每次触摸屏幕时,新的PNG图像将显示在ImageView
的图片顶部,因此需要5个onClick(触摸屏幕)来显示所有的透明PNG在图片的顶部。
我觉得我几乎没有与下面的代码,但我想我需要建立在drawable
文件夹需要与每个onClick事件来显示图像的array
,我觉得数组应该是nextBitmap
但不当然。
更新Sparkys回答
我曾尝试加入private Integer[] nextBitmap = { R.drawable.img1, R.drawable.img2 };
但我得到的错误The method getBitmapOverlay(Bitmap, Bitmap, int, int) in the type BeatEmUp is not applicable for the arguments (Bitmap, Integer[], int, int)
谁知道这可能是我需要添加private Integer[]......
的onCreate
方法之外?
public class Image extends Activity {
Bitmap myBitmap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Image);
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;
}
}
如果用户必须在5个图像显示前点击5次,我不会将它们全部加载到数组中,因为用户可能不会点击5次。这将浪费内存和电池电量。每次用户点击时我都会加载它们。 – 2012-01-05 09:58:37
好酷,不知道该怎么做。 – Matt 2012-01-05 10:03:11