문제

나는 이것이 쉬운 일이 아니라고 생각하지만 Uiimageview를 결합하거나 평평하게하여 다른 uiimage view와 위에 놓여야합니다. 예를 들어 : 두 개의 uiimageviews가 있습니다. 그들 중 하나는 잔디밭 (1200 x 1200 픽셀)의 uiimage를 가지고 있습니다. 다른 하나는 농구 (128 x 128 픽셀)의 uiimage이며, 농구가 잔디밭에있는 것처럼 보이는 방식으로 잔디밭의 이미지 위에 위치합니다. 중첩 된 uiimageviews를 사진 앨범에 단일 이미지 파일로 저장할 수 있기를 원합니다. 이는 두 이미지를 어떻게 든 결합해야합니다. 이것이 어떻게 달성 될까요? (참고 : 스크린 샷 (320 x 480 픽셀)을 복용하는 것은 1200 x 1600 픽셀의 크기를 보존하기 때문에 허용되는 솔루션이 아닙니다.

의문:
여러 uiimageviews를 하나로 평평하게하고 크기/해상도를 보존하면서 결과 이미지를 저장할 수있는 방법.

도움이 되었습니까?

해결책

이것은 모든 견해를 취하고 그것으로부터 uiimage를 만듭니다. 모든보기와 하위 뷰는 디스크에 표시하거나 저장할 수있는 UIIMAGE로 "평평한"것입니다.

  - (UIImage*)imageFromView{

    UIImage *image;

    UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;

}

다른 팁

원본 UIImages를 서로 꼭대기에 배경 버퍼에 뽑은 다음 파일에 결합 된 이미지를 작성하지 않겠습니까? 아래는 동일한 버퍼에 두 개의 이미지를 그릴 수있는 방법입니다.

CGImageRef bgimage = [bguiimage CGImage];
width = CGImageGetWidth(bgimage);
height = CGImageGetHeight(bgimage);

// Create a temporary texture data buffer
GLUbyte* data = (GLubyte *) malloc(width * height * 4);
assert(data);

// Draw image to buffer
CGContextRef ctx = CGBitmapContextCreate(data, width, height, 8, width * 4, CGImageGetColorSpace(image), kCGImageAlphaPremultipliedLast);
assert(ctx);

// Flip image upside-down because OpenGL coordinates differ
CGContextTranslateCTM(ctx, 0, height);
CGContextScaleCTM(ctx, 1.0, -1.0);

CGContextDrawImage(ctx, CGRectMake(0, 0, (CGFloat)width, (CGFloat)height), bgimage);

CGImageRef ballimage = [balluiimage CGImage];
bwidth = CGImageGetWidth(ballimage);
bheight = CGImageGetHeight(ballimage);

float x = (width - bwidth) / 2.0;
float y = (height - bheight) / 2.0;
CGContextDrawImage(ctx, CGRectMake(x, y, (CGFloat)bwidth, (CGFloat)bheight), ballimage);

CGContextRelease(ctx);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top