0
我使用ASIHTTP到POST數據到服務器,並在接收到所有的數據,因爲它應該ASIHTTP上傳白色圖像
我上傳與
[request1 setData:imageData withFileName:@"upload.png" andContentType:@"image/png" forKey:@"Image"];
圖像這裏的imageData是NSData的
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"] ;
UIGraphicsBeginImageContext(CGSizeMake(320,480));
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGSize kMaxImageViewSize = {.width = 100, .height = 100};
//[self resizeImage:newImage newSize:kMaxImageViewSize];
imageData=UIImageJPEGRepresentation([self resizeImage:newImage newSize:kMaxImageViewSize], 0.5);
}
- (UIImage *)resizeImage:(UIImage*)image newSize:(CGSize)newSize {
CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
CGImageRef imageRef = image.CGImage;
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// Set the quality level to use when rescaling
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height);
CGContextConcatCTM(context, flipVertical);
// Draw into the context; this scales the image
CGContextDrawImage(context, newRect, imageRef);
// Get the resized image from the context and a UIImage
CGImageRef newImageRef = CGBitmapContextCreateImage(context);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
CGImageRelease(newImageRef);
UIGraphicsEndImageContext();
return newImage;
}
這是我如何重新調整圖像的大小。我的問題是,當圖像被保存在服務器上時,我只是得到一個白色的圖像,空白的一個。它是一個服務器的問題,或者也可以是我不發送表單應用程序
編輯 這裏是我的服務器代碼
$filename="upload";
$target_path = "uploads/";
$target_path = $target_path .$filename.".png";
if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
echo "uploaded an image";
} else{
echo "There was an error uploading the file, please try again!";
}
我做這種方式爲我工作。謝謝 – SALMAN 2012-07-09 21:02:37
沒有幫助。從我可以看到的方式來看,這可能是服務器(php)問題 – Spire 2012-07-11 02:47:15
@Spire是的!如果它仍然無法正常工作,那麼webservice端必須存在問題?你有php的代碼結束了嗎?我可以爲你解決這個問題。謝謝 – SALMAN 2012-07-11 07:37:51