相关疑难解决方法(0)

如何将UIImage旋转90度?

我有一个UIImageUIImageOrientationUp(纵向),我想通过90度逆时针旋转(景观).我不想用CGAffineTransform.我想要UIImage实际转移位置的像素.我正在使用一段代码(如下所示),最初是为了调整大小UIImage来执行此操作.我将目标大小设置为当前大小UIImage但是我得到一个错误:

(错误):CGBitmapContextCreate:无效数据字节/行:对于8个整数位/组件,3个组件,kCGImageAlphaPremultipliedLast,应该至少为1708.

(每当我提供SMALLER尺寸作为目标尺寸BTW时,我都不会收到错误).如何UIImage在保留当前尺寸的同时仅使用核心图形功能旋转我的90度CCW?

-(UIImage*)reverseImageByScalingToSize:(CGSize)targetSize:(UIImage*)anImage
{
    UIImage* sourceImage = anImage; 
    CGFloat targetWidth = targetSize.height;
    CGFloat targetHeight = targetSize.width;

    CGImageRef imageRef = [sourceImage CGImage];
    CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
    CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageRef);

    if (bitmapInfo == kCGImageAlphaNone) {
        bitmapInfo = kCGImageAlphaNoneSkipLast;
    }

    CGContextRef bitmap;

    if (sourceImage.imageOrientation == UIImageOrientationUp || sourceImage.imageOrientation == UIImageOrientationDown) {
        bitmap = CGBitmapContextCreate(NULL, targetHeight, targetWidth, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);

    } else {


        bitmap = CGBitmapContextCreate(NULL, targetWidth, …
Run Code Online (Sandbox Code Playgroud)

core-graphics objective-c uikit uiimage ios

174
推荐指数
11
解决办法
17万
查看次数

iPhone SDK:方向(横向和纵向视图)

好的,我有我的普通应用程序处于纵向模式.我可以强制我的应用程序转到横向模式的视图(使用navigationcontroller和viewcontroller),如下所示:

- (void)viewWillAppear:(BOOL)animated {
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
Run Code Online (Sandbox Code Playgroud)

但是当我回到主菜单(tableview)时,它会直接回到肖像.我试试这段代码:

- (void)viewWillAppear:(BOOL)animated {
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}
Run Code Online (Sandbox Code Playgroud)

但这不起作用..

有任何想法吗?

cocoa-touch

9
推荐指数
2
解决办法
5万
查看次数

在Quartz中旋转图像?图像是颠倒的!(苹果手机)

  • 我不想改变整个上下文.

我正在用Quartz制作一个游戏,我正在用线条,椭圆和椭圆来绘制我的播放器.

然后我有diamong.png,我在屏幕左上角的0,0渲染.

问题是......

它呈现颠倒!

我怎么旋转180度?

这是我的一些代码:

CGImageRef diamondImage = CGImageRetain([UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"Diamond.png" ofType:nil]].CGImage);
CGContextDrawImage(context, CGRectMake(0, 0, 32, 24), diamondImage);
Run Code Online (Sandbox Code Playgroud)

如果它有任何帮助,我正在使用横​​向模式,右侧有主页按钮.它在我的.plist和我的ViewController中定义

-shouldAutorotateToInterfaceOrientation:interfaceOrientation:

我该如何旋转/转换它?

iphone image objective-c rotation quartz-graphics

0
推荐指数
1
解决办法
3496
查看次数