J2ME 判断图片的格式
2009-03-10 18:08
232 查看
public String GetFormat(String path)
{
String PicFormat = "UNKNOWN";
try{
InputStream is = this.getClass().getResourceAsStream(path);
byte[] data = new byte[128];
ByteArrayOutputStream os = new ByteArrayOutputStream();
while(is.read(data)!=-1)
{
os.write(data);
}
byte [] buffer = os.toByteArray();
StringBuffer sb = new StringBuffer();
int tmp = 0;
for(int i = 0; i < 16;i++)
{
tmp = buffer[i];
if(tmp >= 32 && tmp <= 127)
{
sb.append((char)tmp);
}
}
String head = sb.toString();
System.out.println(head);
if(head.toUpperCase().startsWith("GIF"))
{
PicFormat = "GIF";
}
else if(head.toUpperCase().startsWith("JFIF"))
{
PicFormat = "JPG";
}
else if(head.toUpperCase().startsWith("PNG"))
{
PicFormat = "PNG";
}
else if(head.toUpperCase().startsWith("BM"))
{
PicFormat = "BMP";
}
}
catch(IOException ioe){ioe.printStackTrace();}
return PicFormat;
}
{
String PicFormat = "UNKNOWN";
try{
InputStream is = this.getClass().getResourceAsStream(path);
byte[] data = new byte[128];
ByteArrayOutputStream os = new ByteArrayOutputStream();
while(is.read(data)!=-1)
{
os.write(data);
}
byte [] buffer = os.toByteArray();
StringBuffer sb = new StringBuffer();
int tmp = 0;
for(int i = 0; i < 16;i++)
{
tmp = buffer[i];
if(tmp >= 32 && tmp <= 127)
{
sb.append((char)tmp);
}
}
String head = sb.toString();
System.out.println(head);
if(head.toUpperCase().startsWith("GIF"))
{
PicFormat = "GIF";
}
else if(head.toUpperCase().startsWith("JFIF"))
{
PicFormat = "JPG";
}
else if(head.toUpperCase().startsWith("PNG"))
{
PicFormat = "PNG";
}
else if(head.toUpperCase().startsWith("BM"))
{
PicFormat = "BMP";
}
}
catch(IOException ioe){ioe.printStackTrace();}
return PicFormat;
}
相关文章推荐
- PHP判断图片格式的7种方法
- iOS 压缩图片,判断图片格式
- PHP判断图片格式
- 基于asp.net + easyui框架,js实现上传图片之前判断图片格式,同时实现预览,兼容各种浏览器+下载
- c语言常见图片格式判断实例
- 校验出生日期,校验身份证格式,校验会员账户:9开头数字,校验手机号码是否合法,判断字符串中的url是否都是图片格式字符串,通过图片url读取图片并将图片转换成base64编码
- 基于asp.net + easyui框架,js实现上传图片之前判断图片格式,同时实现预览,兼容各种浏览器+下载
- JAVA正则表达式判断图片格式
- Struts2图片文件上传,判断图片格式和图片大小
- php判断上传文件是不是图片,如果是,返回图片格式
- 判断内存流中的图片格式
- ios判断图片格式类型
- 用HTML的File控件上传图片,用JS判断和限制图片格式、类型、尺寸
- js判断上传的图片格式
- java代码判断图片文件格式, 不是根据文件后缀来判断。
- 根据图片的URL地址判断图片的格式
- php判断图片的格式
- C# 判断图形文件(GIF,JPG,PNG)的图片格式的方法
- 用Delphi从内存流中判断图片格式
- 基于ASP.NET+easyUI框架实现图片上传功能(判断格式+即时浏览 )