Titanium Creating an image file: file.write (blob) not creating the correct file

I am trying to read a .PNG file using Titanium 1.8.1 Here is my code to read the file.

var f = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'KS_nav_views.png');
var blob = f.read();

When I create a new file using the above blob, the new file created in this way is not the same as the original file. Here is my code for creating a 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);

The outFile.png file is created, but the problem is that it is not a valid image file. Also the file size is about 53 bytes, while my input file was 1kb.

The same code works fine if we use a simple text file for input and try to create a duplicate output file.

+5
source share
2 answers

read(), :

var t = Titanium.Filesystem.getFile(tempDataDirectory, 'a.json');
var o = Titanium.Filesystem.getFile(onlineDataDirectory, 'b.json');
o.write(t);
+1

.

test.close();
0

All Articles