2011-04-14 2 views

Répondre

159

Ceci est probablement plus simple que vous pensez:

int w = WIDTH_PX, h = HEIGHT_PX; 

Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types 
Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap 
Canvas canvas = new Canvas(bmp); 

// ready to draw on that bitmap through that canvas 

Voici une série de tutoriel, je l'ai trouvé sur le sujet: Drawing with Canvas Series

+0

Si je crée cela dans une classe séparée, comment puis-je référencer le bitmap dans une autre classe. Par exemple: Bitmap text = BitmapFactory.decodeResource (mContext.getResources(), Que mettre ici?); J'ai besoin d'un textView dans un fond d'écran opengl live. Merci d'avance –

+0

Salut @bigstones Je suis votre code pour la création de bitmap dans onSizeChanged() lorsque je crée bitmap Je reçois OutOfMemoryError s'il vous plaît voir ce http://stackoverflow.com/questions/24303759/outofmemoryerror-when-creatingbitmp – user123456

+0

Comment cela peut-il être fait dans un autre thread tout en utilisant SurfaceView? –

-3

Ne pas utiliser Bitmap.Config.ARGB_8888

Utilisez plutôt int w = WIDTH_PX, h = HEIGHT_PX;

Bitmap.Config conf = Bitmap.Config.ARGB_4444; // see other conf types 
Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap 
Canvas canvas = new Canvas(bmp); 

// ready to draw on that bitmap through that canvas 

ARGB_8888 peut vous poser des questions OutOfMemory lorsqu'ils traitent avec plus de bitmaps ou de grandes bitmaps. Ou mieux encore, essayez d'éviter d'utiliser l'option ARGB elle-même.

+0

ARGB_8888 est la valeur par défaut dans le code source Android Bitmap –

+0

Bonjour @userI crée bitmap dans onSizeChanged() avec RGB_565 mais quand je crée bitmap je reçois OutOfMemoryError.S'il vous plaît voir ce http://stackoverflow.com/questions/24303759/ outofmemoryerror-when-creatingbitmp – user123456

+9

ARGB_4444 est maintenant obsolète (http://developer.android.com/reference/android/graphics/Bitmap.Config.html#ARGB_4444) – Allen