Tag: 图片上传

Android – 缩小图像文件大小

我有一个URI图像文件,我想减小它的大小来上传它。 初始图像文件的大小取决于手机到手机(可以是2MB,可以是500KB),但是我希望最终大小约为200KB,以便我可以上传它。 从我读到的,我有(至less)2个select: 使用BitmapFactory.Options.inSampleSize ,对原始图像进行二次采样并获得较小的图像; 使用Bitmap.compress压缩指定压缩质量的图像。 什么是最好的select? 我正在考虑最初调整图像宽度/高度,直到宽度或高度超过1000像素(如1024×768等),然后压缩图像质量下降,直到文件大小超过200KB。 这是一个例子: int MAX_IMAGE_SIZE = 200 * 1024; // max final file size Bitmap bmpPic = BitmapFactory.decodeFile(fileUri.getPath()); if ((bmpPic.getWidth() >= 1024) && (bmpPic.getHeight() >= 1024)) { BitmapFactory.Options bmpOptions = new BitmapFactory.Options(); bmpOptions.inSampleSize = 1; while ((bmpPic.getWidth() >= 1024) && (bmpPic.getHeight() >= 1024)) { bmpOptions.inSampleSize++; bmpPic = BitmapFactory.decodeFile(fileUri.getPath(), bmpOptions); […]

如何在iOS中发布更多的图片上传代码参数?

您好我正在上传图像的PHP服务器,并成功上传与此代码的帮助 – (NSString*)uploadData:(NSData *)data toURL:(NSString *)urlStr:(NSString *)_userID { // File upload code adapted from http://www.cocoadev.com/index.pl?HTTPFileUpload // and http://www.cocoadev.com/index.pl?HTTPFileUploadSample NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:urlStr]]; [request setHTTPMethod:@"POST"]; // NSString* = [NSString stringWithString:@"0xKhTmLbOuNdArY"]; NSString *stringBoundary = [NSString stringWithString:@"—————————14737809831466499882746641449"]; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",stringBoundary]; [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; NSMutableData *body = [NSMutableData data]; […]