本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7586473
建立时间:2006年5月29日




[算法]Nokia中图片short数组转换算法
软件技术,  电脑与网络

lhwork 发表于 2006/6/2 14:23:03

import java.awt.Image;import java.awt.image.PixelGrabber; import javax.imageio.ImageIO; public class ImageConverter {  /**  * @param args  */ public static void main(String[] args) {  // TODO Auto-generated method stub    short [] pixels = parseImage("/ef1s.png"); }  static class Rect{  public int _width;    public int _height;    public int [] _pixels;    public Rect(int w, int h){   _width = w;   _height = h;   _pixels = new int[w * h];     } }  public static short []  parseImage(String s){    Image image = null;  try{  image = ImageIO.read("".getClass().getResourceAsStream(s));  }  catch(Exception e){     }  if(image == null)   return null;            int w = image.getWidth(null);        int h = image.getHeight(null);        if(w < 0 || h < 0)            return null;                Rect rect = new Rect(w, h);        PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, w, h, rect._pixels, 0, w);        try        {            if(!pixelgrabber.grabPixels())                return null;        }        catch(InterruptedException interruptedexception1)        {            return null;        }                short [] results = new short[w * h];                int idx = 0;        int idy = 0;                int format = 4444;                for(int l2 = 0; l2 < h; l2++)        {            if(format == 4444)            {                for(int i3 = 0; i3 < w; i3++)                {                    int k3 = rect._pixels[idx++] >> 4 & 0xf0f0f0f;                    k3 = (k3 >> 4 | k3) & 0xff00ff;                    k3 = k3 >> 8 | k3;                    k3 &= 65535;                    results[idy++] = (short)k3;                }             } else            if(format == 565)            {                for(int j3 = 0; j3 < w; j3++)                {                    int l3 = rect._pixels[idx++];                    l3 = l3 >> 3 & 0x1f | l3 >> 5 & 0x7e0 | l3 >> 8 & 0xf800;                    results[idy++] = (short)l3;                }             } else            {                throw new IllegalArgumentException();            }            //i2 += l1 - k;            //idy += rect._pixels.length - k;        }    return results; } }


阅读全文(4955) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.125 second(s), page refreshed 144763912 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号