i save uiimage coredata entity.
per accepted answer here, in order save uiimage same entity table, suggested size of uiimage should < 100kb
thus when user takes uiimage uiimagepickercontroller (either library or camera), uiimagejpegrepresentation
@ compressionquality
rate render uiimage data < 100kb
playing around with
let imgdata: nsdata = uiimagejpegrepresentation(cameraimage, <#compressionquality: cgfloat#>) let size = imgdata.length
i've realized 0.8 not equivalent 80% data size of 1.0 compression.
how take uiimage of size , compress down data: size of 100kb maximum, integrity held while allowing size small enough store in coredata entity?
note: original idea test size
of uiimage compress @ "rate x = 100,000/size"
you not need downsize image under 100kb, have create coredata attribute of type binary , tick "allows external storage" box. coredata take care of rest you:
- create attribute named
imagedata
of type binary , allowing external storage - create transient attribute named 'image' , implement custom getters , setters per below:
files larger 1mb stored on separate folder relative database folder whereas smaller files saved directly sqlite file.
- (void)setimage:(uiimage*)image { nsdata *data = uiimagejpegrepresentation(image, 0.5); if (data) { [self setimagedata:data]; } } - (uiimage*)image { uiimage *image = [uiimage imagewithdata:self.imagedata]; return image; }