我是一名初学者,对编码知之甚少。我已经在我的viewfippler画廊中实现了一个保存按钮,但我在这一行上遇到两个错误“Bitmap bitmap = getBitmapFromImageView(ImageView imageView);”在saveimage()方法中。编译器说有预期的“)”,并且在上面指定的行上有一个非法的表达式开始。相关代码如下。
ViewFlipper.java
public class ViewFlipperActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.btnSave).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
saveimage();
}
});
........
}
public Bitmap getBitmapFromImageView(ImageView imageView) {
int viewWidth = imageView.getWidth();
int viewHeight = imageView.getHeight();
Bitmap bitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
imageView.layout(0, 0, viewWidth, viewHeight);
imageView.draw(canvas);
return bitmap;
}
public static void saveimage(){
Bitmap bitmap = getBitmapFromImageView(ImageView imageView);
File f =new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/HD GOSPEL LOCKSCREENS");
if(!f.exists())
{
f.mkdirs();
}
f = new File(f.getAbsolutePath(),
String.valueOf(System.currentTimeMillis()) +"hdgospelLockScreen.jpg");
if(!f.exists())
{
try {
f.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(f));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
.......
}
答案 0 :(得分:1)
您的语法不正确。将此行:Bitmap bitmap = getBitmapFromImageView(ImageView imageView);
更改为Bitmap bitmap = getBitmapFromImageView(imageView);
,其中imageView是ImageView对象。
编辑:另外,你的静态函数saveImage应该包含ImageView对象:
public static void saveImage(ImageView imageView) {