我现在正在制作一个绘图应用程序,用户可以在其中从图库中导入图片并进一步绘图。图片可以加载成功,东西可以绘制成功,但是我想进一步修改,因为当导入的文件尺寸大于屏幕尺寸时,它只会显示部分图像。
因此,我加载屏幕尺寸和导入文件尺寸,如果某些条件,它将弹出警报对话框,以便用户可以选择拉伸或通过填充最大宽度或高度来导入该图片,保持宽度:高度比例.
对于加载图片,它是在ActivityA
调用一个方法ActivityB (name as DrawView).
问题:
alertdialog 强调The constructor AlertDialog.Builder(DrawView) is undefined
了短语中的错误
new AlertDialog.Builder(this);
我尝试将以上内容修改为
new AlertDialog.Builder(DrawView.this);
但仍然失败。这怎么可能被修改?非常感谢!!!
编码:
public void load_pic(String picturePath) // load a picture from gallery
{
// get screen dimension first
WindowManager wm = (WindowManager) context_new.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();
Options op = new Options();
op.inJustDecodeBounds = true;
Bitmap pic_to_be_imported = BitmapFactory.decodeFile(picturePath, op);
int x_pic_to_be_imported = op.outWidth;
int y_pic_to_be_imported = op.outHeight;
if ((x_pic_to_be_imported > screenWidth) || (y_pic_to_be_imported > screenHeight))
{
TextView myView2 = new TextView(context_new.getApplicationContext());
myView2.setText(R.string.message_load_pic);
myView2.setTextSize(15);
AlertDialog.Builder onBackBuilder = new AlertDialog.Builder(DoodleView.this);
onBackBuilder.setTitle(R.string.menuitem_on_load_pic);
onBackBuilder.setView(myView2);
onBackBuilder.setCancelable(true);
onBackBuilder.setPositiveButton(R.string.buttontext_create_load_pic_extend, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
//code
}
});
onBackBuilder.setNegativeButton(R.string.buttontext_create_load_pic_keep_scale, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
bitmap = (BitmapFactory.decodeFile(picturePath)).copy(Bitmap.Config.ARGB_8888, true)
.createScaledBitmap(bitmap, screenWidth, screenHeight, true);
bitmapCanvas = new Canvas(bitmap);
}
});
AlertDialog alert = onBackBuilder.create();
alert.show();
}
// further codes
}