2013-03-26 33 views
0

使用的PhoneGap和android,我得到一個用戶進行拍照,然後顯示預覽對他們說:導入現有的照片尺寸更小 - 的PhoneGap的Android

var img = new Image(); 
img.src= imageUri; 
$("#dialogContent").prepend(img); 

它工作正常。然而,在功能強大的現代手機與超級強大的相機[如銀河S3]由於文件大小崩潰的應用程序。

我想要的是能夠導入我以較小尺寸拍攝的照片,但保留原始照片的全尺寸(因爲我要上傳它)。

事情是這樣的:

var maxSize = Math.max(screen.width, screen.height); 
targetHeight: maxSize, 
targetWidth: maxSize, 

是否有使用「navigator.camera.getPicture」如果你已經知道了fileURI的一種方式?

回答

-1
File file=new File("your path"); 

Bitmap screen = BitmapFactory.decodeFile(file);    
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
screen.compress(Bitmap.CompressFormat.JPEG, 15, bytes); 
+0

看起來不錯,但它看起來像是Java,我正在使用Phonegap(它使用JS鉤入一些android apis)。 – Richard 2013-03-26 15:23:28