2015-03-25 77 views
0

你好,此時相機拍攝圖像大小超過1mb。我想把它縮小到20kb。請幫幫我。如何縮小basic4android中的jpeg圖像大小

Sub Camera1_PictureTaken (Data() As Byte) 
    camera1.StartPreview 
    DateTime.DateFormat ="HH.mm.ss.SS_dd-MM-yy_" 
    forDate=DateTime.Date(DateTime.now) 
    imei = pID.GetDeviceId 

    filename = forDate & imei& "_.jpeg" 
    File.MakeDir(File.DirRootExternal,"/data/data/a3a/cam/update/images") 
    out = File.OpenOutput(File.DirRootExternal,"/data/data/a3a/cam/update/images/"&filename, False) 
    out.WriteBytes(Data, 0, Data.Length) 
    out.Close 
End Sub 

回答

0

您可以將RSImageProcessing庫添加到您的項目。

該代碼將是光明的你的心:)沒有圖書館

Sub ReSize(b As Bitmap, newWidth As Int, newHeight As Int) As Bitmap 
    Dim r As RSImageProcessing 
    Return r.scaleBitmap(b, newWidth, newHeight) 
End Sub 
1

方法:

Sub UploadImage(Dir As String, Filename As String) As Byte() 
    Dim Image As Bitmap = LoadBitmapSample(Dir, Filename, 1920, 1080) 
    Dim Out As OutputStream 
    Out.InitializeToBytesArray(100) 
    Image.WriteToStream(Out, 90, "JPEG") 
    Return Out.ToBytesArray 
End Sub