日期:2014-05-18 浏览次数:20764 次
public byte[] image2Bytes(String imagePath) throws Exception {
BufferedImage bu=ImageIO.read(new File(imagePath));
ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
try {
ImageIO.write(bu, "bmp", imageStream);
} catch (Exception e) {
e.printStackTrace();
}
imageStream.flush();
return imageStream.toByteArray();
}
byte[] imgBuff = hello.image2Bytes("a.bmp");
int nImageSize = imgBuff.length;
for(int i=0;i<10;i++){
if(imgBuff[i]!=-1){
System.out.println(i+":"+imgBuff[i]);
}
}
FILE *fpImageFile;
long lBegin, lEnd;
unsigned char *pImage;
int nImageSize;
fpImageFile = fopen("a.bmp", "rb");//读取图片
lBegin = ftell(fpImageFile);
fseek(fpImageFile, 0L, SEEK_END);
lEnd = ftell(fpImageFile);
nImageSize = int(lEnd - lBegin);
pImage = new unsigned char[nImageSize];
fseek(fpImageFile, 0L, SEEK_SET);
fread(pImage, sizeof(unsigned char), nImageSize, fpImageFile);
fclose(fpImageFile);
int k=0;
for(k=0;k<10;k++){
printf("%d : %d\n",k,pImage[k]);
}