Reduce image size / weight

Hi all,

Once the user has taken a photo with his Android camera (I therefore retrieve a Picture object from the MobileImagePicker), I need to reduce the size/weight (mainly the weight) of the image significantly, before sending it to my server. Phone photos are so huge now…

Do you know how to do this on Android?

try this from a web app

Public Function Thumbnail(data As MemoryBlock, size As Double) As Picture
  'die kommen ja als File rein darum data
  Var pic As Picture = Picture.FromData(data)
  Return SmallPic(pic, size)
End Function

Public Function SmallPic(pic As WebPicture, size As Double) As WebPicture
  Var ratio As Double = Min(size / pic.Height, size / pic.Width)
  'Größe berechnen
  Var w As Integer = pic.Width * ratio
  Var h As Integer = pic.Height * ratio
  Var pic_out As New Picture(w,h)
  Var g As Graphics = pic_out.Graphics
  g.AntiAliased = True
  g.AntiAliasMode = Graphics.AntiAliasModes.HighQuality
  g.DrawPicture(pic, 0, 0, g.Width, g.Height, 0, 0, pic.Width, pic.Height)
  Return pic_out
End Function

with picture .ToData you can create file data


Great, thank you Markus!

1 Like