这是我显示图像的地方 它是一个放在imageview中的画布,然后使用asynctask绘制 我希望你能帮助我,请解释我的代码中的错误。 但不断收到此错误:
这是我的代码:
private Bitmap mImageone, mImagetwo, mImagethree, mImagefour;
private Bitmap mBackground;
private BitmapDrawable mBitmapDrawable;
private static String mTempDir;
private FileOutputStream mFileOutputStream = null;
private Canvas mCanvas;
public class ImageAsyctask extends AsyncTask<Bitmap, Void, Bitmap> {
private final WeakReference<Bitmap> imageViewReference;
public ImageAsyctask(Bitmap bitmap) {
imageViewReference = new WeakReference<Bitmap>(bitmap);
}
@Override
protected Bitmap doInBackground(Bitmap... params) {
// TODO Auto-generated method stub
mTempDir = Environment.getExternalStorageDirectory()
+ "/MyCameraBooth/Photo/";
File mTempFile = new File(mTempDir);
if (!mTempFile.exists()) {
mTempFile.mkdirs();
}
mBackground = Bitmap
.createBitmap(1800, 1200, Bitmap.Config.RGB_565);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
f = new File(AppConstant.filepathone);
Bitmap mImageone = decodeFile(f);
g = new File(AppConstant.filepathtwo);
Bitmap mImagetwo = decodeFile(g);
h = new File(AppConstant.filepaththree);
Bitmap mImagethree = decodeFile(h);
i = new File(AppConstant.filepathfour);
Bitmap mImagefour = decodeFile(i);
j = new File(sharedpreferences.getString("positionImage",
"positionImage"));
Bitmap mbGG = decodeFile(j);
Bitmap mBack = Bitmap.createScaledBitmap(mbGG, 1800, 1200, true);
Bitmap mImaget = Bitmap.createScaledBitmap(mImagetwo, 515, 360,
true);
Bitmap mImageth = Bitmap.createScaledBitmap(mImagethree, 515, 360,
true);
Bitmap mImagef = Bitmap.createScaledBitmap(mImagefour, 515, 360,
true);
Bitmap mImageo = Bitmap.createScaledBitmap(mImageone, 1085, 635,
true);
mCanvas = new Canvas(mBackground);
mCanvas.drawARGB(255, 150, 150, 10);
if (sharedpreferences.getString("positionImage", "positionImage")
.contains("FrameA")) {
mCanvas.drawBitmap(mBack, 0, 0, null);
mCanvas.drawBitmap(mImaget, 75, 75, null);
mCanvas.drawBitmap(mImageo, 75, 490, null);
mCanvas.drawBitmap(mImageth, 645, 75, null);
mCanvas.drawBitmap(mImagef, 1215, 75, null);
} else if (sharedpreferences.getString("positionImage",
"positionImage").contains("FrameB")) {
mCanvas.drawBitmap(mBack, 0, 0, null);
mCanvas.drawBitmap(mImaget, 75, 75, null);
mCanvas.drawBitmap(mImageo, 645, 490, null);
mCanvas.drawBitmap(mImageth, 645, 75, null);
mCanvas.drawBitmap(mImagef, 1215, 75, null);
} else if (sharedpreferences.getString("positionImage",
"positionImage").contains("FrameC")) {
mCanvas.drawBitmap(mBack, 0, 0, null);
mCanvas.drawBitmap(mImaget, 75, 765, null);
mCanvas.drawBitmap(mImageo, 645, 75, null);
mCanvas.drawBitmap(mImageth, 645, 765, null);
mCanvas.drawBitmap(mImagef, 1215, 765, null);
} else if (sharedpreferences.getString("positionImage",
"positionImage").contains("FrameD")) {
mCanvas.drawBitmap(mBack, 0, 0, null);
mCanvas.drawBitmap(mImaget, 75, 765, null);
mCanvas.drawBitmap(mImageo, 75, 75, null);
mCanvas.drawBitmap(mImageth, 645, 765, null);
mCanvas.drawBitmap(mImagef, 1215, 765, null);
}
Log.e(sharedpreferences.getString("positionImage", "positionImage"),
sharedpreferences.getString("positionImage",
"positionImage"));
return mBackground;
}
@Override
protected void onPostExecute(Bitmap result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
try {
String friendlydate = DateFormat.getTimeInstance(
DateFormat.MEDIUM).format(new Date());
friendlydate = friendlydate.replace(':', '_');
String filename = friendlydate + ".jpg";
mBitmapDrawable = new BitmapDrawable(mBackground);
Bitmap mNewSaving = mBitmapDrawable.getBitmap();
String FtoSave = mTempDir + filename;
File mFile = new File(FtoSave);
mFileOutputStream = new FileOutputStream(mFile);
mNewSaving.compress(Bitmap.CompressFormat.PNG, 100,
mFileOutputStream);
imVCature_pic.setImageBitmap(decodeSampledBitmapFromFile(
mFile.getAbsolutePath(), 150, 150));
f.delete();
i.delete();
g.delete();
h.delete();
// imVCature_pic.setImageBitmap(decodeFile(mFile));
mFileOutputStream.flush();
mFileOutputStream.close();
mFileOutputStream = null;
} catch (FileNotFoundException e) {
Log.e(AppConstant.TAG,
"FileNotFoundExceptionError " + e.toString());
} catch (IOException e) {
Log.e(AppConstant.TAG, "IOExceptionError " + e.toString());
}
Log.i(AppConstant.TAG, "Image Created");
}
}
并运行它: 新的ImageAsyctask(mBackground).execute();