How to upload image in Sqlite Database Browser? - ios

I am making one IOS application in which will be using core data and I want to save image in database can anyone tell me how to upload image in Sqlite Database Browser?

To store image in Sqlite Database using core data u need to convert image to data
for example
NSData *photo_data = UIImagePNGRepresentation(aImage);
Now u can store this photo_data. In core data model u create a attribute of type "Binary data"
use this attribute while storing the image data.

You can't just slap in an image file into sqlite. you need to transform the image into a format such as base64 or something that can be stored. when you want to retrieve the image you must transform it back into its original form. for most cases all you need to do is store the path to the image, and not the image itself.

You can use blob object at sqlite. First of all you transform your image to NSData type:
NSData *uiimage=UIImagePNGRepresentation(im);
After bind your datas as blob object such as :
sqlite3_bind_blob(statement,.., [uiimage bytes], [uiimage length], SQLITE_TRANSIENT);

Related

Core data with images

I'm new to iOS app development. My first question is it possible to create a core data entity that will have both text and images included? so attributes will be: Name, Price, Detail and Image. if so, how can I preload the data into the database?
you have to change image into (pngData) them save it and then when reading the image change (pngData) to image
and in core Data model make the image attribute of type binary Data
that source will help
https://blog.devgenius.io/saving-images-in-coredata-8739690d0520

Store zip file to Core data entity like a attribute

I'm work in my application with Core data and want save my zip file to core data entity. Please, tell me is possible and how is possible do
As vadian suggest its a bad practice to store file to core data, if you still wants to save it.
Convert the zip file to data and store the data to Core Data.
[NSData dataWithContentsOfFile: <file_path>] //Objective C
Data.init(contentsOf: <file_path>) //Swift
And Core Data supports the Data attribute, so you will be able to save the data.

How do I convert NSData to a PDF?

I have pdf files stored on Parse.com, I want to download them and set them as images. I have googled around trying to find out how to do this but I'm still clueless. I have got my parse object downloading successfully, the pdf file is stored in the field "image"
//DOWNLOAD IMAGE CODE
PFFile *image = object[#"image"];
[image getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
//we have data, now we want to convert it to a UIImage
}];
just have no idea what to do with the data. Can someone please give me some pointers? thanks
I haven't done this, but I think what you need to do is to first create a data provider out of your data using a call like CGDataProviderCreateWithCFData(), then use the data provider to create a PDF object using CGPDFDocumentCreateWithProvider.
These are Core Foundation calls so you need to do manual memory management of the CF objects (ARC doesn't manage CF objects)
You should be able to Google around using those terms and find code to do what you want.
Are the files store on parse as images or PDF's?
It sounds to me like you've got actual PDF files on parse. You can't just convert them to an image as they aren't images.
If they're PDF files you can save them to disk and then view them with QuickLookPreview
https://developer.apple.com/library/prerelease/ios/documentation/NetworkingInternet/Reference/QLPreviewController_Class/index.html#//apple_ref/occ/instp/QLPreviewController/currentPreviewItem
If they're actually images then you simply use:
[UIImage imageWithData:data]

RestKit CoreData and UIImage

I'm using Rest Kit with Core Data, one of the Core Data entities has an attribute 'image' that has a binary type.
I'm still in mockup stage so the image is populated with this code:
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://lorempixel.com/60/60/people"]]];
entry.image = UIImagePNGRepresentation(image);
Another tab has a collection view that uses fetchedResultsController.
After creating a new entity, if I only save the context the image works fine.
But if I push the entity to the web server using 'postObject:' the image is corrupted when it comes back from the server. I've confirmed the server receives the same string representation of the image "<2f396a2f 34414151 536b5a4a 52674142 ... 6a6e502f 32513d3d>" and stores it directly into a MySQL column of type long blob and at all points the string representation is the same.
But when the collection view is populated using a server call via RestKit the entities image is invalid. I'm think the issue is the data is being converted into the data representation of the description of the data.
Does anyone have a working example with images. The only thing I can think of is that I need to add a custom transformation, but the documentation and examples are lacking as far as how to actually implement one.
RestKit is storing the plain NSData for the image in Core Data - it has no idea what else you might want to do with it. Generally you don't want to manage images directly in Core Data or using RestKit.
Generally, store the path of the image in Core Data and the file on disk. Download them asynchronously (from the URL's which would also be in Core Data).
For uploading, you could make RestKit upload the data, but you probably actually want to file upload or convert to base64. You will need to write some code for this (which you could have RestKit pick up by using the key of the method name that returns the appropriate data). A similar process will work for mapping the data in.
RestKit data transformers are hard to make work in this situation as you are converting between data and strings and they are too general to be able to intercept accurately.

kCGImageStatusUnknownType when calling CGImageSourceCreateWithDataProvider from UIGraphicsGetImageFromCurrentImageContext

I'm trying to create a CGImageSourceRef from a CGDataProviderRef. The CGDataProviderRef comes from a UIImage that was created with UIGraphicsGetImageFromCurrentImageContext. When I do this and check the status of my image source, it's returning kCGImageStatusUnknownType.
I've tried giving it a hint with kCGImageSourceTypeIdentifierHint but to no avail.
Does anyone know how I can create this CGImageSource?
Thanks!
You tell the source that you are giving it PNG data, but you are not. The data provider that you get from the CGImageGetDataProvider function provides raw pixel data, not data in some external format.
The purpose of a CGImageSource is to decode data in some external format (such as PNG) into CGImages. It can't handle pixel data; when you have pixel data, you can just create the CGImage from it directly. Of course, given that you already have the final image, I'm not sure why you're then trying to create it again from any kind of data at all.
If you want to generate some external data to subsequently (as in, after you release this image, possibly in another process) be loaded back in by a CGImageSource, use a CGImageDestination.

Resources