我想用Libtiff創建TIFF圖像。我無法弄清楚文件無法打開的原因。任何人有任何想法?TIFFOpen總是在ios中返回NULL
TIFF *image;
// Open the TIFF file
if((image = TIFFOpen("output.tif", "w")) == NULL){
printf("Could not open output.tif for writing\n");
}
編輯1
#include <stdio.h>
#include <tiffio.h>
int main(int argc, char *argv[]){
// Define an image
char buffer[25 * 144] = { /* boring hex omitted */ };
TIFF *image;
// Open the TIFF file
if((image = TIFFOpen("output.tif", "w")) == NULL){
printf("Could not open output.tif for writing\n");
exit(42);
}
// We need to set some values for basic tags before we can add any data
TIFFSetField(image, TIFFTAG_IMAGEWIDTH, 25 * 8);
TIFFSetField(image, TIFFTAG_IMAGELENGTH, 144);
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 1);
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, 144);
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(image, TIFFTAG_XRESOLUTION, 150.0);
TIFFSetField(image, TIFFTAG_YRESOLUTION, 150.0);
TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
// Write the information to the file
TIFFWriteEncodedStrip(image, 0, buffer, 25 * 144);
// Close the file
TIFFClose(image);
}
任何幫助將不勝感激。 謝謝
我想用這段代碼來寫tiff文件。這是一個c代碼。 – pa12 2012-02-14 22:45:46
這是我嘗試在ios中使用的c函數。 – pa12 2012-02-15 14:25:06
至少把代碼放在自動釋放池和'#import'中,這樣你就可以使用iOS方法,比如'NSSearchPathForDirectoriesInDomains'。 –
zaph
2012-02-15 14:51:19