如何从 UIImageView 创建 UIImage?

发布于 2024-10-08 19:20:18 字数 2007 浏览 3 评论 0原文

我正在尝试在我的应用程序上实现一组动画图像。

NSArray *myImages = [NSArray arrayWithObjects:
    [UIImage imageNamed:@"myImage1.png"],
    [UIImage imageNamed:@"myImage2.png"],
    [UIImage imageNamed:@"myImage3.png"],
    [UIImage imageNamed:@"myImage4.gif"],
    nil];

UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:[self bounds]];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 0.25; // seconds
myAnimatedView.animationRepeatCount = 0; // 0 = loops forever
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[myAnimatedView release];

好的,但问题是我正在使用 API 函数在地图上放置标记。

该函数如下:

RMMarker *newMarker;
UIImage *blueMarkerImage = [UIImage imageNamed:@"marker.png"];
newMarker = [[RMMarker alloc] initWithUIImage:blueMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];


[mapView.contents.markerManager addMarker:newMarker AtLatLong:position];
[newMarker release];

问题是“initWithUIImage:”仅适用于 UIImage,不适用于 UIImageView。

那么,我该如何解决呢?

更新:我的新代码不起作用:

NSArray *myImages = [NSArray arrayWithObjects:                           
                         [UIImage imageNamed:@"marker0.png"],
                         [UIImage imageNamed:@"marker1.png"],
                         [UIImage imageNamed:@"marker2.png"],
                         [UIImage imageNamed:@"marker3.png"],
                         [UIImage imageNamed:@"marker4.png"],
                         nil];

    UIImageView *myAnimatedView = [UIImageView alloc];
    myAnimatedView.animationImages = myImages;
    myAnimatedView.animationDuration = 10; // seconds
    myAnimatedView.animationRepeatCount = 1; // 0 = loops forever
    [myAnimatedView startAnimating];
    RMMarker *newMarker = [[RMMarker alloc] initWithUIImage:[myAnimatedView image] anchorPoint:CGPointMake(0.5, 1.0)];
    [mapView.contents.markerManager addMarker:newMarker AtLatLong:markerPosition];

I am trying to implement an animation set of images on my application.

NSArray *myImages = [NSArray arrayWithObjects:
    [UIImage imageNamed:@"myImage1.png"],
    [UIImage imageNamed:@"myImage2.png"],
    [UIImage imageNamed:@"myImage3.png"],
    [UIImage imageNamed:@"myImage4.gif"],
    nil];

UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:[self bounds]];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 0.25; // seconds
myAnimatedView.animationRepeatCount = 0; // 0 = loops forever
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[myAnimatedView release];

Ok, but the problem is that i am using an API function to place a marker on a map.

That function is the following:

RMMarker *newMarker;
UIImage *blueMarkerImage = [UIImage imageNamed:@"marker.png"];
newMarker = [[RMMarker alloc] initWithUIImage:blueMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];


[mapView.contents.markerManager addMarker:newMarker AtLatLong:position];
[newMarker release];

The problem is that "initWithUIImage:" only works with UIImage, not with UIImageView.

So, how can i solve it??

UPDATE: My new code that is not working:

NSArray *myImages = [NSArray arrayWithObjects:                           
                         [UIImage imageNamed:@"marker0.png"],
                         [UIImage imageNamed:@"marker1.png"],
                         [UIImage imageNamed:@"marker2.png"],
                         [UIImage imageNamed:@"marker3.png"],
                         [UIImage imageNamed:@"marker4.png"],
                         nil];

    UIImageView *myAnimatedView = [UIImageView alloc];
    myAnimatedView.animationImages = myImages;
    myAnimatedView.animationDuration = 10; // seconds
    myAnimatedView.animationRepeatCount = 1; // 0 = loops forever
    [myAnimatedView startAnimating];
    RMMarker *newMarker = [[RMMarker alloc] initWithUIImage:[myAnimatedView image] anchorPoint:CGPointMake(0.5, 1.0)];
    [mapView.contents.markerManager addMarker:newMarker AtLatLong:markerPosition];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绿光 2024-10-15 19:20:18

您可以尝试使用来自 UIImageViewimage 消息:

 newMarker = 
     [
          [RMMarker alloc] 
              initWithUIImage:[myAnimatedView image] 
              anchorPoint:CGPointMake(0.5, 1.0)
     ];

或者,如果您需要创建一个 UIImageView 那么您可以尝试:

 UIImageView *newMakerImageView = 
     [[UIImageView alloc] initWithImage:
        [
          [RMMarker alloc] 
              initWithUIImage:yourImageHere
              anchorPoint:CGPointMake(0.5, 1.0)
        ]
     ];

You can try using image message from UIImageView:

 newMarker = 
     [
          [RMMarker alloc] 
              initWithUIImage:[myAnimatedView image] 
              anchorPoint:CGPointMake(0.5, 1.0)
     ];

Or, if what you need is creating a UIImageView then you can try:

 UIImageView *newMakerImageView = 
     [[UIImageView alloc] initWithImage:
        [
          [RMMarker alloc] 
              initWithUIImage:yourImageHere
              anchorPoint:CGPointMake(0.5, 1.0)
        ]
     ];
旧伤还要旧人安 2024-10-15 19:20:18
UIImageView *myAnimatedView = [UIImageView alloc] 

这可能只是一个复制/粘贴错误,但您忘记了 init。

UIImageView *myAnimatedView = [[[UIImageView alloc] initWithFrame:[self bounds]] autorelease]
UIImageView *myAnimatedView = [UIImageView alloc] 

That may just be a copy/paste error, but you forget the init.

UIImageView *myAnimatedView = [[[UIImageView alloc] initWithFrame:[self bounds]] autorelease]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文