iphone - CGBitmapContextCreateImage on flipped context -
i've got context, on i've performed drawing. want save result. because of inverted context y-axis first want flip everything, create image:
// 1. flip y cgcontexttranslatectm(context, 0, height); cgcontextscalectm(context, 1.0, -1.0); // 2. create image cgimageref rawmask = cgbitmapcontextcreateimage(context);
however image not flipped. if change order of action 1 2, image still not flipped. can't understand why , how fix it. more important 'why', because in logic, if flip context upside down drawing, should ok.
the ctm affects drawing operations perform after set ctm. say, changing ctm can change pixels modified subsequent drawing operations.
the ctm not affect cgbitmapcontextcreateimage
directly. cgbitmapcontextcreateimage
copies pixels out of context image. doesn't @ ctm @ all.
thus have omitted critical part of program question: part modifies pixels. correct order this:
// 1. flip y axis. cgcontexttranslatectm(context, 0, height); cgcontextscalectm(context, 1.0, -1.0); // 2. draw context. example: cgcontextbeginpath(context); cgcontextaddellipseinrect(context, somerect); cgcontextsetfillcolorwithcolor(context, ...); cgcontextfillpath(context); // 3. create image. cgimageref rawmask = cgbitmapcontextcreateimage(context);
Comments
Post a Comment