有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java的缩放图形问题

我对安卓5.1版有问题。(lolipop)

当我尝试使用Bitmap.createScaledBitmap缩放位图时,应用程序向我发送了一个错误:

java.lang.NullPointerException: Attempt to invoke virtual method 'int 安卓.graphics.Bitmap.getWidth()' on a null object reference

我不知道为什么会这样。在最新版本的安卓系统上,这项功能运行良好

ImageView imageView = this.menuPageModel.getBackground();
int id;
Bitmap bitmap;
Context context = appModel.getContext();

id = context.getResources().getIdentifier("background", "drawable", context.getPackageName());

bitmap = BitmapFactory.decodeResource(context.getResources(), id);

bitmap = Bitmap.createScaledBitmap(bitmap, appModel.getScreenWidth(), appModel.getScreenHeight(), false);

imageView.setLayoutParams(new 安卓.view.ViewGroup.LayoutParams(appModel.getScreenWidth(), appModel.getScreenHeight()));

imageView.setImageBitmap(bitmap);

共 (0) 个答案