参考资料:http://blog.sina.com.cn/s/blog_4b650d650100nq9g.html

http://www.chalayout.com/Article/%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1/200603/20060301114940.html


标准的16色的调色板如下:

颜色RGB
-----------------------
0000
100170
201700
30170170
417000
51700170
61701700
7170170170
8858585
98585255
108525585
1185255255
122558585
1325585255
1425525585

15255255255

问题背景:输入参数格式为一串byte流:heigth,width,颜色像素数据。颜色像素数据是每4bit一个像素,16色。

运行结果:如下的一小块彩方块。


源码如下:

package android.test.showpic;


import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.graphics.Bitmap.Config;
public class ShowpicActivity extends Activity {
/** Called when the activity is first created. */
ImageView img;
final String tag="mayShowPic";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findviews();
int[] colorindex=new int[]{
0xff000000,0xff0000aa,0xff00aa00,0xff00aaaa,0xffaa0000,
0xffaa00aa,0xffaaaa00,0xffaaaaaa,0xff555555,0xff5555ff,
0xff55ff55,0xff55ffff,0xffff5555,0xffff55ff,0xffffff55,
0xffffffff
};
int h=23,w=33,i;
int lenold=((h*w)+1)/2,lennew=h*w;
byte[] colorold=new byte[lenold];
for(i=0;i<lenold;i++)
{
colorold[i]=(byte)(i%256);
}
int[] colornew=new int[lennew];
int hi,lo;
for(i=0;i<lennew-2;)
{

hi=((int)colorold[i>>1]&0xf0)>>4;
lo=((int)colorold[i>>1]&0x0f);
Log.i(tag, "i,colorold,hi,lo"+i+","+colorold[i>>1]+","+hi+","+lo);
colornew[i]=colorindex[hi];
colornew[i+1]=colorindex[lo];
i=i+2;
}
hi=((int)colorold[lenold-1]&0xf0)>>4;
lo=((int)colorold[lenold-1]&0x0f);
Log.i(tag, ""+colorold[lenold-1]+","+hi+","+lo);
colornew[i]=colorindex[hi];
if(i+1<lennew)
colornew[i+1]=colorindex[lo];
i=i+2;
Log.i(tag, "aa");

Bitmap b = Bitmap.createBitmap(colornew,w, h,Bitmap.Config. ARGB_8888 );
Log.i(tag, "bb");
ImageView img23 = new ImageView(ShowpicActivity.this);
Log.i(tag, "anew");
img.setImageBitmap(b);
Log.i(tag, "bb2");

}
void findviews()
{
img=(ImageView)findViewById(R.id.img);
}

}




更多相关文章

  1. 一句话锁定MySQL数据占用元凶
  2. Context和SQLiteOpenHelper创建数据库
  3. Android(安卓)sqlite3插入速度优化方案
  4. Button 或 ImageButton 背景设为 透明 或半透明
  5. Android数据的四种存储方式之SQLite数据库
  6. Android(安卓)动态修改SVG数据
  7. Android异步任务处理之AsyncTaskLoader的使用
  8. Android(安卓)Sqlite数据库详解
  9. Android(安卓)Camera 二 JNI JAVA和C/CPP图像数据传输流程分析

随机推荐

  1. Android----单元测试 (1)
  2. [HTML5]android远程调试工具chrome
  3. Android学习笔记,Notification通知事件
  4. Android精华笔记
  5. android中自定义的控件,使用自定义属性at
  6. Android(安卓)混淆代码总结 和 Android(
  7. Android:SQLiteOpenHelper,SqliteDatabas
  8. android studio 打包报 MissingTranslati
  9. Android(安卓)自定义控件属性,自定义Dialo
  10. Android--stetho使用介绍