【问题标题】:Blackberry screenshot image file not showing after saving it黑莓截图图像文件保存后不显示
【发布时间】:2012-07-24 03:01:41
【问题描述】:

我正在开发一个应用程序,它需要在某个时刻截取屏幕截图并将其保存在文件系统中。我的问题是,在设备重置之前,图像在文件资源管理器中不可见,并且在某些型号中,图像甚至不显示,它只是一个不可读的 img 文件(如曲线)。

我拍摄图像的代码是:

private Bitmap getScreenShot(){
    Bitmap bitmap;
    bitmap = new Bitmap(Display.getWidth(), Display.getHeight());
    Display.screenshot(bitmap);
    // return the screen shot
    return bitmap;
}

private void saveInMemory(){
    Bitmap screenShot = getScreenShot();

    Date dateNow = new Date ();

    SimpleDateFormat dateformatYYYYMMDD = new SimpleDateFormat("yyyyMMddHHmmss");

    String timeStamp = dateformatYYYYMMDD.format(dateNow);

    String mFileName = System.getProperty("fileconn.dir.photos")
                + "RM_" + timeStamp + ".jpg";

    PNGEncodedImage png = PNGEncodedImage.encode(screenShot);

    writeFile(png.getData(), mFileName);

}

private void writeFile(byte[] data, String fileName) {
    FileConnection fconn = null;
    try {
        fconn = (FileConnection) Connector.open(fileName);
    } catch (IOException e) {
        System.out.print("Error opening file");
    }

    if (fconn.exists()){
        try {
            fconn.delete();
        } catch (IOException e) {
            System.out.print("Error deleting file");
        }
    }

    try {
        fconn.create();
    } catch (IOException e) {
        System.out.print("Error creating file");
    }
    OutputStream out = null;

    try {
        out = fconn.openOutputStream();
    } catch (IOException e) {
        System.out.print("Error opening output stream");
    }

    try {
        out.write(data);
    } catch (IOException e) {
        System.out.print("Error writing to output stream");
    }

    try {
        fconn.close();
    } catch (IOException e) {
        System.out.print("Error closing file");
    }
}

【问题讨论】:

    标签: blackberry screenshot


    【解决方案1】:

    我没试过。但是为什么要为 png 文件生成 .jpg 扩展名呢?

    正确答案是:输出流没有正确关闭。

    【讨论】:

    • 实际上我已经得到了解决方案,但它不允许我在接下来的 5 个小时内发布它:p。我错过了最后关闭的 outputStream
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多