qq_27665781
2015-07-28 01:42
采纳率: 100%
浏览 3.1k

android canvas保存为图片在手机中打开是一片黑色

//保存
public void save()
{

    File sd=Environment.getExternalStorageDirectory();   
    String path=sd.getPath()+"/paint";   
    File file=new File(path); 
    file.mkdir();    
    Bitmap  bm  =  Bitmap.createBitmap(480, 800, Config.ARGB_8888);
    Canvas  canvas  =  new  Canvas(bm); 
    Paint  p  =  new  Paint();
    canvas.drawRect(50,  50,  200,  200,  p); 
    canvas.save(Canvas.ALL_SAVE_FLAG  ); 
    canvas.restore();

    String fileName = path+"19961234.jpg";  
    FileOutputStream  fos  =  null; 
    try  {   
        fos  =  new  FileOutputStream(fileName); 
        bm.compress(Bitmap.CompressFormat.PNG,  100,  fos);
        fos.flush();
        fos.close();    
    } 
    catch  (FileNotFoundException  e) 
    {  

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }  

}

1条回答 默认 最新

相关推荐 更多相似问题