我有一个包含一些字段(名称、价格、类别)和一个分段控件的视图,加上这个按钮来拍照。
如果我在模拟器(没有相机)上尝试这个,它可以正常工作:我可以从相机胶卷中选择图像,编辑它并返回到视图,这将显示所有字段及其内容。
但是在我的 iPhone 上,当我在编辑后选择图像并返回视图时,除了 UIImageView 之外,所有字段都是空的。我还尝试将字段的内容保存在变量中并将它们放回"viewWillApper"" 方法,但应用程序崩溃。
开始想也许下面的方法有问题
编辑
我在这里找到了解决方案。我为 UIImage 类定义了一个新方法。 (点击链接获取更多信息)。然后我在 UIImageView 的框架上工作以适应新的维度,横向或纵向。
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) { self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera; self.imgPicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto; } else { imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; } [self presentModalViewController:self.imgPicker animated:YES]; } -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissModalViewControllerAnimated:YES]; NSDate *date = [NSDate date]; NSString *photoName = [dateFormatter stringFromDate:date]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUs erDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; imagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", photoName]]; UIImage *picture = [info objectForKey:UIImagePickerControllerOriginalImage]; // ---------RESIZE CODE--------- // if (picture.size.width == 1936) { picture = [picture scaleToSize:CGSizeMake(480.0f, 720.0f)]; } else { picture = [picture scaleToSize:CGSizeMake(720.0f, 480.0f)]; } // --------END RESIZE CODE-------- // photoPreview.image = picture; // ---------FRAME CODE--------- // photoPreview.contentMode = UIViewContentModeScaleAspectFit; CGRect frame = photoPreview.frame; if (picture.size.width == 480) { frame.size.width = 111.3; frame.size.height =167; } else { frame.size.width = 167; frame.size.height =111.3; } photoPreview.frame = frame; // --------END FRAME CODE-------- // NSData *webData = UIImagePNGRepresentation(picture); CGImageRelease([picture CGImage]); [webData writeToFile:imagePath atomically:YES]; imgPicker = nil; } |
现在我有一个新问题!如果我以横向拍摄一张照片,然后尝试以纵向拍摄另一张,则应用程序会崩溃。我必须发布一些东西吗?
我也遇到了同样的问题,使用相机时没有经过编辑的图像,您必须使用原始图像:
2 3 4 5 6 | if ([editingInfo objectForKey:UIImagePickerControllerMediaMetadata]) { // test to chek that the camera was used // especially I fund out htat you then have to rotate the photo ... |
如果在使用专辑时被裁剪,你当然必须重新裁剪:
2 3 4 5 6 7 8 | CGRect cropRect = [[editingInfo objectForKey:UIImagePickerControllerCropRect] CGRectValue]; CGImageRef imageRef = CGImageCreateWithImageInRect([originalimage CGImage], cropRect); chosenimage = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); } else { chosenimage = originalimage; } |
相机模式也存在croprect信息,您需要检查您希望它的行为方式。
要裁剪图像,我认为这可能会对您有所帮助
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | CGSize size = CGSizeMake(croppedImage.size.height, croppedImage.size.width); UIGraphicsBeginImageContext(size); CGPoint pointImg1 = CGPointMake(0,0); [croppedImage drawAtPoint:pointImg1 ]; [[UIImage imageNamed:appDelegete.strImage] drawInRect:CGRectMake(0,532, 150,80) ]; UIImage* result = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); croppedImage = result; UIImageView *mainImageView = [[UIImageView alloc] initWithImage:croppedImage]; CGRect clippedRect = CGRectMake(0, 0, croppedImage.size.width, croppedImage.size.height); CGFloat scaleFactor = 0.5; UIGraphicsBeginImageContext(CGSizeMake(croppedImage.size.width * scaleFactor, croppedImage.size.height * scaleFactor)); CGContextRef currentContext = UIGraphicsGetCurrentContext(); CGContextClipToRect(currentContext, clippedRect); //this will automatically scale any CGImage down/up to the required thumbnail side (length) when the CGImage gets drawn into the context on the next line of code CGContextScaleCTM(currentContext, scaleFactor, scaleFactor); [mainImageView.layer renderInContext:currentContext]; appDelegete.appphoto = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); |
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
目前,Itembelongs_toCompany和has_manyItemVariants。我正在尝试使用嵌套的fields_for通过Item表单添加ItemVariant字段,但是使用:item_variants不显示该表单。只有当我使用单数时才会显示。我检查了我的关联,它们似乎是正确的,这可能与嵌套在公司下的项目有关,还是我遗漏了其他东西?提前致谢。注意:下面的代码片段中省略了不相关的代码。编辑:不知道这是否相关,但我正在使用CanCan进行身份验证。routes.rbresources:companiesdoresources:itemsenditem.rbclassItemi
如果我在模型中设置验证消息validates:name,:presence=>{:message=>'Thenamecantbeblank.'}我如何让该消息显示在闪光警报中,这是我迄今为止尝试过的方法defcreate@message=Message.new(params[:message])if@message.valid?ContactMailer.send_mail(@message).deliverredirect_to(root_path,:notice=>"Thanksforyourmessage,Iwillbeintouchsoon")elseflash[:error]
📢博客主页:https://blog.csdn.net/weixin_43197380📢欢迎点赞👍收藏⭐留言📝如有错误敬请指正!📢本文由Loewen丶原创,首发于CSDN,转载注明出处🙉📢现在的付出,都会是一种沉淀,只为让你成为更好的人✨文章预览:一.分辨率(Resolution)1、工业相机的分辨率是如何定义的?2、工业相机的分辨率是如何选择的?二.精度(Accuracy)1、像素精度(PixelAccuracy)2、定位精度和重复定位精度(RepeatPrecision)三.公差(Tolerance)四.课后作业(Post-ClassExercises)视觉行业的初学者,甚至是做了1~2年
我刚刚按照thebootsygempage上的安装说明进行操作在我保存并查看帖子内容之前,一切看起来都不错。这是输出在View中的样子:HeaderSubhead:似乎没有呈现任何html格式,因为它被引号或类似的东西转义了-其他人有这个问题吗?我没有在github页面或SO上看到任何问题来指出我正确的方向。除了遵循gem安装说明之外,我还没有做任何事情,但也许我错过了什么或者只是犯了一个愚蠢的错误。如果你还有什么想知道的,请尽管问。干杯 最佳答案 你需要有这样的东西,转义html: 关
我正在写一篇关于在Ruby中几乎一切都是对象的博客文章,我试图通过以下示例来展示这一点:classCoolBeansattr_accessor:beansdefinitialize@bean=[]enddefcount_beans@beans.countendend所以从类中我们可以看出它有4个方法(当然,除非我错了):它可以在创建新实例时初始化一个默认的空bean数组它可以计算它有多少个bean它可以读取它有多少个bean(通过attr_accessor)它可以向空数组写入(或添加)更多bean(也通过attr_accessor)但是,当我询问类本身它有哪些实例方法时,我没有看到默认