user24205
user24205

Reputation: 502

How to Show an Image in OS X with C code in XCode

I am writing a C application, and I am developing in XCode. I would like my code to create a window and display an image in that window. If possible, I would like the image to be resized if a user changes the size of the displayed window, but this is not at all necessary.

I am specifically avoiding C++ and ObjectiveC. I need to work with straight C. Is this possible?

All help is appreciated.

Upvotes: 0

Views: 520

Answers (1)

user149341
user149341

Reputation:

Your best bet will be to learn Objective-C. It's not difficult to pick up, especially if you already have a strong understanding of C. (It's a much smaller and simpler extension of C than C++, for instance.)

Your options other than that are quite limited:

  • There's Carbon, Apple's legacy C framework for UI development. Using it is not recommended. Carbon was never updated to support 64-bit applications, and lacks many features that have been added to Cocoa since the 64-bit transition (~2005). It's also very awkward to write an application in, as it was designed in large part to ease porting of applications written for Classic Mac OS.

  • There's also X11, with an appropriate UI library like GTK. I wouldn't recommend this either. Neither X11 nor any UI libraries for it are installed by default -- they must be installed by the user -- and applications which use X11 have a significantly different interface from native applications.

  • A third-party UI library. Most of the ones I can think of offhand (QT, wxWidgets, and FLTK) require C++, though. GTK+ does have a C interface and natively supports a macOS interface, but it's not particularly native.

  • A library specific to your use case. Impossible to recommend one without knowing more about what you're trying to do.

  • Nothing. That's right, nothing at all. If you just need to let the user view an image, you can save it to a file and use the open command-line tool to open it in the Preview application. It's janky, but it's also really easy.

Upvotes: 1

Related Questions