Android(安卓)利用setpixels设置单色位图
1.创建纯白色位图
Bitmap bm1 = Bitmap.createBitmap(picw, pich, Bitmap.Config.ARGB_8888); int[] pix = new int[picw * pich]; for (int y = 0; y < pich; y++) for (int x = 0; x < picw; x++) { int index = y * picw + x; int r = ((pix[index] >> 16) & 0xff)|0xff; int g = ((pix[index] >> 8) & 0xff)|0xff; int b =( pix[index] & 0xff)|0xff; pix[index] = 0xff000000 | (r << 16) | (g << 8) | b; // pix[index] = 0xff000000; } bm1.setPixels(pix, 0, picw, 0, 0, picw, pich); BitmapDrawable bmp11=new BitmapDrawable(bm1); iv.setImageBitmap(bm1);
2.创建纯黑色位图
Bitmap bm1 = Bitmap.createBitmap(picw, pich, Bitmap.Config.ARGB_8888); int[] pix = new int[picw * pich]; for (int y = 0; y < pich; y++) for (int x = 0; x < picw; x++) { int index = y * picw + x; //int r = ((pix[index] >> 16) & 0xff)|0xff; //int g = ((pix[index] >> 8) & 0xff)|0xff; //int b =( pix[index] & 0xff)|0xff; // pix[index] = 0xff000000 | (r << 16) | (g << 8) | b; pix[index] = 0xff000000; } bm1.setPixels(pix, 0, picw, 0, 0, picw, pich); BitmapDrawable bmp11=new BitmapDrawable(bm1); iv.setImageBitmap(bm1);
更多相关文章
- Android绘制进阶之五:位图的处理
- Android(安卓)Bitmap相关
- android4.4 安装微信7.0.6版本底部显示黑色的问题
- android .9图讲解
- Android制作 9-Patch图片(可调整大小的位图)
- Android(安卓)SVG和Lottie库播放动画(Json)
- android 图片占用内存与什么有关
- JNI下使用AndroidBitmap_lockPixels修改位图为黑白照片
- android 中遇到的Ui问题