Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
BlackBerry:从SD卡图像创建位图对象_Blackberry - Fatal编程技术网

BlackBerry:从SD卡图像创建位图对象

BlackBerry:从SD卡图像创建位图对象,blackberry,Blackberry,我们可以从SD卡图像文件路径创建位图对象吗 我已经编写了一个示例方法来创建它。这是正确的方法吗 公共位图创建位图(字符串文件路径){ 试一试{ //文件路径,例如。“file:///SDCard/test.jpg" FileConnection fc=(FileConnection)Connector.open(filepath); 字节[]响应数据=新字节[10000]; InputStream InputStream=fc.openDataInputStream(); 整数长度=0; Str

我们可以从SD卡图像文件路径创建
位图
对象吗

我已经编写了一个示例方法来创建它。这是正确的方法吗

公共位图创建位图(字符串文件路径){
试一试{
//文件路径,例如。“file:///SDCard/test.jpg"
FileConnection fc=(FileConnection)Connector.open(filepath);
字节[]响应数据=新字节[10000];
InputStream InputStream=fc.openDataInputStream();
整数长度=0;
StringBuffer rawResponse=新的StringBuffer();
而(-1!=(长度=inputStream.read(responseData))){
append(新字符串(responseData,0,长度));
}
byte[]dataArray=rawResponse.toString().getBytes();
位图位图=位图.createBitmapFromBytes(dataArray,0,dataArray.length,1);
//createEncodedImage(dataArray,0,dataArray.length);
返回位图;
}捕获(IOE异常){
返回null;
//TODO自动生成的捕捉块
//e.printStackTrace();
}
}

公共最终课程MyScreen扩展主屏幕{

Bitmap bit, bit1;

BitmapField bitf[] = new BitmapField[12];

FileConnection fc;

FlowFieldManager grid;

String[] imgpath = { "bharat.png", "fighter1.jpg", "fighter2.jpg",
        "fighter3.jpg", "fighter4.jpg", "fighter5.jpg", "fighter7.jpg",
        "fighter8.jpg", "fighter9.jpg", "fighter10.jpg", "fighter11.jpg",
        "fighter6.jpg" };
String compath = "file:///SDCard/";`enter code here`

public MyScreen() {
    grid = new FlowFieldManager();
    try {

        setTitle("Bharat Title");

        for (int i = 0; i < imgpath.length; i++) {

            fc = (FileConnection) Connector.open(compath + imgpath[i]);
            DataInputStream in = fc.openDataInputStream();
            int size = (int) fc.fileSize();
            byte[] bb = new byte[size];
            bb = IOUtilities.streamToBytes(in);
            bit = bit.createBitmapFromBytes(bb, 0, bb.length, 1);
            bit1 = new Bitmap(120, 120);
            bit.scaleInto(bit1, Bitmap.FILTER_BOX);
            bitf[i] = new BitmapField(bit1, FOCUSABLE);
            grid.add(bitf[i]);
            fc.close();

        }
    }

    catch (Exception ex) 
    {
        ex.getMessage();
    }
    finally {
        try {
            fc.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    add(grid);
}
位图位,位1;
BitmapField bitf[]=新的BitmapField[12];
文件连接fc;
流场管理器网格;
字符串[]imgpath={“bharat.png”、“fighter1.jpg”、“fighter2.jpg”,
“fighter3.jpg”、“fighter4.jpg”、“fighter5.jpg”、“fighter7.jpg”,
“fighter8.jpg”、“fighter9.jpg”、“fighter10.jpg”、“fighter11.jpg”,
“fighter6.jpg”};
字符串compath=”file:///SDCard/“;`在这里输入代码`
公共MyScreen(){
网格=新的FlowFieldManager();
试一试{
setTitle(“Bharat Title”);
for(int i=0;i

}

我们可以创建一个具有源图像高度和宽度的位图吗?