我只在安卓8.0的华硕ZenFone 3 (ZE552KL) (ASUS_Z012D)上看到这个错误
java.lang.NullPointerException: at android.graphics.Bitmap.createScaledBitmap (Bitmap.java:714)
File imageFile = new File(
Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+imageBlocksFolder, "img122.png");
if(imageFile.exists()){
bitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(imageFile.getAbsolutePath()), 50, 50, false);
paint.setColor(cor);
canvas.drawBitmap(bitmap, 100, 100, paint);
}有没有人遇到过同样的问题?
发布于 2018-07-04 13:25:29
试试这个:
public void showImage(string filename)
{
analytics.LocalLog ("ShowImage");
if (!string.IsNullOrEmpty (filename))
{
analytics.LocalLog ("Showing File: " + filename);
BitmapFactory.Options options = new BitmapFactory.Options ();
options.InSampleSize = 4;
try {
using(var fs = new System.IO.FileStream(filename, System.IO.FileMode.Open))
{
using(Bitmap bitmap = BitmapFactory.DecodeStream (fs, null, options))
//using(Bitmap bitmap = BitmapFactory.DecodeFile (filename, options))
{
if(bitmap != null)
{
try {
momentImage.SetImageBitmap (bitmap);
momentImage.Visibility = ViewStates.Visible;
}catch{
GC.Collect ();
}
}else{
Utilities.DisplayMessage ("Could not load Image", "Please use a locally stored image, and check permissions", this);
}
}
fs.Close ();
}
}catch{
Utilities.DisplayMessage ("Could not load Image", "Access denied to image, sorry", this);
}
}else{
analytics.LocalLog ("No Filename passed");
}
}https://stackoverflow.com/questions/51163986
复制相似问题