gpt4 book ai didi

ios - 如何将完整数据写入 UIImage 到 NSOutputStream

转载 作者:行者123 更新时间:2023-11-28 21:54:14 25 4
gpt4 key购买 nike

如何将带有完整数据的 UIImage 发送到 NSOutputStream。我试过这段代码但输出不写完整的图像。如何将图像的完整数据发送到输出。

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
NSData *imgData = UIImageJPEGRepresentation(image, 0.2);

NSMutableData *completeData = [[NSMutableData alloc] initWithBytes:[stringData bytes] length:[stringData length]];
[completeData appendData:imgData];

NSInteger bytesWritten = 0;
while ( imgData.length > bytesWritten )
{
while ( ! self.outputStream.hasSpaceAvailable )
[NSThread sleepForTimeInterval:0.05];

//sending NSData over to server
NSInteger writeResult = [self.outputStream write:[imgData bytes]+bytesWritten maxLength:[imgData length]-bytesWritten];
if ( writeResult == -1 )
NSLog(@"error code here");
else
bytesWritten += writeResult;
}
}

最佳答案

您只发送imgData

  NSData *imgData = UIImageJPEGRepresentation(image, 0.2);

NSMutableData *completeData = [[NSMutableData alloc] initWithBytes:[stringData bytes] length:[stringData length]];
[completeData appendData:imgData];

NSInteger bytesWritten = 0;
while ( completeData.length > bytesWritten )
{
while ( ! self.outputStream.hasSpaceAvailable )
[NSThread sleepForTimeInterval:0.05];

//sending NSData over to server
NSInteger writeResult = [self.outputStream write:[completeData bytes]+bytesWritten maxLength:[completeData length]-bytesWritten];
if ( writeResult == -1 )
NSLog(@"error code here");
else
bytesWritten += writeResult;
}

关于ios - 如何将完整数据写入 UIImage 到 NSOutputStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27164987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com