钛创建映像文件:file.write(BLOB)没有创造正确的文件 [英] Titanium Creating Image file: file.write(blob) not creating the correct file
问题描述
我想读使用钛1.8.1 .png文件 这是我的code读取文件。</ P>
I am trying to read a .PNG file using Titanium 1.8.1 Here is my code to read file.
var f = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'KS_nav_views.png');
var blob = f.read();
当我创建使用上述blob对象一个新的文件,从而创建新的文件是不一样的原始文件。 这是我的code创建新的文件。
When I create a new file using the above blob object, the new file thus created is not same as the original file. Here is my code to create the new file.
var outputDir = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory,'output');
outputDir.createDirectory();
var newFile = Titanium.Filesystem.getFile(outputDir.nativePath,'outFile.png');
var test = newFile.write(blob);
if ( test === false){
Ti.API.debug("Write Error");
}
Ti.API.debug("Write complete? " + test);
在outFile.png被创建,但问题是,这不是一个有效的图像文件。另外,文件的大小约为53字节,而我的输入文件是1kb的
The outFile.png gets created but the problem is that It is not a valid image file. Also the size of the file is around 53 bytes, whereas my input file was 1kb.
同样的code工作正常,如果我们用一个简单的文本文件作为输入,并尝试创建重复的输出文件。
The same code works fine if we use a simple text file as input and try to create duplicate output file.
推荐答案
您不需要做阅读()做这样的:
You do not need to do read() do it like this:
var t = Titanium.Filesystem.getFile(tempDataDirectory, 'a.json');
var o = Titanium.Filesystem.getFile(onlineDataDirectory, 'b.json');
o.write(t);
这篇关于钛创建映像文件:file.write(BLOB)没有创造正确的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!