From 3ee8852b73624373d2ace2c3d36880df0e9293ed Mon Sep 17 00:00:00 2001 From: "rohitrao@chromium.org" Date: Mon, 24 Sep 2012 23:28:13 +0000 Subject: Properly flip the CGContext during UIImage->SkBitmap conversions. Skia's origin is in the upper-left whereas CG's origin is in the lower-left, so the CGContext needs to be flipped in order to prevent the resulting image from being upside-down. TBR=thakis@chromium.org BUG=None TEST=None Review URL: https://chromiumcodereview.appspot.com/10963064 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@158441 0039d316-1c4b-4281-b951-d872f2087c98 --- skia/ext/skia_utils_ios.mm | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'skia/ext') diff --git a/skia/ext/skia_utils_ios.mm b/skia/ext/skia_utils_ios.mm index 9d4c14a..a52a998 100644 --- a/skia/ext/skia_utils_ios.mm +++ b/skia/ext/skia_utils_ios.mm @@ -47,6 +47,12 @@ SkBitmap UIImageToSkBitmap(UIImage* image, CGSize size, bool is_opaque) { if (!context) return bitmap; + // We need to invert the y-axis of the canvas so that Core Graphics drawing + // happens right-side up. Skia has an upper-left origin and CG has a lower- + // left one. + CGContextScaleCTM(context, 1.0, -1.0); + CGContextTranslateCTM(context, 0, -size.height); + // UIGraphicsPushContext be called from the main thread. // TODO(rohitrao): We can use CG to make this thread safe, but the mac code // calls setCurrentContext, so it's similarly limited to the main thread. -- cgit v1.1