Image 加载图像

来源:互联网 发布:专业手机视频数据恢复 编辑:程序博客网 时间:2024/04/29 21:19
Image类使用静态方法createImage加载图像,如:Imagezhaoyun=Image.createImage("/zhaoyun.png");
此处需要注意的是图像文件的路径。
项目的文件目录如下:
HelloJAVAME/
.......... src/
             com/
             wushi/
                  Hello.java
...........res/
             zhaoyun.png
在此目录的组织下,图片处于资源目录RES下,所以加载图片时用绝对路径的情况下是“/zhaoyun.png”,此处一定要加斜杠。
类似的情况,如果res下面有多个目录, 如 res/beauty/zhaoyun.png,则加载路径为”/beauty/zhaoyun.png“

----------------------摘录一段document

Application Resource Files

Application resource files are accessed usinggetResourceAsStream(String name) injava.lang.Class . In the MIDP specification,getResourceAsStream is used to allow resource files tobe retrieved from the MIDlet Suite's JAR file.

Resource names refer to the contents of the MIDlet Suite JARfile. Absolute pathnames, beginning with "/" are fully qualifiedfile names within the jar file.

Relative pathnames, not beginning with "/" are relative to theclass upon which getResourceAsStream is called.Relative names are converted to absolute by prepending a "/"followed by the fully qualified package with "." charactersconverted to "/" and a separator of "/". The resulting string isreduced to canonical form by applying as many times as possible thefollowing:

  • All occurences of "/./" are replaced with "/".
  • All occurences of "/segment/../" are replaced with "/" wheresegment does not contain "/".

The canonical resource name is the absolute pathname of theresource within the JAR.

In no case can the path extend outside the JAR file, andresources outside the JAR file MUST NOT be accessible. For example,using "../../" does NOT point outside the JAR file. If there areany remaining "." or ".." characters they are treated literally inlocating the resource. No resource can exist with that name sonull is returned fromClass.getResourceAsStream. Also, devices MUST NOTallow classfiles to be read from the JAR file as resources, but allother files MUST be accessible.



               

0 0
原创粉丝点击