-(uiimage *)grayimage:(uiimage *)sourceimage
{
int bitmapinfo = kcgimagealphanone;
int width = sourceimage.size.width;
int hight = sourceimage.size.height;
cgcolorspaceref colorspace = cgcolorspacecreatedevicegray();
cgcontextref contect = cgbitmapcontextcreate(nil, width, hight, 8, 0, colorspace, bitmapinfo);
cgcolorspacerelease(colorspace);
if (contect == null) {
return nil;
}
cgcontextdrawimage(contect, cgrectmake(0, 0, width, hight), sourceimage.cgimage);
uiimage *grayimage = [uiimage imagewithcgimage:cgbitmapcontextcreateimage(contect)];
cgcontextrelease(contect);
return grayimage;
}