- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我似乎无法弄清楚这一点。我有 2 个具有不同特性的 java 类,每个都调用 BitmapFactory.decodeResource 来获取相同的图像资源,一个返回位图,而另一个返回 null。这两个类都在同一个包中。
这是工作的类,它调用返回位图的 BitmapFactory.decodeResource。我只包含了相关代码。
package advoworks.test;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class MainScreen extends SurfaceView implements SurfaceHolder.Callback {
private static final String TAG = MainScreen.class.getSimpleName();
public MainScreen(Context context) {
super(context);
Bitmap bitmap;
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.droid_1);
//adding the callback (this) to the surface holder to intercept events;
getHolder().addCallback(this);
// make the GamePanel focusable so it can handle events
setFocusable(true);
}
}
这是不起作用的类。 BitmapFactory.decodeResource 在调试时返回 NULL。我只包含了我认为相关的代码。
package advoworks.test;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.Log;
public class Segment {
private int x;
private int y;
private Bitmap bitmap;
public Segment(int x, int y) {
Log.d(TAG, "Creating Segment");
try {
this.bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.droid_1);
} catch (Exception e) {
Log.d(TAG,"Error is " + e);
}
this.x = x;
this.y = y;
Log.d(TAG, "Created Segment");
}
}
有什么线索吗?
最佳答案
检查图像的分辨率,如果太大,BitmapFactory.decodeResource 将返回 null(无一异常(exception))
关于安卓:BitmapFactory.decodeResource 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7501863/
在我的应用程序中,我有以下几行代码: import android.graphics.Bitmap; import android.graphics.BitmapFactory; private Bi
我有这种方法,可以在图像上绘制一些文本: public BitmapDrawable writeOnDrawable(int drawableId, String text){ Bit
我正在尝试从 View 对象中的内部资源加载位图(源本身位于“可绘制”文件中)。 代码是: import android.content.Context; import android.graphic
我正在为 child 子开发一款游戏,其中包含不同的教育练习。在其中一个中,我需要一个图片背景,因此我正在加载它并使用矩阵缩放它以填充屏幕。但有时加载图片会导致崩溃。 public DrawThrea
我正在重新编写一个 Android 应用程序,其中每个 Activity (有多个)都显示背景图片。用户可能会更改此图像,因此我已完成以下操作: 创建了 MyAppApplication(扩展了 Ap
您好,我正在使用以下方法将位图设置为 ImageView: o = new BitmapFactory.Options(); o.inJustDecodeBounds
我的 /res/drawable/ 目录中有一张 120x120px 的图片。这是所有设备所需的大小。 要加载此位图,我使用以下内容: Bitmap tmpBmp = BitmapFactory.de
我刚刚在检查一些资源图像的一些解码时间时注意到,当我将资源图像移动到 drawable 文件夹时,BitmapFactory.decodeResource() 函数大约慢了 3-6 倍。 问题: 有人
我对从资源加载位图有疑问。我的代码: public void onClick(View view) { if (mainButton == view) { Bitmap bm
我有这段代码可以裁剪图像表的一部分。 问题是当我使用 BitmapFactory.decodeResource 并记录宽度和高度时,大小与原始大小不同。 Bitmap spriteSheet = Bi
我的 /res/drawable/ 目录中有一张 120x120px 的图片。这是所有设备所需的大小。 要加载此位图,我使用以下内容: Bitmap tmpBmp = BitmapFactory.de
我在解码可绘制图像资源 960x926px jpg 时遇到奇怪的内存不足错误,分配了 3555856 字节。图像仅放置在 drawable-xxhdpi (3x) 中,我使用的是 hdpi (1.5x
我似乎无法弄清楚这一点。我有 2 个具有不同特性的 java 类,每个都调用 BitmapFactory.decodeResource 来获取相同的图像资源,一个返回位图,而另一个返回 null。这两
我正在尝试从文件夹/drawable 中获取图像,但当 api > 19 时我收到 null。有人知道问题出在哪里吗? 我使用的所有图像都是矢量。 dog.setImagen(BitmapFactor
我想得到 image在我的 bitmap像这样: bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bug); 但这显示
我尝试在我的 Activity 中使用类 BitmapFactory 中的 decodeResource 方法,如下所示: Bitmap image = new BitmapFactory.decod
我已经检查了所有其他类似的问题,但没有人帮助我。这是我获取位图的代码: public class HachureView extends View { //... @Override
打电话是不是不好的做法 getResources().getDrawable() 或 BitmapFactory.decodeResource() 来自 Android 上的 UI 线程?我只是想知道
我想知道 decodeResource (Resources res, int id, BitmapFactory.Options opts) 是否考虑了 drawable-ldpi、mdpi、hdp
在我当前的 android 项目中,我从 xml 资源创建了两个位图。每次我使用 xml 位图作为 Bitmap.decodeResources() 的资源构建我的项目时,当我尝试访问位图时,我都会遇
我是一名优秀的程序员,十分优秀!