gpt4 book ai didi

blackberry - 我如何从黑莓的图库中获取图像?

转载 作者:行者123 更新时间:2023-12-03 21:05:55 26 4
gpt4 key购买 nike

我正在使用具有照片功能的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com