2011-01-12 57 views

回答

1

如果你的意思是你需要設置模擬器路徑爲SD卡,
這裏是你如何在Eclipse中做到這一點的步驟:
1-運行模擬器
2 - 選擇「Smulate」
3-選擇「更改SD卡」
4-按「添加目錄」
5瀏覽並按下「OK」


但如果你需要的代碼在這裏開設的圖片,它是:

FileConnecti onApplication.java:

public class FileConnectionApplication extends UiApplication { 
    public FileConnectionApplication() { 
     FileConnectionScreen screen = new FileConnectionScreen(); 
     pushScreen(screen); 
    } 

    public static void main(String[] args) { 
     FileConnectionApplication app = new FileConnectionApplication(); 
     app.enterEventDispatcher(); 
    } 
} 


FileConnectionScreen.java:

public class FileConnectionScreen extends MainScreen { 
    private ObjectListField fileList; 
    private String currentPath = "file:///"; 

    public FileConnectionScreen() { 
     setTitle("FileConnection"); 
     fileList = new ObjectListField(); 
     fileList.set(new String[] { "store/", "SDCard/" }); 
     add(fileList); 
    } 

    protected void makeMenu(Menu menu, int instance) { 
     super.makeMenu(menu, instance); 
     menu.add(new MenuItem("Select", 10, 10) { 
      public void run() { 
       loadFile(); 
      } 
     }); 
    } 

    private void loadFile() { 
     currentPath += fileList.get(fileList, fileList.getSelectedIndex()); 
     try { 
      FileConnection fileConnection = (FileConnection) Connector.open(currentPath); 
      if (fileConnection.isDirectory()) { 
       Enumeration directoryEnumerator = fileConnection.list(); 
       Vector contentVector = new Vector(); 
       while (directoryEnumerator.hasMoreElements()) 
         contentVector.addElement(directoryEnumerator.nextElement()); 
       String[] directoryContents = new String[contentVector.size()]; 
       contentVector.copyInto(directoryContents); 
       fileList.set(directoryContents); 
      } else if (currentPath.toLowerCase().endsWith(".jpg") || currentPath.toLowerCase().endsWith(".png")) { 
       InputStream inputStream = fileConnection.openInputStream(); 
       byte[] imageBytes = new byte[(int) fileConnection.fileSize()]; 
       inputStream.read(imageBytes); 
       inputStream.close(); 
       EncodedImage eimg = EncodedImage.createEncodedImage(imageBytes, 0, imageBytes.length); 
       UiApplication.getUiApplication().pushScreen(new ImageDisplayScreen(eimg)); 
      } 
     } catch (IOException ex) { 
     } 
    } 
} 


ImageDisplayScreen.java:

public class ImageDisplayScreen extends MainScreen { 
    public ImageDisplayScreen(EncodedImage image) { 
     int displayWidth = Fixed32.toFP(Display.getWidth()); 
     int imageWidth = Fixed32.toFP(image.getWidth()); 
     int scalingFactor = Fixed32.div(imageWidth, displayWidth); 
     EncodedImage scaledImage = image.scaleImage32(scalingFactor, scalingFactor); 
     BitmapField bitmapField = new BitmapField(); 
     bitmapField.setImage(scaledImage); 
     add(bitmapField); 
    } 
} 
3
1.create folder and give name-SDCard. 
2.in the simulator click on-simulate. 
3.choose change SD Card. 
4.select your folder SDCard. 
5.click on close. 

now create file connection 
FileConnection fileConnection = (FileConnection)Connector.open(("file:///SDCard/images/a.png") 
,Connector.READ, true); 
InputStream inputStream = fileConnection.openInputStream(); 
byte[] imageBytes = new byte[(int) fileConnection.fileSize()]; 
inputStream.read(imageBytes); 
inputStream.close(); 
EncodedImage eimg = EncodedImage.createEncodedImage(imageBytes, 0, imageBytes.length); 


now u can use this encoded image any where. 
相關問題