2011-04-04 67 views
1

我嘗試將黑白色UIImage轉換爲IplImage,但是從控制檯給出這些。不能做什麼?uimage to iplimage

CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 16 bits/pixel; 1-component color space; kCGImageAlphaPremultipliedLast; 84 bytes/row. 

CGContextDrawImage: invalid context 0x0. 


notaImage = [UIImage imageWithCGImage:drawImage]; 
     //UIImageWriteToSavedPhotosAlbum(notaImage, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil); 
     vec_iphone.push_back(notaImage);  
     CGImageRef i_Ref = notaImage.CGImage; 

     CGColorSpaceRef color_S = CGColorSpaceCreateDeviceGray(); 
      // Creating temporal IplImage for drawing 
     IplImage *nota_img = cvCreateImage(
            cvSize(notaImage.size.width,notaImage.size.height), IPL_DEPTH_8U, 1 
           ); 
      // Creating CGContext for temporal IplImage 
     CGContextRef c_Ref = CGBitmapContextCreate(
             nota_img->imageData, nota_img->width, nota_img->height, 
             nota_img->depth, nota_img->widthStep, 
             color_S, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault 
            ); 

      // Drawing CGImage to CGContext 
      CGContextDrawImage(
           c_Ref, 
           CGRectMake(0, 0, notaImage.size.width, notaImage.size.height), 
           i_Ref 
           ); 

      // 


      vec_images.push_back(nota_img); 
      CGContextRelease(c_Ref); 
      CGColorSpaceRelease(color_S); 
      CGImageRelease(i_Ref); 

回答

1

作爲輸入圖像是灰色的,您的上下文格式不包含任何alpha通道,因此使用kCGImageAlphaPremultipliedLast是不正確的。改爲嘗試kCGImageAlphaNone