rotate image from cam and save

stefanoa

Active Member
Licensed User
Longtime User
i have this code to take a photo from cam (with ACL - Advanced Camera Library)
how can i rotate of 90°???

Sub PhotoButton_Click
PhotoButton.Enabled = False
objCamera.TakePicture '--- take photo (not TakePicture2 because too big...)
End Sub

Sub objCamera_PictureTaken(Data() As Byte)

root=File.DirRootExternal
path1 = root & "/DCIM/Camera"

objCamera.StartPreview
blnIsCameraInPreview = True

'---->>> HOW ROTATE OF 90° ???? <<---------

'--- write image ---
Dim out As OutputStream
out = File.OpenOutput(path1, newFilename, False)
out.WriteBytes(Data, 0, Data.Length)
out.Close
end sub
 

birnesoft

Active Member
Licensed User
Longtime User
Solution to rotate the Foto from Camera

The best way I found,
first scale it to a square of picturewidth^2, (if not you get crazy :sign0135:)
rotate it and scale it down to the new size.

Sub Camera1_PictureTaken (Data() As Byte)

Dim fn As String
root=File.DirRootExternal
path1 = root & "/DCIM/Camera"
fn="TEST.JPG"
camera1.StartPreview

Dim out As OutputStream
out = File.OpenOutput(path1, fn, False)
out.WriteBytes(Data, 0, Data.Length)
out.Close

Dim bmp,smaller As Bitmap

bmp.Initialize(path1, fn)
smaller.Initialize3(bmp)
smaller = ResizeRotateBitmap(bmp, 640, 640)
smaller=CreateScaledBitmap(smaller, 480, 640, True)
out = File.OpenOutput(path1 ,fn, False)
smaller.WriteToStream(out, 80, "JPEG")
out.Close

End Sub

Sub ResizeRotateBitmap(src_bmp As Bitmap, w As Int, h As Int) As Bitmap
Dim new As Bitmap
new.InitializeMutable(w, h)
Dim c As Canvas
c.Initialize2(new)
Dim dst_rect As Rect
dst_rect.Initialize(0,0, w, h)
c.DrawBitmapRotated (src_bmp,Null, dst_rect,90)
Return new
End Sub


Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int, Filter As Boolean) As Bitmap
Dim r As Reflector
Dim b As Bitmap
b = r.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
Array As Object(Original, Width, Height, Filter), _
Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
Return b
End Sub

for this you need the Reflection lib.

good trying

Björn >:)-D)X
 
Last edited:
Upvote 0

Yeshua

Member
Licensed User
Longtime User
Rotate and resize.

Sub CameraY_PictureTaken(Data() As Byte)
CameraY.StartPreview
CameraY.FlashOff
Dim out As OutputStream
out = File.OpenOutput(File.DirRootExternal, "Image.bmp", False)
out.WriteBytes(Data, 0, Data.Length)
out.Close
ToastMessageShow("Image saved: " & File.Combine(File.DirRootExternal, "Image.bmp"), True)
:sign0085:
 
Upvote 0
Top