- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在传真类型的 iOS 应用程序中使用相机,在这种情况下,图像往往会变得很大,并导致传真网络服务明显延迟。我没有嫁给更好的图像质量。我的问题是如何降低分辨率/减小文件大小,使其成为较小文件大小的图像?
#import <UIKit/UIKit.h>
//Definition of the delegate's interface
@protocol SnapShotViewControllerDelegate
-(void)selectedFileName:(NSString*)filename;
@end
@interface SnapShotViewController : UIViewController<UINavigationControllerDelegate,UIImagePickerControllerDelegate> {
IBOutlet UIButton *button;
IBOutlet UIImageView *image;
UIImagePickerController *imgPicker;
}
- (IBAction)grabImage;
- (IBAction)useImage;
@property (nonatomic, retain) UIImagePickerController *imgPicker;
@property (nonatomic,retain)UIImageView *image;
@property (nonatomic,retain)UIButton *button;
@property (nonatomic, assign) id<SnapShotViewControllerDelegate> delegate;
@end
#import "SnapShotViewController.h"
#import "PDFImageConverter.h"
@implementation SnapShotViewController
@synthesize imgPicker, image, button;
@synthesize delegate=_delegate;
- (IBAction)grabImage{
[self presentModalViewController:self.imgPicker animated:YES];
}
- (IBAction)useImage{
if ([image image]==nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Image Found" message:@"Click 'Grab Image' to take a snapshot first" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}else {
//do something with file
[self.delegate selectedFileName: filename];
[self.navigationController popViewControllerAnimated:YES];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
[image setImage:img];
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
if (imgPicker == nil) {
self.imgPicker = [[[UIImagePickerController alloc] init] autorelease];
}
//self.imgPicker.allowsImageEditing = YES;
imgPicker.delegate =self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}else
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.image = nil;
self.button = nil;
}
- (void)dealloc {
[imgPicker release];
[image release];
[button release];
[super dealloc];
}
@end
最佳答案
我忘记了我在哪里看到这段代码(也许在 SO 上)
我从 this thread 得到这段代码在我从 iPhone 相机获取图像后,我在我的一个应用程序中使用它:
CGSize newImageSize = CGSizeMake(100, 133);
self.studentPic.image = student.pic = [StudentInfo imageWithImage:[info objectForKey:UIImagePickerControllerOriginalImage] scaledToSize:newImageSize];
+ (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;
{
// Create a graphics image context
UIGraphicsBeginImageContext(newSize);
// Tell the old image to draw in this new context, with the desired
// new size
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
// Get the new image from the context
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
// End the context
UIGraphicsEndImageContext();
// Return the new image.
return newImage;
}
关于objective-c - 如何减小使用相机拍摄的快照的文件大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6644645/
我是 R 新手,我正在使用 glmer 来拟合几个二项式模型,我只需要它们来调用 predict使用得到的概率。但是,我有一个非常大的数据集,即使只有一个模型的大小也会变得非常大: > library
我有一个包含数百个项目的直方图,我为其绘制了 Q-Q 图。这导致 EPS 大小为 2.5 兆字节。对于仅包含在出版物中并且不会以 100 倍放大倍率查看的图形来说,这太大了。 R 中是否有任何选项可以
我有一个 。 mp4 文件大小为 的视频540kb 并且在转换之前的持续时间为 30 秒,但是当我使用 时ffmpeg 将其转换为文件大小变为 21mb .我需要添加哪些选项才能将文件大小减小到小于
因此,我们有一个非常庞大且复杂的网站,需要在 URL 中放置大量状态信息。大多数时候,这只是桃子,应用程序运行良好。但是,有(越来越多的)URL 长度变得非常长的实例。由于 URL 长度限制,这会在
有没有办法减少分组 UITableViewCell 的标准宽度并将自定义按钮放在左侧(单元格边界之外)?我尝试更改单元格大小,但它保持不变 最佳答案 你将不得不伪造编辑模式。我的意思是,正如 Atom
我的项目中有大约 1000 张图像,图像总大小约为 400MB。我正在使用此图像在 MAc 上显示缩略图。 构建 xcode 后,我的应用程序构建大小为 410MB。我正在使用 NSImage ima
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
当我编译我的 Snap 时webapp(将其部署到生产服务器),结果为 19MB!是什么赋予了?这是正常的吗?我做错了什么吗? 我的网站只有3个静态页面,基本上是snap's init project
在我们的项目中,我们决定通过使用预构建的二进制文件来减少构建时间。我们每周/每月创建一个稳定版本并将其提交到存储库。构建使用这些二进制文件,而不是从源代码构建所有内容。 对于构建速度来说,这太棒了。但
我必须创建一个自定义 jdialog,但我希望它小一点。它不应该有空白空间。下面的代码给了我这个: 如果我使用 setSize 减小大小,则会导致如下所示的错误 GUI: class Find ext
这个问题已经有答案了: pyplot: Can I set a global marker size parameter? (1 个回答) How to make markers on lines s
我正在尝试在列表中聚合使用 rpart::rpart 构建的多个 CART 模型。 我刚刚意识到每个模型在 $terms 和 $where 中存储了大量(元?)数据(在我的例子中每个模型超过 10MB
当我使用 scaledToHeight 调整 QPixmap 的大小,然后将其转换为 QByteArray 时,此 ByteArray 的大小恰好是未缩放 QPixmap 的 ByteArray 的大
有没有办法设置图形的 YSTEP? 我们正在尝试显示包含以下数据的图表 g = new Dygraph( document.getElementById("graph"),
我创建了一个 xib,其中一个单元格包含 UIImageView。 imageview 具有前导、尾随、顶部、底部约束。 xib为4kb,文件大小为4kb。我以编程方式创建了另一个具有相同约束和对象的
我正在尝试将图像大小减小到小于 64000 字节这是我的代码和日志。 NSData *beforeData = UIImageJPEGRepresentation(self.photo, 1.
我正在使用 OpenSSL-for-iPhone生成我可以与库一起使用的 OpenSSL 的自编译版本 RMStoreAppReceiptVerifier用于收据验证。具体来说,它构建了 OpenSS
我目前正在按照本指南制作多标签图像分类模型(它使用初始模型作为基础模型):https://towardsdatascience.com/multi-label-image-classification
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我的 HTML 页面中有宽度超过 250 像素的下拉菜单。 我需要更改下拉菜单的字体大小以减小宽度。 我尝试使用如下字体标签: . . . 以
我是一名优秀的程序员,十分优秀!