ios-changing the size of a picture

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.