Sample code: NSBitmapImageRep, NSImage and high resolution images (was RE: NSBitmapImageRep NSCachedImageRep Problem)
Sample code: NSBitmapImageRep, NSImage and high resolution images (was RE: NSBitmapImageRep NSCachedImageRep Problem)
- Subject: Sample code: NSBitmapImageRep, NSImage and high resolution images (was RE: NSBitmapImageRep NSCachedImageRep Problem)
- From: Marco Binder <email@hidden>
- Date: Mon, 23 Jun 2003 12:29:48 +0200
Due to some post of mine to the lists dealing with NSBitmapImageReps
and NSImages, people frequently (well, once in a while) contact me
off-list to ask their image questions. This might be a
misunderstanding: I am no Cocoa professional, particularly no image
processing specialist, not even an educated programmer.
Nevertheless, I was lucky enough to solve most problems and the result
of my playing around are three sample projects which might be of quite
some help for newbies in the field of cocoa image handling. They can be
downloaded here:
MarcosImageTagger
-----------------
http://www.marco-binder.de/dev/MarcosImageTagger.sit
(Stamps "copyrighted" onto a source-image and writes the result to
disk, preserving the originals resolution)
This is a very concise project (one source-file, only 30-40 lines of
code), commented very well (as compared to my usual commenting style).
It is a result of the recent problem of Robert Ziefel on cocoa-dev. He
had the problem, that an NSBitmapImageRep would not output any higher
resolution image than 72 dpi. We figured out, that NSBitmapImageRep
exhibits a "feature" so that [myRep TIFFRepresentation] will in some
cases disregard any changes to the reps size (and hence its
resolution). It shows a simple workaround (mock-calling [myRep
TIFFRepresentation] once).
PDF2Grayscale
-------------
http://www.marco-binder.de/dev/PDF2Grayscale.sit
(Demonstration project; takes a PDF, transforms it into a TIFF of
selectable resolution, renders that into grayscale and writes it out to
disk)
This is a rather simple demo project, commented pretty well. It shows
how to turn a PDF into a TIFF of a certain resolution, and, more
exciting, how to access the raw bitmap data of an NSBitmapImageRep and
working with that (in this case rendering it grayscale). For that
purpose, it sets up a new NSBitmapImageRep into which bitmap data is
filled in subsequently; this seems to be a tough call to many newbies
(actually, it was for me, too, when I started).
PDF2Image
---------
http://www.marco-binder.de/dev/PDF2Image.sit
(Usable but very unfinished application that converts a specifiable
page of a PDF (or almost any other cocoa-supported image type) into a
bitmap image of a selectable format. It can render the source grayscale
and replace any transparency by a selectable color.)
This is a very unfinished app, that was once intended to be a sample
project but is still commented very sparsely and code legibility is
still rather bad. Many portions still require some polish, not even
talking about performance optimization. Still, people might find it
interesting, because it can convert an image rep into any supported
file format (jpeg, tiff, gif, bmp) using user definable compression
settings. It still lacks support for a couple of source image-types
(16-bit images, ...), but it works for PDFs. A newbie will have to chew
quite a bit on it, but can potentially take out quite some ideas as to
how to work with bitmap image reps.
Terms of use
------------
I dont even understand the terms used in the common licenses (GPL and
the like) exactly, so dont expect me to give precise terms of use for
some simple demo projects:
Please note that all three projects are mainly for demonstrating
purposes, not for production work. You can use any portion of the code
freely for your own projects. If you use the category on NSImageRep in
PDF2Image in an only sparsely altered or unaltered fashion in your own
project, I d be very happy if you d put me into the credits.
I hope these samples are of some help to the newbies on these lists
that want to start working with images in cocoa.
Greetings,
marco
--
|\ /| email@hidden
http://www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.