gpt4 book ai didi

titanium - 无法保存图像 Blob

转载 作者:行者123 更新时间:2023-12-04 18:34:57 25 4
gpt4 key购买 nike

我正在尝试将照片库中的图像保存到本地存储,以便我可以跨应用程序 session 加载图像。用户完成选择图像后,将执行以下逻辑。在模拟器上,我看到错误消息已写入日志。即使我看到错误消息,我认为图像仍保存在模拟器中,因为当我重新启动应用程序时,我能够加载保存的图像。但是,当我在设备上运行它时,我仍然收到您在下面的代码中看到的错误消息,并且加载了默认背景,这表明写入不成功。

谁能看出我做错了什么以及为什么图像无法成功保存?

var image = i.media.imageAsResized(width, height);
backgroundImage.image = image;
function SaveBackgroundImage(image)
{
var file = Ti.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,W.CUSTOM_BACKGROUND);
if(file.write(image, false))
{
W.analytics.remoteLog('Success Saving Background Image');
}
else
{
W.analytics.remoteLog('Error Saving Background Image');
}
file = null;
}

最佳答案

试试这个代码:

var parent = Titanium.Filesystem.getApplicationDataDirectory();
var f = Titanium.Filesystem.getFile(parent, 'image_name.png');
f.write(image);
Ti.API.info(f.nativePath); // it will return the native path of image

在您的代码中,我认为您没有提供图像类型 (png/jpeg),这就是您出现错误的原因。

关于titanium - 无法保存图像 Blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13707615/

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