Change the size of the picture
-(uiimage*) Originimage: (UIImage *) image scaletosize: (cgsize) size
{
Uigraphicsbeginimagecontext (size); Size is the cgsize type, which is the size of the picture you need
[Image drawinrect:cgrectmake (0, 0, Size.width, size.height)];
uiimage* scaledimage = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
UIImage *imagescaless= [self imageretain:scaledimage];
return imagescaless; Returned is a picture that has changed
}
Processing of. 2x Images
-(uiimage*) Imageretain: (UIImage *) sourceimage
{
Cgsize size;
Size = Cgsizemake (sourceimage.size.width/2.0f, sourceimage.size.height/2.0f);
Uigraphicsbeginimagecontextwithoptions (size, NO, 0);
if (1.0 = = [[UIScreen mainscreen] scale]) {
[Sourceimage drawinrect:cgrectintegral ((cgrect) {0.0f, 0.0f, size})];
}else{
[Sourceimage Drawinrect: (CGRect) {0.0f, 0.0f, size}];
Sourceimage = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
}
return sourceimage;
}
Here's how to call it:
-(void) viewdidload
{
[Super Viewdidload];
_datalist=[[nsmutablearray Alloc]initwithcapacity:10];
[Self initviews];
Nsarray *tmparray1 = @[@ "photo Wall" @ "Discussion area" @ "group" @ "Contacts"];
Self. Sxhary = TmpArray1;
Nsarray *tmparray2 = @[@ "Evening rest assured buy", @ "Xiamen Real Estate dynamic", @ "Xiamen auto market dynamic"];
Self. Xmrbary = TmpArray2;
Nsarray *bfirsts = @[@ "Gc1.png", @ "Gc2.png", @ "Gc3.png", @ "Gc4.png"];
Nsmutablearray *bfirst=[[nsmutablearray alloc]initwithcapacity:0];
for (int i=0; i<bfirsts.count; i++) {
Uiimage*images=[uiimage imagenamed:[bfirsts Objectatindex:i]];
UIImage *imagenew=[self originimage:images Scaletosize:cgsizemake (45, 45)];
[Bfirst addobject:imagenew];
}
Self.bfirstary = [Bfirst copy];
Nsarray *bsecconds = @[@ "Gc6.png", @ "Gc7.png", @ "Gc8.png"];
Nsmutablearray *bsecond=[[nsmutablearray alloc]initwithcapacity:0];
for (int i=0; i<bsecconds.count; i++) {
Uiimage*images=[uiimage Imagenamed:[bsecconds Objectatindex:i]];
UIImage *imagenew=[self originimage:images Scaletosize:cgsizemake (45, 45)];
[Bsecond addobject:imagenew];
}
Self.bsecondary = [Bsecond copy];
Nsarray *rfirsts = @[@ "Gc1.png", @ "Gc2.png", @ "Gc3.png", @ "Gc4.png"];
Nsmutablearray *rfirst=[[nsmutablearray alloc]initwithcapacity:0];
for (int i=0; i<rfirsts.count; i++) {
Uiimage*images=[uiimage imagenamed:[rfirsts Objectatindex:i]];
UIImage *imagenew=[self originimage:images Scaletosize:cgsizemake (45, 45)];
[Rfirst addobject:imagenew];
}
Self.rfirstary = [Rfirst copy];
Nsarray *rseconds = @[@ "Gc6.png", @ "Gc7.png", @ "Gc8.png"];
Nsmutablearray *rsecond=[[nsmutablearray alloc]initwithcapacity:0];
for (int i=0; i<rseconds.count; i++) {
Uiimage*images=[uiimage Imagenamed:[rseconds Objectatindex:i]];
UIImage *imagenew=[self originimage:images Scaletosize:cgsizemake (45, 45)];
[Rsecond addobject:imagenew];
}
Self.rsecondtary = [Rsecond copy];
[Self SetExtraCellLineHidden:self.squareTableCell];
}
ios-changing the size of a picture