Good day,
I have a problem with my project using sarxos webcam capture. When running the project, camera is working just fine. I have a button to turn on/off the camera, if turned on the numpad is enabled and if off, numpad is disabled and camera will be enabled, but after turning on back the camera, the panel displays "No image available" but it can still capture bar codes, it has just no display. Tried googling some possible way but no luck, also tried repaint() and revalidate() the panel but still not working.
Camera on
Camera turned back on
camOrNumpad.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ev) {
if(ev.getStateChange()==ItemEvent.SELECTED){
camOrNumpad.setText("Camera On");
keyP.clear();
CamSacnner.webcam.open(); //on camera
numpad.setEnabled(false);
numScanImg.setVisible(false);
numScanIDView.setVisible(false);
numScanName.setVisible(false);
camScanViewHide.setVisible(false);
camScanImg.setVisible(true);
camScanIDView.setVisible(true);
camScanName.setVisible(true);
} else if(ev.getStateChange()==ItemEvent.DESELECTED){
camOrNumpad.setText("Camera Off");
CamSacnner.webcam.close(); //off camera
camScanView.setEnabled(false);
numpad.setEnabled(true);
camScanImg.setVisible(false);
camScanIDView.setVisible(false);
camScanName.setVisible(false);
camScanViewHide.setVisible(true);
numScanImg.setVisible(true);
numScanIDView.setVisible(true);
numScanName.setVisible(true);
}
}
});
Related
I use this code below to toggle on and off camera flash light
private void toggleFlash() {
try {
if(!flashOn) {
captureRequestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_TORCH);
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
} else {
captureRequestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
}
captureSession.setRepeatingRequest(captureRequestBuilder.build(), null, handler);
flashOn = !flashOn;
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
It works, but the issue is this. At first when I open the camera (without flash light), I can see the image preview from the camera clear, but when I toggle on the flash and toggle it off, the preview becomes more darker than the initial time of opening the camera.
I'm still new to the camera API but I guess the issue is coming from here
captureRequestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
But I don't know the proper code to use to make the camera not to be dark. Anyone with a solution?
It's going black because you're turning off auto-exposure, and I suspect the default manual exposure and sensitivity values are so low that the image is very underexposed.
You don't need to turn auto-exposure OFF when you turn off the flash. To control the flash manually, you do need to make sure AE is not set to ON_AUTO_FLASH, ON_ALWAYS_FLASH, or ON_AUTO_FLASH_REDEYE, but that just means you can leave it as ON all the time, if you don't need automatic flash firing.
So just remove the bit about setting CONTROL_AE_MODE to CONTROL_AE_MODE_OFF
Torch and flash are two different setting in camera2.
You can try and control flash with these setting.
On
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
Off
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
I used video capturing code using built-in camera in an application, but it reporting issues some of android phones like OnePlus phones. in other phones it works perfectly, can anyone help me to solve this issue, i tried many times but it didn't work, I'm sharing my code below..
Acutually it is shows only in device like one plus, I try to use built-in cam for to recording video, in my project, After we click button for to record video, it will redirected to the built-in cam in the device, in other devices it's working perfectly. but in one plus version11 , after we click the button for to record video it will not redirected to built-in cam, it is just stuck with the same page.. this is the issue
private void captureVideo() {
Intent VideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (VideoIntent.resolveActivity(getPackageManager()) != null) {
VideoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
VideoIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
VideoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 3);
VideoIntent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION,true);
startActivityForResult(VideoIntent, VIDEO_REQUEST);
}
}
I am currently working on a barcode scanning app, which uses the mobile vision api for the majority of processes. I am trying to implement a flash button so that a user may scan in low light, but for some reason the activation of flash freezes the camera feed. Is there some way to start flash with a button while the feed is active? To activate flash without interfering with other threads? Thanks!
i used this code in my custom camera Application.when User clicks the FlashOn Button then Flash will be start.i think this code will help to you.
try this code (OnButton Click) :
private void btnFlashOnClick() {
if (mCamera != null) {
// First get the Camera Parameters.
Camera.Parameters parameters = mCamera.getParameters();
// set FlashMode to camera parameters.
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
// set Parameters Objects to Camera.
mCamera.setParameters(parameters);
// Finally, Start the Preview Of a Camera
mCamera.startPreview(); // this Line is Usefull for MyApp.If you don't need then Remove this Line.
}
}
this code is works fine in my App..Hope this will helps you...(:
It really depends what camera api you are using as there are few.
CameraManager has
void setTorchMode (String cameraId, boolean enabled)
that lets you operate flash regardless of current state of the camera (and without a need to restart one), but it could be overridden by other apps too
Hi My requirement is like this. I have an activity in that I want to disable back button, menu button, home button screen settings button. When I touch on that screen I open one alert dialog with two buttons. If I click ok button all the buttons are enabled and my app is exit.
Thats my requirement. If anyone knows about this, please reply me as soon as possible. Quick reply is Very very appreciable.
To achieve this you must specify your activity as android.category.HOME.
And when you finish your activity (press ok button) you must start default launcher on phone.
But it's mean that on every home button press you will see your activity. To prevent this you must determine how your activity was started.
I would rather override onKeyDown method
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
//DO NOTHING
}if(keyCode == ..etc){
//Still do nothing
return super.onKeyDown(keyCode, event);
}
This way you will have full control of what happens.
Regards,
Robert
I'm trying to develop a Mac OsX app provided by a system tray icon, so after the first attempt with the simplest code to achieve it I noticed that every apps tray icon's (both system and user apps) on mac osX (10.8) allows to activate the relative popup menu with both left and right click on it but with my project only the left (MouseEvent.BOTTON1) button causes the popup menu to pulldown. Here's my code:
public class SystemTrayDemo
{
private SystemTray tray;
private TrayIcon tray_icon;
public SystemTrayDemo()
{
if (!SystemTray.isSupported())
{
JOptionPane.showMessageDialog(null, "System tray not supported!");
return;
}
else
tray = SystemTray.getSystemTray();
final PopupMenu popup = new PopupMenu();
MenuItem exit = new MenuItem("Exit");
exit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (tray != null)
{
tray.remove(tray_icon);
System.exit(0);
}
}
});
popup.add(exit);
//add tray icon
tray_icon = new TrayIcon(getIcon("images/wifi.png"), "Open documents...", popup);
tray_icon.setImageAutoSize(true);
try
{
tray.add(tray_icon); // adds icon
}
catch (AWTException ex) {}
}
private Image getIcon(String name)
{
URL _url = getClass().getResource(name);
return new ImageIcon(_url).getImage();
}
public static void main(String args[])
{
new SystemTrayDemo();
}
}
but how I already said, only through left mouse button click.
So during a further attempt I've tried to mimic the behavior of the tray icons of every other apps using a MouseListener and firing a left button event on right click event using dispatchEvent() method like so:
public static void fireMouseEvent(Component c)
{
MouseEvent me = new MouseEvent(c, // which
MouseEvent.MOUSE_CLICKED, // what
System.currentTimeMillis(), // when
MouseEvent.BUTTON1_MASK, // no modifiers
0, 0, // where: at (10, 10}
1, // only 1 click
true); // popup trigger
c.dispatchEvent(me);
}
the event will handled by the mouse listener but obviously TrayIcon Class is not a Component subclass and therefore the source of MouseEvent is null and I get a NPE. Here's my MouseListener:
class MouseAdapt extends java.awt.event.MouseAdapter
{
public void mouseClicked(java.awt.event.MouseEvent me)
{
int button = me.getButton();
if(button == java.awt.event.MouseEvent.BUTTON3)
{
fireMouseEvent(me.getComponent());
}
}
}
try
{
tray.add(tray_icon); // aggiungi l'icona
tray_icon.addMouseListener(new MouseAdapt());
}
catch (AWTException ex) {}
Sorry for my english, I hope that someone who have ever had some experience with that kind of projects can help me. I've searched for hours but with no luck. Thank You for your help.
Edit: There's now a library working to fix all of this here: https://github.com/dorkbox/SystemTray
to activate the [TrayIcon] relative popup menu with both left and right click
This is simply not possible on Mac + Java currently. Using reflection to invoke the underlying triggers doesn't seem to help. This is a bug.
https://bugs.openjdk.java.net/browse/JDK-8041890
only the left (MouseEvent.BOTTON1) button causes the popup menu to pulldown. Here's my code
Even this is broken in some Java versions (7u79), fixed with an upgrade...
https://bugs.openjdk.java.net/browse/JDK-7158615
Cross-Platform TrayIcon Support:
Albeit slightly off-topic, I wanted to add, some projects use a JXTrayIcon to accomplish some fancy drop-down menus in Linux/Windows, etc. These also cause problems on Mac despite a click-bug it already suffers from today as well as bugs with Gnome3 requiring a completely separate hack. But on Mac, any attempt to use the decorated menus causes the menu to linger and is a very bad experience for the end-user. The solution I settled on was to use AWT for Mac, Swing for everything else. The Java TrayIcon support is in dire need of a rewrite. JavaFX claims to help this initiative, but it's staged for Java 9. In the mean time, I'm sticking to OS-dependent hacks.
Related Tray Issues for Other Platforms
Furthermore, some Linux distributions like Ubuntu have removed the tray icon by default in the Unity desktop, causing further headaches. https://askubuntu.com/a/457212/412004
In addition, the transparency of the icon is replaced with a gray color on Gtk/Gnome or Qt/KDE powered desktops (Both OpenJDK and Oracle JRE suffer this)
https://stackoverflow.com/a/3882028/3196753
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6453521
In addition, Gnome3 powered desktops may show it in the wrong corner, not at all, or it may show but be unclickable (Both OpenJDK and Oracle JRE suffer this)
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=660157
https://bugzilla.redhat.com/show_bug.cgi?id=1014448
In addition to that, high-DPI screens on Windows have a bug that draws the icon incorrectly: Windows 8 Distorts my TrayIcon
So in summary, the state of the System Tray in Java is OK, but due to the combination of factors is quite fragmented and buggy in JDK6, JDK7 and JDK8.