Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.icon2);//返回的估计是一个immutalbe的bitmap;所以不能用setpixels而Bitmap b = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888);//返回的是一个mutable的bitmap,可以用setpixels
从Bitmap.createBitmap可以看到有的返回immutable bitmap,有的返回 mutable bitmap1。static Bitmap createBitmap(Bitmap src) Returns an immutable bitmap from the source bitmap.2.static Bitmap createBitmap(int[] colors, int width, int height, Bitmap.Config config) Returns a immutable bitmap with the specified width and height,3.static Bitmap createBitmap(int[] colors, int offset, int stride, int width, int height, Bitmap.Config config) Returns a immutable bitmap with the specified width and height, 4.static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter) Returns an immutable bitmap from subset of the source bitmap, 5.static Bitmap createBitmap(int width, int height, Bitmap.Config config) Returns a mutable bitmap with the specified width and height.6.static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height) Returns an immutable bitmap from the specified subset of the source bitmap.
Bitmap bitmap2=Bitmap.createBitmap(w, h, Config.ARGB_8888);
然后使用
bitmap2.setPixels(pixels, 0, bitmap2.getWidth(), 0, 0, bitmap2.getWidth(),
bitmap2.getHeight());// 取出
显示
iv.setImageBitmap(bitmap2);// 显示
就可以了,我分析会不会是内存处理上的问题。
Returns an immutable bitmap from the source bitmap.2.static Bitmap createBitmap(int[] colors, int width, int height, Bitmap.Config config)
Returns a immutable bitmap with the specified width and height,3.static Bitmap createBitmap(int[] colors, int offset, int stride, int width, int height, Bitmap.Config config)
Returns a immutable bitmap with the specified width and height, 4.static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)
Returns an immutable bitmap from subset of the source bitmap, 5.static Bitmap createBitmap(int width, int height, Bitmap.Config config)
Returns a mutable bitmap with the specified width and height.6.static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height)
Returns an immutable bitmap from the specified subset of the source bitmap.