1, UIView screenshot
-(uiimage*) Captureview: (UIView *) theview{
CGRect rect = theview.frame;
if ([TheView Iskindofclass:[uiscrollview class]]) {
Rect.size = ((Uiscrollview *) theview). Contentsize;
}
Uigraphicsbeginimagecontext (rect.size);
Cgcontextref context = Uigraphicsgetcurrentcontext ();
[Theview.layer Renderincontext:context];
UIImage *img = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
return img;
}
2, Uiscrollview screenshot
-(UIImage *) Capturescrollview: (Uiscrollview *) scrollview{
uiimage* image = Nil;
Uigraphicsbeginimagecontext (scrollview.contentsize);
{
Cgpoint savedcontentoffset = Scrollview.contentoffset;
CGRect savedframe = scrollview.frame;
Scrollview.contentoffset = Cgpointzero;
Scrollview.frame = CGRectMake (0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
[Scrollview.layer Renderincontext:uigraphicsgetcurrentcontext ()];
Image = Uigraphicsgetimagefromcurrentimagecontext ();
Scrollview.contentoffset = Savedcontentoffset;
Scrollview.frame = Savedframe;
}
Uigraphicsendimagecontext ();
if (image!= nil) {
return image;
}
return nil;
}
3. Combine multiple photos
-(UIImage *) Composewithheader: (UIImage *) header content: (UIImage *) content footer: (uiimage *) footer{
Cgsize size = Cgsizemake (content.size.width, header.size.height +content.size.height +footer.size.height);
Uigraphicsbeginimagecontext (size);
[Header drawinrect:cgrectmake (0,
0,
Header.size.width,
Header.size.height)];
[Content drawinrect:cgrectmake (0,
Header.size.height,
Content.size.width,
Content.size.height)];
[Footer Drawinrect:cgrectmake (0,
Header.size.height+content.size.height,
Footer.size.width,
Footer.size.height)];
UIImage *image = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
return image;
}
4, Streaming media
Turn audio and pictures into base64binary
+ (NSData *) base64encoded: (NSData *) data
{
base64binary (Streaming media)
static char encodingtable[64] = {
' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ',
' Q ', ' R ', S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z ', ' A ', ' B ', ' C ', ' d ', ' e ', ' f ',
' G ', ' h ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' o ', ' P ', ' Q ', ' R ', ' s ', ' t ', ' u ', ' V ',
' W ', ' x ', ' y ', ' z ', ' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' + ', '/'};
Const unsigned char *bytes = [data bytes];
nsmutablestring *result = [nsmutablestring stringwithcapacity:[data length]];
unsigned long ixtext = 0;
unsigned long lentext = [data length];
Long ctremaining = 0;
unsigned char inbuf[3], outbuf[4];
unsigned short i = 0;
unsigned short charsonline = 0, ctcopy = 0;
unsigned long IX = 0;
while (YES)
{
ctremaining = Lentext-ixtext;
if (ctremaining <= 0) break;
for (i = 0; i < 3; i++) {
IX = Ixtext + i;
if (ix < lentext) Inbuf[i] = Bytes[ix];
else inbuf [i] = 0;
}
outbuf [0] = (inbuf [0] & 0xFC) >> 2;
outbuf [1] = ((inbuf [0] & 0x03) << 4) | ((Inbuf [1] & 0xF0) >> 4);
OUTBUF [2] = ((Inbuf [1] & 0x0f) << 2) | ((Inbuf [2] & 0xc0) >> 6);
OUTBUF [3] = Inbuf [2] & 0x3F;
Ctcopy = 4;
Switch (ctremaining)
{
Case 1:
Ctcopy = 2;
Break
Case 2:
Ctcopy = 3;
Break
}
for (i = 0; i < ctcopy; i++)
[Result appendformat:@ "%c", Encodingtable[outbuf[i]]];
for (i = Ctcopy i < 4; i++)
[Result appendstring:@ "="];
Ixtext + 3;
Charsonline + 4;
}
return [result datausingencoding:nsutf8stringencoding];
}
This calls the above method
+ (NSString *) Loadingfile: (Nsurl *) filepath
{
NSData * data = [[NSData Alloc]initwithcontentsofurl:filepath];
NSData * Base64data = [self base64encoded:data];
NSString * strBase64 = [[NSString alloc]initwithdata:base64data encoding:nsasciistringencoding];
return strBase64;
Can upload this base64data to server now
}