当前位置: 代码迷 >> J2ME >> 急图片可以open,但是不能createImage解决方法
  详细解决方案

急图片可以open,但是不能createImage解决方法

热度:8569   发布时间:2013-02-25 21:33:44.0
急啊!图片可以open,但是不能createImage
源码如下:
  FileConnection fc =
  (FileConnection)Connector.open("file:///C:/Images/a.jpg");

  if (!fc.exists()) {
  throw new IOException("File does not exists");
  } else 
  {
 
  displayForm.append("file:///C:/Images/a.jpg 可以打开");
  display.setCurrent(displayForm);
  }
   
 
  try {
  javax.microedition.lcdui.Image inimg = javax.microedition.lcdui.Image.createImage("file:///C:/Images/a.jpg");  

} catch (IOException ex) {
ex.printStackTrace();//会抛出这个异常
 
}

------解决方案--------------------------------------------------------
仔细看下API就可以知道,createImage的几种重载方法,参数类型为字符串的表示

"创建一个数据从指定的资源获得的不可改变的解码图像。 name参数是一个Class.getResourceAsStream(名称)定义的资源名称。解决资源名称的规则是被定义在java.lang包中的文件的部分的应用程序资源文件。"
------解决方案--------------------------------------------------------
先加载这个文件 得到byte 或者stream 然后再用这个作为参数生成图片 试试
  相关解决方案