2010-04-28 41 views
4

我使用以下代码从手机或SDCard中检索图像,并将该图像用于我的ListField。它给出了输出,但它需要很长时间才能生成屏幕。如何解决这个问题呢 ??谁能帮我??提前致谢!!!Blackberry - ListField与来自文件系统的图像

String text = fileholder.getFileName(); 
try{ 
String path="file:///"+fileholder.getPath()+text; 
//path=”file:///SDCard/BlackBerry/pictures/image.bmp” 

InputStream inputStream = null; 
//Get File Connection 
FileConnection fileConnection = (FileConnection) Connector.open(path); 

inputStream = fileConnection.openInputStream(); 

ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
int j = 0; 
while((j=inputStream.read()) != -1) { 
baos.write(j); 
} 
byte data[] = baos.toByteArray();     
inputStream.close(); 
fileConnection.close(); 

//Encode and Resize image 
EncodedImage eImage = EncodedImage.createEncodedImage(data,0,data.length); 
int scaleFactorX = Fixed32.div(Fixed32.toFP(eImage.getWidth()), 
     Fixed32.toFP(180)); 
int scaleFactorY = Fixed32.div(Fixed32.toFP(eImage.getHeight()), 
     Fixed32.toFP(180)); 
eImage=eImage.scaleImage32(scaleFactorX, scaleFactorY); 
Bitmap bitmapImage = eImage.getBitmap(); 
graphics.drawBitmap(0, y+1, 40, 40,bitmapImage, 0, 0); 
graphics.drawText(text, 25, y,0,width); 
} 
catch(Exception e){} 

回答

6

你应该读一次文件(在应用程序启动或屏幕上打开之前,也许把进度对话框出现),把图像阵列和涂料使用这个数组。

相关问题