标签: uiimageview

iPhone:在AspectFt之后获取图像的大小

真的很奇怪的一个被卡住但奇怪的是我.

你有一个imageView包含图像.你缩小尺寸,imageView然后告诉它使用UIViewContentModeScaleAspectFit.所以你imageView可能是300乘200但你的缩放图像可能是300乘118或228乘200因为它aspectfit.

你到底如何得到实际图像的大小?
imageView.image.size是原始图像的大小.
imageview.frameimageview不包含图像的框架.
imageview.contentstretch也不起作用

iphone uiimageview

25
推荐指数
3
解决办法
1万
查看次数

UITapGestureRecognizer无法在UIImageView中运行

我有以下代码:

UITapGestureRecognizer *showStoryTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showNewsStory:)];
[showStoryTapRecognizer setDelegate:self];
[self.storyImageView_ addGestureRecognizer:showStoryTapRecognizer];
[showStoryTapRecognizer release];
Run Code Online (Sandbox Code Playgroud)

然而这并没有触发showNewsStory,为什么会这样呢?我在图像视图中启用了userInteraction.

iphone objective-c uiimageview ipad ios

25
推荐指数
4
解决办法
2万
查看次数

在UIViewContentModeScaleAspectFit之后获取已调整大小的图像的宽度

我有我的UIImageView,我把一个图像放入其中,我调整大小如下:

UIImageView *attachmentImageNew = [[UIImageView alloc] initWithFrame:CGRectMake(5.5, 6.5, 245, 134)];
attachmentImageNew.image = actualImage;
attachmentImageNew.backgroundColor = [UIColor redColor];
attachmentImageNew.contentMode = UIViewContentModeScaleAspectFit;
Run Code Online (Sandbox Code Playgroud)

我尝试UIImageView通过这样做获得调整大小的图片的宽度:

NSLog(@"Size of pic is %f", attachmentImageNew.image.size.width);
Run Code Online (Sandbox Code Playgroud)

但它实际上返回原始图片的宽度.关于如何获得我在屏幕上看到的图片框架的任何想法?

编辑:这是我的UIImageView外观,红色区域是它的backgroundColor

在此输入图像描述

iphone cocoa-touch objective-c uiimageview ios

25
推荐指数
1
解决办法
2万
查看次数

iOS 8照片框架.访问照片元数据

我期待在更换ALAssetsLibraryPhotos框架在我的应用程序.

我可以很好地检索照片,集合和资源(甚至可以将它们写回来),但是看不到任何地方可以访问照片的元数据({Exif},{TIFF},{GPS}等字典,等等...).

ALAssetsLibrary有办法.UIImagePickerController有办法.Photos也必须有办法.

我看到它PHAsset有一个location属性可以用于GPS词典,但我希望访问所有的元数据,包括面部,方向,曝光,ISO和吨更多.

目前苹果处于测试阶段2.也许还有更多的API需要推出?

UPDATE

没有官方的方法只使用Photos API来做到这一点.

但是,您可以在下载图像数据后读取元数据.有几个方法来做到这一点使用两种PHImageManagerPHContentEditingInput.

PHContentEditingInput方法需要较少的代码,不需要您导入ImageIO.我把它包装在PHAsset类别中.

iphone uiimageview ios alassetslibrary ios8

25
推荐指数
5
解决办法
3万
查看次数

UIImageView手势(缩放,旋转)问题

我想对UIImageView缩放,旋转进行2次操作,我有2个问题:

答:我为ex做了缩放操作.当我尝试进行旋转时,将UIImageView其设置为初始大小,我想知道如何保持缩放UIImageView并从缩放图像进行旋转.

B.我想将缩放操作与旋转相结合,我不知道如何实现这一点:

- (void)viewDidLoad 
{
    foo = [[UIImageView alloc]initWithFrame:CGRectMake(100.0, 100.0, 600, 800.0)];
    foo.userInteractionEnabled = YES;
    foo.multipleTouchEnabled  = YES;
    foo.image = [UIImage imageNamed:@"earth.jpg"];
    foo.contentMode = UIViewContentModeScaleAspectFit;
    foo.clipsToBounds = YES;

    [self.view addSubview:foo];
}

//---pinch gesture--- 
UIPinchGestureRecognizer *pinchGesture =
[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
[foo addGestureRecognizer:pinchGesture]; 
[pinchGesture release];

//---rotate gesture--- 
UIRotationGestureRecognizer *rotateGesture =
[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotateGesture:)];
[foo addGestureRecognizer:rotateGesture]; 
[rotateGesture release];

//---handle pinch gesture--- 
-(IBAction) handlePinchGesture:(UIGestureRecognizer *) sender {
    NSLog(@"Pinch");
    CGFloat factor = [(UIPinchGestureRecognizer *) …
Run Code Online (Sandbox Code Playgroud)

iphone zoom rotation uiimageview pinch

24
推荐指数
3
解决办法
3万
查看次数

有效地检测仅触摸UIImageView的非透明像素

你如何才能有效地检测到a的非透明像素上的触摸UIImageView

考虑下面的图像,显​​示为UIImageView.目标是仅在触摸发生在图像的非透明(在这种情况下为黑色)区域时使手势识别器响应.

在此输入图像描述

思路

  • 覆盖hitTest:withEvent:或者pointInside:withEvent:,尽管这种方法可能非常低效,因为这些方法在触摸事件期间被多次调用.
  • 检查单个像素是否透明可能会产生意外结果,因为手指大于一个像素.检查命中点周围的像素圆形区域,或尝试找到朝向边缘的透明路径可能会更好.

奖金

  • 区分图像的外部和内部透明像素会很好.在该示例中,零内的透明像素也应被视为有效.
  • 如果图像有变换会发生什么?
  • 图像处理可以硬件加速吗?

iphone image-processing uiimageview hittest ios

24
推荐指数
2
解决办法
8978
查看次数

如何在iOS中的UIImageView中裁剪圆圈内的图像

我有一个应用程序,我有一个UIImageView显示主图像和另一个UIImageView被用作掩码,显示一个透明的圆形和不透明的外面,这个圆圈可以使用a移动UIPanGestureRecognizer,我想知道一个方法来裁剪里面的图像将圆圈变成新的图像.这是附加的代码和屏幕截图

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    // create pan gesture

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self
                                                                          action:@selector(handlePan:)];
    [self.view addGestureRecognizer:pan];


    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = [[self makeCircleAtLocation:self.view.center radius:100.0] CGPath];
    shapeLayer.strokeColor = [[UIColor clearColor] CGColor];
    shapeLayer.fillColor = nil;
    shapeLayer.lineWidth = 3.0;

    // Add CAShapeLayer to our view

    [self.view.layer addSublayer:shapeLayer];

    // Save this shape layer in a class property for future reference,
    // namely so we …
Run Code Online (Sandbox Code Playgroud)

uiimageview ios

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

Swift UIImageView Stretched Aspect

UIImageView错误地渲染图像的大小.使用Scale Aspect Fit,如果UIImageView是正方形,则图像是正确的宽高比,在图像未填充的区域中具有透明度.

//Image is Square & Correct Size
var imageView = UIImageView(frame: CGRectMake(0, 50, 320, 320))
imageView.clipsToBounds = true
imageView.contentMode = UIViewContentMode.ScaleAspectFit

//Image is Rectangle & Incorrect Size
var imageView = UIImageView(frame: CGRectMake(0, 50, 320, 450))
imageView.clipsToBounds = true
imageView.contentMode = UIViewContentMode.ScaleAspectFit
Run Code Online (Sandbox Code Playgroud)

UIImageView需要触摸边缘并在屏幕的顶部和底部具有透明空间,并且内部图像需要保持其原始比率而不是拉伸更高.我附上了两张UIImageView内部图像渲染图像.

ImageView具有正确的Aspect ImageView有错误的Aspect

objective-c uiimageview ios swift

24
推荐指数
4
解决办法
6万
查看次数

从CMSampleBufferRef创建的UIImage没有显示在UIImageView中?

我正试图从相机实时显示UIImage,看来我的UIImageView没有正确显示图像.这是AVCaptureVideoDataOutputSampleBufferDelegate必须实现的方法

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
       fromConnection:(AVCaptureConnection *)connection
{ 
    // Create a UIImage from the sample buffer data
    UIImage *theImage = [self imageFromSampleBuffer:sampleBuffer];
//    NSLog(@"Got an image! %f %f", theImage.size.width, theImage.size.height);
//    NSLog(@"The image view is %@", imageView);
//    UIImage *theImage = [[UIImage alloc] initWithData:[NSData 
//        dataWithContentsOfURL:[NSURL 
//        URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]];
    [self.session stopRunning];
    [imageView setImage: theImage];
}
Run Code Online (Sandbox Code Playgroud)

为了解决容易出错的问题:

  • 使用UIImagePickerController不是一个选项(最终我们将实际使用图像做事)
  • 我知道正在调用处理程序(NSLog调用已经完成,我看到了输出)
  • 我知道我已正确设置了IBOutlet声明.如果我使用上面的注释代码从Web加载任意图像而不是简单地发送setImage:theImage到imageView,则图像被正确加载(并且第二次调用NSLog报告非零对象).
  • 至少在基本范围内,我得到的图像imageFromSampleBuffer:很好,因为NSLog报告的大小为360x480,这是我预期的大小.

我正在使用的代码是最近发布的AVFoundation苹果公司提供片段在这里.

特别是,这是我用来设置AVCaptureSession对象和朋友的代码(我很少理解),并从Core Video缓冲区创建UIImage对象(这就是imageFromSampleBuffer方法).

最后,我可以让应用程序崩溃,如果我尝试发送drawInRect:到一个普通的UIView子类与UIImage …

iphone avfoundation uiimageview uiimage ios4

23
推荐指数
4
解决办法
2万
查看次数

如何使用IBDesignable UIImageView在prepareForInterfaceBuilder中加载图像

我想在IB设计中加载样本图像,UIImageView在编辑界面时在Interface Builder中显示.以下代码不起作用,因为IB中的视图占位符保持为空(视图区域仅包含UIImageView文本):

@IBDesignable
class TestImageView : UIImageView
{
    override func prepareForInterfaceBuilder() {
        //let bundle = NSBundle.mainBundle()
        let bundle = NSBundle(forClass: nil)
        let imagePath = bundle.pathForResource("Test", ofType: "jpg")
        self.image = UIImage(contentsOfFile: imagePath)
    }
}
Run Code Online (Sandbox Code Playgroud)

注意:

  • 在IB中,视图的Custom Class类是正确的(TestImageView)
  • Test.jpg存在于项目中(如果我手动设置UIImageViewIB中图像属性的图像显示).
  • 我尝试了两种不同的方法来获取代码中的包

这是用Xcode 6 beta 3测试的.

更新:在这两种情况下,我获得的捆绑路径是"/Applications/Temporary/Xcode6-Beta3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Overlays".在该路径中,图像显然不存在.

uiimageview ios swift

23
推荐指数
5
解决办法
1万
查看次数