Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 112
Registered: ‎09-23-2009
My Device: Not Specified

Re: Camera Overlay

Hi all,

It's quite sometime since last post in this thread. I'm sorry to awakening old thread, but this topic is something that somehow being trend right now. Has anyone figured out if this is possible Blackberry? To overlay a camera?

 

Thanks for the attention.

Highlighted
Developer
Posts: 60
Registered: ‎05-04-2011
My Device: Torch 9800, Bold 9700, Curve 9380
My Carrier: None

Re: Camera Overlay

[ Edited ]

in 7.0, you can achieve this very easily.

 

Use these lines of code:

 

import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;

import net.rim.device.api.system.Display;
import net.rim.device.api.system.MagnetometerData;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.AbsoluteFieldManager;
import net.rim.device.api.ui.container.ComponentCanvas;
import net.rim.device.api.ui.container.MainScreen;

public class HeadingScreen extends MainScreen
{
	private Player       _player;
	private VideoControl _videoControl;
	private Field        _cameraField;
	private LabelField   _headingLabel;
	 
    public HeadingScreen()
    {            
        setTitle("Augmented Reality Heading Sample");
        initializeCamera();
        AbsoluteFieldManager afm = new AbsoluteFieldManager();
        ComponentCanvas cc = new ComponentCanvas(Display.getWidth(),Display.getHeight());
        
        afm.add(_cameraField,0,0);
        afm.add(cc);
        add(afm);
        
        _headingLabel = new LabelField("?");
        Font myFont;
        try
        {
	        FontFamily ff = FontFamily.forName("BBCAPITALS");
	        myFont = ff.getFont(FontFamily.SCALABLE_FONT, 42).derive(Font.BOLD);
	        cc.add(_headingLabel,Display.getWidth()/2,30);
	        cc.setFont(myFont);
        }
        catch(Exception e)
        {
        //handle e
        }
    }

	private void initializeCamera()
	{
	    try
	    {
	        _player = javax.microedition.media.Manager.createPlayer("capture://video");
	        _player.realize();
	
	        _videoControl = (VideoControl)_player.getControl("VideoControl");
	
	        if (_videoControl != null)
	        {
	            _cameraField = (Field)_videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
	            _videoControl.setDisplayFullScreen(true);                
	            _videoControl.setVisible(true);
	        }
	        _player.start();           
	    }
	    catch(Exception e)
	    {
	        //handle exception
	    }
	}
}

 

 But remember this is only possible in OS7.0.