我使用异步任务在视图上绘制位图,但它什么也没画!
这是异步任务代码
class BitmapWorker extends AsyncTask<String, Void, Void>
{
private Canvas canvas;
private Rect rcText;
private Paint paint;
private Options options;
private Options opt;
public BitmapWorker(Canvas canvas,Rect rcText,Paint paint)
{
this.canvas = canvas;
this.rcText = rcText;//the bitmap must draw on it's rect
this.paint = paint;
}
@Override
protected Void doInBackground(String... params)
{
options = new Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(m_AttachSource, options);
opt = new Options();
opt.inPurgeable = true;
opt.inSampleSize = calculateInSampleSize(options, INSAMPLESIZE_THIMBPIC_WIDTH, INSAMPLESIZE_THIMBPIC_HEIGHT);
LoadThumbPic(m_AttachSource, opt);
return null;
}
@Override
protected void onPostExecute(Void result)
{
super.onPostExecute(result);
Boolean hasBitmap = false;
while(!hasBitmap)
{
if(m_PictureMessageTumbPic.get() != null)
{
canvas.drawBitmap(m_PictureMessageTumbPic.get(), null, rcText, paint);
hasBitmap = true;
}
else
{
Options opt = new Options();
opt.inPurgeable = true;
opt.inSampleSize = calculateInSampleSize(options, INSAMPLESIZE_THIMBPIC_WIDTH, INSAMPLESIZE_THIMBPIC_HEIGHT);
LoadThumbPic(m_AttachSource, opt);
canvas.drawBitmap(m_PictureMessageTumbPic.get(), null, rcText, paint);
hasBitmap = true;
}
}
}
}
tnx 4 高级版