PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data,Camera camera) {
FileOutputStream outStream = null;
currentFilename = String.format("%d",System.currentTimeMillis());
outStream = new FileOutputStream("/sdcard/" + currentFilename + ".jpg");
outStream.write(data);
outStream.close();
}
};
public void uploadPhoto() {
try {
// Create HttpPost
HttpPost post = new HttpPost("http://www.example.com/upload.PHP");
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_1);
MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );
// Add the Picture as "userfile"
entity.addPart( "userfile",new FileBody(
new File( "/sdcard/",currentFilename + ".jpg" ),"image/jpeg")
);
// Send the data to the server
post.setEntity( entity );
client.execute( post );
} catch (Exception e) {
// catch
} finally {
// finally
}
}
这适用于运行Android 2.2.2和运行Android 2.3.4的Droid X的LG Optimus V
但是 – 拥有运行2.3.4的HTC Evo(与我的Droid X相同)的用户正在体验到,当她们保存到手机时(以及当他们到达服务器时),她上传的所有照片都会被打乱.图像看起来像一串锯齿状的彩色线条.
关于这里可能发生什么以及可以采取哪些措施来解决问题的任何想法?
更新:
我能够访问这款手机,当我从sdcard中取出jpg文件时,它说文件大小为3.5 – 4.0 MB,但是它们无法打开并且可能已损坏……但另一方面的文件手机正常工作.
最佳答案
原文链接:https://www.f2er.com/android/430643.html