home *** CD-ROM | disk | FTP | other *** search
/ Altsys Virtuoso 2.0K / virtuoso_20k.iso / NeXTanswers / Questions_and_Answers / NEXTSTEP_Developer / AppKit / 1310_NXImage_writeTIFF.rtf < prev    next >
Encoding:
Text File  |  1993-08-31  |  2.0 KB  |  43 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f2\fmodern Ohlfs;}
  2. \paperw13040
  3. \paperh10800
  4. \margl120
  5. \margr120
  6. {\colortbl;\red0\green0\blue0;\red84\green84\blue84;\red83\green83\blue83;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ulnone\fs28\fc0\cf0 Q:  My application is a simple paint program.  The user opens a TIFF image, then scribbles into it, and finally saves the new image as a TIFF file.  However, the changes made by the user aren't saved into the TIFF file—it contains the original image.  Why?\
  8. \
  9. A:  This occurs if you open the TIFF file like this:\
  10. \
  11.  
  12. \f2\fs22     image = [[NXImage alloc] initFromFile:fileName];\
  13.  
  14. \f0\fs28 \
  15. NXImage will have two representations—the file, and the cache.  NXImage will treat the cache as a transitory image, and the file as its "best representation."  The cache is the off-screen window to which the user's scribbles are drawn.  When asked to write out the image, NXImage writes out its best representation of the image—which is the actual TIFF file residing on disk—thus ignoring completely the changes made to the image.  To get around this you must fake out NXImage by forcing the cache to be the best representation of the image.\
  16. \
  17. The following code snippet illustrates what you must do:\
  18. \
  19.  
  20. \f2\fs22     /*  When the user opens the image */\
  21.     rep = [[NXBitmapImageRep alloc] initFromFile:fileName];\
  22.     [rep getSize:&imageSize];\
  23. \
  24.     image = [[NXImage alloc]  initSize:&imageSize];\
  25. \
  26.     if ([image useCacheWithDepth:d] && [image lockFocus]) \{\
  27.         [rep draw];\
  28.         [image unlockFocus];\
  29.     \}\
  30.     [rep free];\
  31.  
  32. \f0\fs28 \
  33.  
  34. \fc1\cf1 This code sample initialized an NXBitmapImageRep from the file containing the opened image.  The NXImage is initialized from this representation.  Now the NXImage does not have a file which can serve as its best representation—it only has the cache.  Thus when you tell NXImage to 
  35. \b writeTIFF:
  36. \b0  the cache with all of the user's scribbles is written out properly.\
  37. \
  38. QA786\
  39. \
  40. Valid for 1.0, 2.0, 3.0\
  41. \
  42.  
  43.