简体   繁体   English

保存的图片与原始图片不同

[英]The saved picture is not the same as the original

I use Titanium Studio 3.4.0 and Titanium SDK 3.4.0 我使用Titanium Studio 3.4.0和Titanium SDK 3.4.0

Before i use it all is fine. 在我使用它之前,一切都很好。 Now when i save an image i can't read the height and th width. 现在,当我保存图像时,我无法读取高度和宽度。

My code for saved: 我保存的代码:

var newDir = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'logo');
if(!newDir.exists())
    newDir.createDirectory();

var writeLogo  = Ti.Filesystem.getFile(newDir.resolve(), logoName);
writeLogo.write(image);

And when i do this 当我这样做时

alert(Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'logo/'+logoName).read().height);

The result is 0. 结果为0。

But when i do this 但是当我这样做时

alert(Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'logo/'+logoName).read().mimeType);

The result are "image/png" like the original. 结果像原始图像一样是“ image / png”。

Do you know where is my mistake and if there is a solution? 您知道我的错误在哪里以及是否有解决方案?

Please see below example working fine in iPhone. 请参阅下面的示例在iPhone上正常运行。

        var filename = "image.png";

        // Create the file in the application directory
        bgImage = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename);

        // Write the image to the new file (image created from camera)
        bgImage.write(image);

        imagePath = Titanium.Filesystem.applicationDataDirectory + Ti.Filesystem.separator + "image.png";
        alert(ImageViewshow);
        imageView = Titanium.UI.createImageView({
            height : 200,
            width : 200,
            image : imagePath,
        });

Thanks and enjoy coding... :) 谢谢,喜欢编码... :)

You can easily delete the stored files in Titanium file systems be the following code: 您可以使用以下代码轻松删除Titanium文件系统中的存储文件:

var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,filename);

if (file.exists()) {
    file.deleteFile();
}

To retrieve the same images as stored, you can put the path as listed below. 要检索与存储的图像相同的图像,可以放置以下路径。 This is image path where image is stored in titanium file system. 这是图像存储在Titan文件系统中的图像路径。

Here is code: 这是代码:

// image path: 

Titanium.Filesystem.applicationDataDirectory + Ti.Filesystem.separator + "image.png" 
imageUpload = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory + Ti.Filesystem.separator + "image.png").read();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用Cordova显示本地保存的图片 - Display locally saved picture with Cordova 如何在iPhone胶卷上取回保存的图片? - How do I get back a saved picture on iPhone camera roll? Ionic:相机选项无法使用-图片未保存,奇怪的错误 - Ionic: Camera options not working - picture not saved, strange error UIGestureRecognizer,使平移的图片返回其原始位置 - UIGestureRecognizer, making panned picture return to its original location 最终在不同的对象上调用save-它们是否以相同的顺序保存? - Calling saveEventually on different objects - are they saved in the same order? 如何获得与取景器UIImagePickerController相同的图片 - How to get a picture same as viewfinder UIImagePickerController 尽管保存了相同的数据,但领域文件大小有所不同 - Realm Filesize varies though same data is saved 自定义的具有与原始标题相同的UIBarButton? - Custom back UIBarButton with same title as the original? 文本段中的内存副本与原始副本不同 - The memory copy from text segment is not the same with the original 应用程序图片中的Swift Camera在保存照片并检索资产时不保存GPS信息吗? - Swift Camera in app picture not saving GPS information when photo is saved and the asset is retrieved?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM