从黑莓设备读取/写入照片的方法

发布于 2024-12-26 01:28:45 字数 141 浏览 3 评论 0原文

我正在尝试创建一个黑莓应用程序,在其中我需要拍摄用户已保存或在黑莓上拍摄的照片,然后将其添加到另一张照片并保存照片,以便当用户进入其保存的照片时新照片已可用。我目前正在努力解决如何访问用户的照片,然后将新照片保存在用户可以获得它的地方,并最终将其添加为手机的背景图像。

I'm trying to create a blackberry app in which I need to take a photo that the user has saved on or taken on their blackberry and then add it to another photo and save the photo so that when the user goes into their saved photos then the new photo is available. I am currently struggling with how to access the user's photos and then saving the new photo in a place where the user can get it and eventually add it as their background image of their phone.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

女皇必胜 2025-01-02 01:28:45

从设备读取图像的代码。

public void checkImages(String imagePath) {
    String path = "";
    if (imagePath.equals(""))
        path = "file:///SDCard/";
    else
        path = imagePath;
    try {
        FileConnection fileConnection = (FileConnection)Connector.open(path);
        if (fileConnection.isDirectory()) {
            Enumeration directoryEnumerator = fileConnection.list("*", true);
            while(directoryEnumerator.hasMoreElements()) {
                contentVector.addElement(directoryEnumerator.nextElement());
            }
            fileConnection.close();
            for (int i = 0 ; i < contentVector.size() ; i ++) {
                String name = (String) contentVector.elementAt(i);
                checkImages(path + name);
            }
        }
        else {
            if (path.toLowerCase().endsWith(".jpg")) {
                fileConnection.close();
            }
        }
    } catch (Exception ex) { }
}

将图像保存到设备的代码..

private void saveBitmap(int picIndex, Bitmap bmp) 
{

    String PHOTO_DIR = System.getProperty ("fileconn.dir.photos"); 
    String EXTENSION = ".bmp";
    String filePath = PHOTO_DIR + picIndex + EXTENSION;        

    try
    {
        FileConnection fconn = (FileConnection)Connector.open(filePath, Connector.READ_WRITE); 

        if(fconn.exists())
           fcomm.delete();

        fconn.create();

        OutputStream outputStream = fconn.openOutputStream();

        PNGEncodedImage encodedImage =  PNGEncodedImage.encode(bmp);
        byte[] imageBytes = encodedImage.getData();                   
       outputStream.write(imageBytes);
       outputStream.close();
        fconn.close();
    }
    catch(Exception e){
        System.out.println("  Exception while saving Bitmap:: "+e.toString());
    }
}

并从 读/写图像

Code to read Images from Device.

public void checkImages(String imagePath) {
    String path = "";
    if (imagePath.equals(""))
        path = "file:///SDCard/";
    else
        path = imagePath;
    try {
        FileConnection fileConnection = (FileConnection)Connector.open(path);
        if (fileConnection.isDirectory()) {
            Enumeration directoryEnumerator = fileConnection.list("*", true);
            while(directoryEnumerator.hasMoreElements()) {
                contentVector.addElement(directoryEnumerator.nextElement());
            }
            fileConnection.close();
            for (int i = 0 ; i < contentVector.size() ; i ++) {
                String name = (String) contentVector.elementAt(i);
                checkImages(path + name);
            }
        }
        else {
            if (path.toLowerCase().endsWith(".jpg")) {
                fileConnection.close();
            }
        }
    } catch (Exception ex) { }
}

Code to save image to device..

private void saveBitmap(int picIndex, Bitmap bmp) 
{

    String PHOTO_DIR = System.getProperty ("fileconn.dir.photos"); 
    String EXTENSION = ".bmp";
    String filePath = PHOTO_DIR + picIndex + EXTENSION;        

    try
    {
        FileConnection fconn = (FileConnection)Connector.open(filePath, Connector.READ_WRITE); 

        if(fconn.exists())
           fcomm.delete();

        fconn.create();

        OutputStream outputStream = fconn.openOutputStream();

        PNGEncodedImage encodedImage =  PNGEncodedImage.encode(bmp);
        byte[] imageBytes = encodedImage.getData();                   
       outputStream.write(imageBytes);
       outputStream.close();
        fconn.close();
    }
    catch(Exception e){
        System.out.println("  Exception while saving Bitmap:: "+e.toString());
    }
}

and get help from Read/Write Image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文