Android Tutorial Take pictures with the internal camera

Not open for further replies.
It is recommend to use the new CameraEx class. It provides more functionality.
The new Camera library allows you to take pictures using the back facing camera.

The following steps are required for taking a picture:
- Initialize a camera object. The Initialize method expects a Panel. The preview images will be displayed on this panel.
- Wait for the Ready event.
- In the Ready event Sub, call Camera.StartPreview to show the images preview.
- Call TakePicture to take a picture.
- The PictureTaken event will be raised with the picture passed as a bytes array (in JPEG format).
- Call StartPreview again to restart the images preview.

Only one process can access the camera at a time. Therefore you should release the camera when your activity is paused.
Usually you will initialize the camera during Activity_Resume and pause it during Activity_Pause.


The following code saves the image:
Sub Camera1_PictureTaken (Data() As Byte)
    Dim out As OutputStream
    out = File.OpenOutput(File.DirRootExternal, "1.jpg", False)
    out.WriteBytes(data, 0, data.Length)
    ToastMessageShow("Image saved: " & File.Combine(File.DirRootExternal, "1.jpg"), True)
You can see in the attached code that the "take picture" button is only enabled when the camera is ready.

For now the camera orientation is always set to landscape mode. Usually you will want to force the activity to also be in landscape mode. This is done by checking 'Lansdcape' in Project - Orientations Supported menu.

On the emulator the preview images will show a moving check board.


    5.7 KB · Views: 9,508


Active Member
Licensed User

i have load the camera and i can take a picture, but if i will show the picture on a imageview it goes wrong the second time

i want if i take a picture directly load on to a image view.
When i take the first time a pictue it is ok but the seccond timme the application stopped


Sub Camera1_PictureTaken (Data() As Byte)
   Dim out As OutputStream
   out = File.OpenOutput(File.DirInternalCache, "1.jpg", False)
   out.WriteBytes(Data, 0, Data.Length)
   ToastMessageShow("Image saved: " & File.Combine(File.DirInternalCache, "1.jpg"), True)
   btnTakePicture.Enabled = True
   ImageView1.Bitmap = LoadBitmap(File.DirInternalCache, "1.jpg")'this goes wrong second time
End Sub

what do i wrong?


Active Member
Licensed User
thank you
this is the right one

ImageView1.Bitmap = LoadBitmapSample(File.DirRootExternal, "Image.jpg", 100,100)


Active Member
Licensed User
Currently only landscape is supported (this is the native camera orientation).

When I run it, the video is stretched out across the screen. It is not a true image. Like when a SD television is stretched on a HD TV (4:3 aspect ratio to 16:9). I think it is because my phone has a longer aspect ratio. ANy ideas how to fix this?

Rick Harris

Well-Known Member
Licensed User
Take picture as bitmap

Regrettable the Camera1_Preview event does not trigger in my App. No idea why. It does work in the example project.

Is there a way to make the Camera take a picture in BMP format in stead of JPEG? That way it would be easy to get the RGB values of any pixel by using the Data Array of the Camera1_PictureTaken event!

Alberto Iglesias

Well-Known Member
Licensed User

I try to use this library in a device with Android 2.2.1 and only Facing Camera, I use your simple example, the StartPreview works very weel, but when I push the button, the _PictureTaken Event not firing. In anothers devices with 2.35 and 4.1.2 works very well.

You know why?

I try anothers libraries, like FrontCamera (by vb1992) and not work too.

Can I get the picture capturing a frame or something like that?

the device I have to do this is:

thank You


Licensed User
Hi Erel,

How can I mirror the image in preview mode? I try to use "setDisplayOrientation" , but it only rotate the image in different direction.
Thank you
Not open for further replies.