2014-01-22 4 views
0

캔버스 객체를 onDraw() 메소드에 저장하여 비트 맵으로 저장하려고합니다. 같은 답변을 제시하지 마십시오 "view.getDrawingCache을 (참)".I "는 비트 맵으로 저장 될 나는 캔버스의 onDraw에서 객체() 메소드를 저장하려면"안드로이드 캔버스를 비트 맵으로 저장

+0

비트 맵에 직접 캔버스를 저장할 - 그건 나에게별로 의미가 없어. 무엇을 성취하려고합니까? – CommonsWare

+0

가능한 중복 : http://stackoverflow.com/questions/7442610/how-to-save-the-image-from-canvas-code-in-android-application – vbo

+0

getDrawingCache()의 문제점은 무엇입니까? 뷰의 가시적 인 자산을 잡을 필요가있을 때 저를 위해 잘 작동합니다. 그러나 만약 당신이 정말로 전체 캔버스를 원한다면 아래의 나의 대답을보십시오 – Martin

답변

1
// first create a mutable bitmap - you determine the size 
bkg = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888); 

// create a canvas with that empty bitmap 
Canvas c = new Canvas(bkg); 

// do whatever drawing methoods you need....I did a circle 
c.drawColor(mContext.getResources().getColor(R.color.off_white)); 
p.setColor(pixel); 
c.drawCircle(width/2, width/2, width/2, p); 

// then pull off the entire canvas as a bitmapdrawable (or bitmap, if you perfer) 
return new BitmapDrawable(mContext.getResources(), bkg); 
관련 문제