I am working on iphone app and i need to save image into .tiff format.
It is possible to save image into png format using UIImagePNGRepresentation method and JPEG format using UIImageJPEGRepresentation. But i need to save signature captured by imageview into tiff format.
I unable to use NSImage class so that i can call TIFFRepresentation method.
How can i do it.Send me suggestion...
Thanks in advance...
I don't know what you mean by "captured by imageview". The means to save as TIFF wasn't introduced until iOS 4. Here is example code to save an arbitrary file as a TIFF; you can do this with any file-format data, no matter how you obtained it. You need to link to ImageIO framework and do #import <ImageIO/ImageIO.h>:
NSURL* url = [[NSBundle mainBundle] URLForResource:#"colson" withExtension:#"jpg"];
CGImageSourceRef src = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
NSFileManager* fm = [[NSFileManager alloc] init];
NSURL* suppurl = [fm URLForDirectory:NSApplicationSupportDirectory
inDomain:NSUserDomainMask
appropriateForURL:nil
create:YES error:NULL];
NSURL* tiff = [suppurl URLByAppendingPathComponent:#"mytiff.tiff"];
CGImageDestinationRef dest = CGImageDestinationCreateWithURL((CFURLRef)tiff,
(CFStringRef)#"public.tiff", 1, NULL);
CGImageDestinationAddImageFromSource(dest, src, 0, NULL);
bool ok = CGImageDestinationFinalize(dest);
NSLog(#"result %i", ok); // 1, all went well
// and don't forget memory management, release source and destination, NSFileManager
[fm release]; CFRelease(src); CFRelease(dest);
Hmm, I don't develop for the iPhone, so can't tell you if there's a magic API way of doing this, but many years ago I had to create TIFF images manually.
The TIFF format is a bit whacky if you're used to just using a framework's CreateThisStuffAsAnImage() methods, but you can get the spec here and create the file yourself:
http://partners.adobe.com/public/developer/tiff/index.html#spec
Related
On MacOS, .heic image files can contain one light and one dark version. This can be seen for system wallpapers using open: for example
open /System/Library/Desktop\ Pictures/Dome.heic
The Preview app displays both versions. My goal is to be able to access them using Objective-C, as I would like to save both light and dark versions to .jpg format.
Following snippet succeeds in extracting the light version and saving it to disk:
NSString* wallpaper_path = /* insert source path here */;
NSString* converted_path_str = /* insert destination path here */;
NSImage* image = [[[NSImage alloc] initWithContentsOfFile:wallpaper_path] autorelease];
NSData* data = [image TIFFRepresentation];
NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:data];
NSDictionary* properties =[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:1.0] forKey:NSImageCompressionFactor];
data = [rep representationUsingType:NSJPEGFileType properties:properties];
[data writeToFile:converted_path_str atomically:NO];
However I cannot find how to access the dark version using NSImage, NSImageRep or NSBitmapImageRep.
As Preview succeeds in doing it, I think it's possible though. I just don't know how to do.
Anyone aware of how to create usdz from obj on the fly? Our application creates an obj file using a third party library and for using the QLPreviewController we need to convert it to usdz format. There are ways to do that using the terminal but wondering if there is any way to do it programmatically?
An engineer on my team figured this out last week!
Creating USDZ files is funny right now - currently we can fake it by saving a USDC file and... renaming the extension!
First you'll want to load the .obj file at filePath as an MDLAsset
NSURL *url = [NSURL fileURLWithPath:filePath];
MDLAsset *asset = [[MDLAsset alloc]initWithURL:url];
ensure the MDLAsset can write the desired extensions
usdc is supported (USD binary format)
if([MDLAsset canExportFileExtension:#"usdc"]){
NSLog(#"able to export as usdc");
// save the usdc file
[asset exportAssetToURL:usdcUrl];
}
rename the usdc to usdz because that's all it takes
NSError *renameErr;
NSFileManager *fm = [[NSFileManager alloc] init];
BOOL mvResult = [fm moveItemAtPath:usdcPath toPath:usdzPath error:& renameErr];
if(! mvResult){
NSLog(#"Error renaming usdz file: %#", [renameErr localizedDescription]);
}
Hope this helps until Apple can give us a more thorough how-to.
If you want to read a more long form breakdown of this - https://www.scandy.co/blog/how-to-export-simple-3d-objects-as-usdz-on-ios
My service returns the following which is a blob representing an image:
/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCADhASw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FjztGM1eSHaOxNLEuzr1NS7h3qCkRhSOtKADUhwaaVx0/SkBJaKrXSbuR1rZChmwXbaO1YQ+U7gcMO9W4ryZWBJ49qadhNF50GcHOCeTUKkBDl+nQUn2oPnaWBPXdTNwZfmYHPTA5qriJAwVgNwOeeTzTC7tk9P8aCu3JDZP8AKopSc8Dt2aquIcz5HX/vqowCcAdcdu9MDZzgE89M0xhl+OPWncQ/KjAwPfkk1EZB5uCmEU9cfyppOzOQMHgU1pMkEE8dDnP4UxEhkbnJwW/yKZuKbixU5qOSYs4B4OP8/jTDJ8gByOv+TQBIzRhd2Qf97qKhaZVfcjKB39aa8mRkbgepPtVdtrkEZyBQBZMoJBbkjqCcUiEtkjC89MVWVhgnk5z+FEbOy9W44+7SsB5tqP8AyE7v/rs//oRqOD/j4j/3hRRQxjbv/j9m/wCuh/nTD0oopgPp1FFIDd8O/fb/AHhXXx/dNFFUgJUq3af65aKKBmifvN/vGnx/6z8aKKBGi/8Aq/xpkv3BRRSYyCTov0rD1j/XR/7tFFSBBD2rSt+p+lFFQyiweg+lI3UUUVLGNP3R9KeP4aKKkYx/9W1Sr0oopiHDv9KfbffH4UUU0MmPQ1DJ0P40UVRDI0+6fxqvL/q/8+tFFWhD2+6/1H8qgg/1zf73+NFFMTIbv7x/3hTf4j9T/WiimIjj/wBX+H9KgT7jf7woooAaPvfgf51et/8AVn60UUCZ/9k=
In Oobjective-C I'm trying to convert it back to an image and I get exception, I even tried saving it to a file testing different extensions (png, jpg, jpeg, bmp) nothing worked the only way the file opens is with a txt extension.
How can I convert this blob into the image it should be?
That looks like Base64 encoded JPEG image data, so this should work:
NSString *b64String = #"/9j/4AAQSkZJRgABAQEASA ..."; // your string from the server
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:b64String options:0];
UIImage *image = [UIImage imageWithData:imageData];
initWithBase64EncodedString is available since iOS 7.0. If you want to target
earlier iOS versions, you can use the following method instead:
NSData *imageData = [[NSData alloc] initWithBase64Encoding:b64String];
I want to convert a UIImage into a format such as a jpeg or png so that I can then share that file using the IOS plug-in called "AddThis".
I tried to share it using just the UIImage but the plug-in doesn't support it so I need to find a way to convert the UIImage to a jpeg first, then add it into this code:
[AddThisSDK shareImage:[UIImage imageNamed:#"test.jpg] withService:#"twitter" title:#"I'm sharing something" description:#"Random description of image"];
the code has to have shareImage:[UIImageNamed:#""] otherwise an error occurs.
So far I've tried to convert it using UIImageJPEGRepresentation but I don't think I've done it properly. To be honest I tried to do it similarly to how you'd convert it straight from taking an image:
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:#"photo_boom.jpg"];
[UIImageJPEGRepresentation(shareImage, 1.0) writeToFile:jpgPath atomically:YES];
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:#"photo_boom.jpg"];
NSLog(#"Documents directory: %#", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
Something tells me this isn't the correct way... mainly because I haven't been able to get it to work.
I'd really appreciate any kind of help!
Basically, I've made a UIImage from converting a UIView:
UIGraphicsBeginImageContext(firstPage.bounds.size);
[firstPage.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
Which I then want to give a jpeg format because when I tried to simply put it in as
[AddThisSDK shareImage:image withService:#"twitter" title:#"I'm sharing something" description:#"Random description of image"];
It gives me an error
UIImage has its own internal representation of an image, so it's irrelevant whether you load it with jpeg or png data.
The API call you're interested has a UIImage as the first parameter, so something along the lines of
[AddThisSDK shareImage:[UIImage imageNamed:#"photo_boom.jpg"]
withService:#"twitter"
title:#"I'm sharing something"
description:#"Random description of image"];
should work, provided photo_boom.jpg is included in your bundle. If you're loading a previously saved image from a folder, you'll need something like this:
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:#"photo_boom.jpg"];
UIImage * myImage = [UIImage imageWithContentsOfFile: jpgPath];
[AddThisSDK shareImage:myImage
withService:#"twitter"
title:#"I'm sharing something"
description:#"Random description of image"];
If that doesn't work, have you tried putting a breakpoint on the AddThisSDK line, and checking the value of image? Type po image on the console.
I receive a binary pdf file, which is base64Binary encoded.
How can I convert it back on the iPhone? What tool kits can I use?
Thanks.
Solved:
NSData theData = [NSData dataWithData:[GTMBase64 decodeString:theBinary]]; //first transfer it to NSData.
[m_oTestingWeb loadData:theData
MIMEType:#"application/pdf"
textEncodingName:#"UTF-8"
baseURL:nil]; //using the web view to show it back
Solution
NSString *binaryString = [myDict objectForKey:#"key"];
NSData* myData = [NSData dataFromBase64String: binaryString];
NSLog(#" %#",datas);
[self savePDF:myData];
and save PDF is like this
- (void)savePDF:(NSData *)pdfContent
{
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask ,YES );
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *finalPath = [documentsDirectory stringByAppendingPathComponent:#"myPdf.pdf"];
NSLog(#"%#",finalPath);
NSURL *url = [NSURL fileURLWithPath:finalPath];
[pdfContent writeToURL:url atomically:YES];
// [aWebView loadRequest:[NSURLRequest requestWithURL:url]];
}
Get headers here.
If you mean NSData by the word "binary" then you can follow the following method.
I think if the binary data is already in PDF format then we can just use the normal NSData method to writeToFile:atomically to write it to the file.
[<NSDataObject> writeToFile:<FilePath> atomically:YES];
And then you can use the DocInteraction to open and display a PDF File.
Hope this helps you.
To convert a binary (base64 pdf string) to pdf and show it you can do this for Swift 3:
// Here you convert the binary base 64 pdf string to pdf
let pdfData = Data(base64Encoded: theBase64PDFString, options: .ignoreUnknownCharacters)
// here you can display the pdf on a UIWebView
webView.load(pdfData!,
mimeType: "application/pdf",
textEncodingName: "UTF-8",
baseURL: URL(fileURLWithPath: ""))
To display a PDF, you can simply use a UIWebView and feed it the PDF. If you want it a little more sophisticated, look at Apple's ZoomingPDFViewer sample code (found that one in an answer to another question).
Visit this site base64 encoding. Here You will get code for decoding base64 data to NSData. Using that data you can save pdf, view pdf using UIWebView or using Quartz Core.
To convert the binary into a PDF file
#IBOutlet var pdfView: PDFView!
guard
var fileURL = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)).last,
let convertedData = Data(base64Encoded: data.base64EncodedData()) // data is the binary pdf
else {
// handle error when getting documents URL
return
}
fileURL.appendPathComponent("filename.pdf")
do {
try convertedData.write(to: documentsURL)
} catch {
// handle write error
}
Bonus: View the PDF without deprecated UIWebView API
let pdfView = PDFView(frame: self.view.bounds)
self.view.addSubview(pdfView)
// Fit content in PDFView.
pdfView.autoScales = true
pdfView.document = PDFDocument(url: fileURL)
Maybe it's a bit late, but I hope it will help someone else at least.