作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用具有照片功能的 Blackberry 开发应用程序。我想从图库中获取照片并将其显示在位图字段上。有没有人对此有想法,请发给我。提前谢谢..
最佳答案
FilePicker is the main concept; I am taking the SDCard images. So, before testing set the sdcard in simulator;
试试这个示例代码:
import net.rim.device.api.ui.picker.FilePicker;
import net.rim.device.api.ui.picker.FilePicker.Listener;
public class FilePickerScreen extends MainScreen implements FieldChangeListener
{
Bitmap bitmap;
ButtonField click;
BitmapField bitmapField;
public FilePickerScreen()
{
setTitle("FilePicker Screen");
createGUI();
}
private void createGUI()
{
add(new LabelField("Click to select the image", Field.FIELD_HCENTER));
click=new ButtonField("Click");
click.setChangeListener(this);
add(click);
bitmapField=new BitmapField();
add(bitmapField);
}
private Bitmap getTheImage(String url)
{
Bitmap bitmap=null,scaleBitmap=null;
InputStream inputStream=null;
FileConnection fileConnection=null;
try
{
fileConnection=(FileConnection) Connector.open(url);
inputStream=fileConnection.openInputStream();
byte[] data=new byte[(int)fileConnection.fileSize()];
data=IOUtilities.streamToBytes(inputStream);
inputStream.close();
fileConnection.close();
bitmap=Bitmap.createBitmapFromBytes(data,0,data.length,1);
//You can return this bitmap otherwise, after this you can scale it according to your requirement; like...
scaleBitmap=new Bitmap(150, 150);
bitmap.scaleInto(scaleBitmap, Bitmap.FILTER_LANCZOS);
}
catch (Exception e)
{
try
{
if(inputStream!=null)
{
inputStream.close();
}
if(fileConnection!=null)
{
fileConnection.close();
}
}
catch (Exception exp)
{
}
scaleBitmap=Bitmap.getBitmapResource("noimage.png");//Your known Image;
}
return scaleBitmap;
}
public void fieldChanged(Field field, int context)
{
if(field==click)
{
try
{
FilePicker filePicker;
filePicker=FilePicker.getInstance();
filePicker.setPath("file:///SDCard/BlackBerry/pictures/");
filePicker.setListener(new Listener()
{
public void selectionDone(String path)
{
bitmapField.setBitmap(getTheImage(path));
}
});
filePicker.show();//it show what ever you select.
}
catch (Exception e)
{
StartUp.exceptionHandling(e.getMessage());
}
}
}
}
我想这可能是你的需求;
关于blackberry - 我如何从黑莓的图库中获取图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8982893/
我是一名优秀的程序员,十分优秀!