首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >合并2个可移动的图像

合并2个可移动的图像
EN

Stack Overflow用户
提问于 2010-10-05 14:22:36
回答 1查看 764关注 0票数 0

我想合并两个图像,其中一个是心形部分透明的贺卡,另一个是一对情侣的图像。现在我希望情侣的图像可以移动,这样我就可以移动它们并调整它们的大小,以设置在心脏部分,然后我想将图像的混合保存为一个图像,并将其作为附件发送到邮件中…你能给我提供任何这样的例子或解决方案的链接吗?

任何帮助都将不胜感激。

先谢谢你...

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-10-28 21:01:44

这就是我做掩蔽的方式,这对我很有效。

代码语言:javascript
复制
- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage1
{

    float width,height;
        width=288.0;
        height=274.0;

    CGContextRef mainViewContentContext; CGColorSpaceRef colorSpace;
    UIImage *orgImage=image; 

    CGImageRef img = [orgImage CGImage];

    colorSpace = CGColorSpaceCreateDeviceRGB();

    mainViewContentContext = CGBitmapContextCreate (NULL, width, height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast); 
    CGColorSpaceRelease(colorSpace);

    if (mainViewContentContext==NULL)
        return NULL;

    CGRect subImageRect; 
    CGImageRef tileImage;
    float xCord=0;
    float yCord=0;
    subImageRect = CGRectMake(xCord,yCord,width,height);
    tileImage = CGImageCreateWithImageInRect(img,subImageRect);
    //UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage:tileImage],nil,nil,nil);
    CGImageRef maskImage = maskImage1.CGImage;
    CGContextClipToMask(mainViewContentContext, CGRectMake(0, 0, width, height), maskImage);
    CGContextDrawImage(mainViewContentContext, CGRectMake(0, 0, width, height), tileImage);
    //UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage: maskImage],nil,nil,nil);
    CGImageRef mainViewContentBitmapContext = CGBitmapContextCreateImage(mainViewContentContext);
    CGContextRelease(mainViewContentContext); 
    UIImage *theImage = [UIImage imageWithCGImage:mainViewContentBitmapContext];
    //UIImageWriteToSavedPhotosAlbum(theImage,nil,nil,nil);
    CGImageRelease(mainViewContentBitmapContext);
    return theImage;
}

这就是我移动图像的方式

代码语言:javascript
复制
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    if([timer isValid])
        [timer invalidate];

    NSSet *allTouches = [event allTouches];

    switch ([allTouches count])
    {
        case 1: {
            //The image is being panned (moved left or right)
            UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
            CGPoint centerPoint = [touch locationInView:[self view]];

            [imgView setCenter:centerPoint];

            NSLog(@"Center.x=%f Center.y=%f",centerPoint.x,centerPoint.y);


        } break;
        case 2: {
            //The image is being zoomed in or out.

            UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
            UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];

            //Calculate the distance between the two fingers.
            CGFloat finalDistance = [self distanceBetweenTwoPoints:[touch1 locationInView:[self view]] toPoint:[touch2 locationInView:[self view]]];
            NSLog(@"Initial=%f Final=%f",initialDistance,finalDistance);
            //Check if zoom in or zoom out.
            //Check if zoom in or zoom out.




            int width;
            int height;

            if(initialDistance < finalDistance) {
                NSLog(@"Zoom Out");

                zx=imgView.frame.origin.x-2.5;
                zy=imgView.frame.origin.y-2.5;
                width=imgView.frame.size.width+5;
                height=imgView.frame.size.height+5;

            }
            else
            {
                NSLog(@"Zoom In");



                zx=imgView.frame.origin.x+2.5;
                zy=imgView.frame.origin.y+2.5;
                               width=imgView.frame.size.width-5;
                               height=imgView.frame.size.height-5;

            }

            imgView.frame = CGRectMake(zx,zy,width,height);
            initialDistance = finalDistance;

        } break;
    }

}

hAPPY cODING...

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3861265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档