我正在尝试将图像保存在相册中。我通过以下代码执行此操作:
CGSize targetSize =self.view.frame.size; UIGraphicsBeginImageContext(targetSize); //UIGraphicsBeginImageContextWithOptions(targetSize, NO, 2.0); // 也试过了,但没有改善 UIImage* image1 = mkImage1.image; UIImage* image2 = mkImage2.image; UIImage* image3 = mkImage3.image; CGRect rectImage1 = CGRectMake(mkImage1.frame.origin.x , mkImage1.frame.origin.y , mkImage1.frame.size.width , mkImage1.frame.size.height ); CGRect rectImage2 = CGRectMake(mkImage2.frame.origin.x , mkImage2.frame.origin.y , mkImage2.frame.size.width , mkImage2.frame.size.height ); CGRect rectImage3 = CGRectMake(mkImage3.frame.origin.x , mkImage3.frame.origin.y , mkImage3.frame.size.width , mkImage3.frame.size.height ); [image1 drawInRect:rectImage1]; // 崩溃线 [image2 drawInRect:rectImage2]; [image3 drawInRect:rectImage3]; tempImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(tempImage, nil,nil,nil);
当我尝试绘制 image1 时,我的应用程序崩溃了。但是,如果我评论那条线,所有其他图像都可以正确保存,没有任何问题..
我的日志信息给了我这个信息:
ImageIO`ImageIO_ABGR_TO_ARGB_8Bit: 0x330abc70: 推 {r4, r5, r6, r7, lr} 0x330abc72: 添加 r7, sp, #12 0x330abc74: push.w {r8, r10, r11} 0x330abc78: ldr r1, [r0] 0x330abc7a: ldr r2, [r0, #12] 0x330abc7c: cmp.w r2, r1, lsl #2 0x330abc80:blo 0x330abd06;ImageIO_ABGR_TO_ARGB_8Bit + 150 0x330abc82: ldr r3, [r0, #24] 0x330abc84: lsls r2, r1, #2 0x330abc86: cmp r3, r2 0x330abc88:blo 0x330abd06;ImageIO_ABGR_TO_ARGB_8Bit + 150 0x330abc8a: ldr r2, [r0, #4] 0x330abc8c:cmp r2,#0 0x330abc8e: beq 0x330abd06 ; ImageIO_ABGR_TO_ARGB_8Bit + 150 0x330abc90: 比克 lr, r1, #7 0x330abc94: ldr r3, [r0, #8] 0x330abc96: ldr.w r12, [r0, #20] 0x330abc9a: sub.w r4, r1, lr 0x330abc9e: asrs r5, r1, #3 0x330abca0: 移动 r6, r12 0x330abca2: 移动 r8, r3 0x330abca4:cbz r5,0x330abcbe;ImageIO_ABGR_TO_ARGB_8Bit + 78 0x330abca6: 移动 r8, r3 0x330abca8: 移动 r9, r5 0x330abcaa: 移动 r6, r12 0x330abcac:vld4.8 {d0,d1,d2,d3},[r8]! 0x330abcb0: vswp d0, d2 0x330abcb4:vst4.8 {d0,d1,d2,d3},[r6]!// EXC_BAD_ACCESS 0x330abcb8: subs.w r9, r9, #1 0x330abcbc: bne 0x330abeac ; slab_dealloc + 132 0x330abcbe: cmp lr, r1 0x330abcc0: bge 0x330abcf8 ; ImageIO_ABGR_TO_ARGB_8Bit + 136 0x330abcc2: add.w r8, r8, #2 0x330abcc6:添加 r6,#2 0x330abcc8: 移动 r9, r4 0x330abcca: ldrb.w r11, [r8] 0x330abcce: subs.w r9, r9, #1 0x330abcd2: ldrb r10, [r8, #-2] 0x330abcd6: strb r11, [r6, #-2] 0x330abcda: ldrb r11, [r8, #-1] 0x330abcde: strb r11, [r6, #-1]
//******************/// 线程 1,队列:com.apple.main-thread 0x32ac2526 in -[UIImage drawInRect:] () -[MyAppViewController saveToAlbum] 中的 0x00018e32
当我将该图像从 png 转换为 jpg 时,一切正常。但我只想保存 png 格式。