Update: Imebra 4.2 includes the full set of ObjectiveC wrappers, which also work with Swift.
Original alswer:
Imebra allows to read and generate DICOM files also on iOS.
It compiles also for iOS and OS-X, it's written in C++ but it can be used with ObjectiveC method if the extension of the file is .mm instead of .m
Since version 4.0.8.1, Imebra contains also few objectiveC helpers that translate C++ strings to NSStrings (and vice-versa) and extract an UIImage (or NSImage) from an Imebra image
How to generate a DICOM file in Imebra (detailed instructions):
Create an empty dataset:
// We specify the transfer syntax and the charset
std::string transferSyntax(imebra::NSStringToString(@"1.2.840.10008.1.2.1"));
std::string encoding(imebra::NSStringToString(@"ISO 2022 IR 6"));
imebra::DataSet dataSet(transferSyntax, encoding);
Create an image, put it into the dataset:
// Create a 300 by 200 pixel image, 15 bits per color channel, RGB
std::string colorSpace(imebra::NSStringToString(@"RGB"));
imebra::Image image(300, 200, imebra::bitDepth_t::depthU16, colorSpace, 15);
{
std::unique_ptr<WritingDataHandlerNumeric> dataHandler(image.getWritingDataHandler());
// Set all the pixels to red
for(std::uint32_t scanY(0); scanY != 200; ++scanY)
{
for(std::uint32_t scanX(0); scanX != 300; ++scanX)
{
dataHandler->setUnsignedLong((scanY * 300 + scanX) * 3, 65535);
dataHandler->setUnsignedLong((scanY * 300 + scanX) * 3 + 1, 0);
dataHandler->setUnsignedLong((scanY * 300 + scanX) * 3 + 2, 0);
}
}
// dataHandler will go out of scope and will commit the data into the image
}
dataSet.setImage(0, image);
Save the dataset
std::string fileName(NSStringToString(@"path/to/file.dcm"));
imebra::CodecFactory::save(dataSet, fileName, imebra::codecType_t::dicom);
(disclusure: I'm the author of Imebra)