ZXing on Android: how to set camera in negative mode? - android

I want to use zxing in an android project. I have download the code and the example app is running now (ZXingTestActivity). For your information, i am not very familiar with coding native android.
I want to use zxing to scan qr-codes to configurate an application. To avoid confusion between normal qrcodes and configuration qrcodes i want to print inverted/negative qrcodes on screen or paper.
To be able to scan these inverted/negative qrcodes, the camera must be in negative mode. How can i do this? I am not sure where to start, however....
In the ZXingTestActivity.java there is a clicklistener that specify some extra parameters to the IntentIntegrator, for example:
private final Button.OnClickListener scanProduct = new Button.OnClickListener() {
#Override
public void onClick(View v) {
IntentIntegrator integrator = new IntentIntegrator(ZXingTestActivity.this);
integrator.addExtra("SCAN_WIDTH", 800);
integrator.addExtra("SCAN_HEIGHT", 200);
integrator.addExtra("RESULT_DISPLAY_DURATION_MS", 3000L);
integrator.addExtra("PROMPT_MESSAGE", "Custom prompt to scan a product");
integrator.initiateScan(IntentIntegrator.PRODUCT_CODE_TYPES);
}
};
Is it possible to add camera settings with addExtra and how do i format this? Is it possible? Or is there another way to configurate the camera to inverted/negative mode?

I do not know if it completely impossible with ZXing but with ZBar it is possible!
First download the ZBar android version on sourceforge:
http://sourceforge.net/projects/zbar/files/AndroidSDK/
Add project to eclipse
Open CameraPreview.java
Add a private var to the class:
private Camera.Parameters mCameraParams;
Add the following lines after the line: mCamera = camera; in the constructor CameraPreview:
mCameraParams = camera.getParameters();
mCameraParams.setColorEffect(Camera.Parameters.EFFECT_NEGATIVE);
mCamera.setParameters(mCameraParams);
That's it! (run the project)
Also think that ZBar is faster to detect damaged barcodes. Is the same as the PC-version i have used in another project and does the job very well. Blink with your eyes and the code is there. No fancy things at all, just good!

#Erwinus, here's the code. I hope it's now clear why it is something you have already been completely given in previous comments. More homework and fewer accusations makes SO a happy place.
mCameraParams = camera.getParameters();
if (mCameraParams.getSupportedColorEffects().contains(Camera.Parameters.EFFECT_NEGATIVE) {
mCameraParams.setColorEffect(Camera.Parameters.EFFECT_NEGATIVE);
}
mCamera.setParameters(mCameraParams);

Sorry there's not a way to do this via Intent. A clean patch adding this as an option would be attractive to commit. The only gotcha is that the camera must support the "negative" mode. Then it's trivial (you can see this behavior as a selectable option in Barcode Scanner+). Otherwise you have to flip the image yourself. Not hard, but takes a bit of code and CPU cycles.

Related

Android Fotoapparat library

I'm new to Android-Developement and I would like to make a Camera-app. I found this library (this is the Github page).
But I don't know how to implement a library. I followed these steps (method 2) but I'm getting an error in a popup window called 'IDE Fatal Errors'. It says: 'To investigate / fix the problem IDE wants to attach following files to the bug report. We recommend to include all the files providing maximum information. Note: all the data you send will be kept private.' Then I can select a 'diagnostic.txt'. There is a section 'file content' where 'rootsChanged' is written. I can report the whole window to Google.
The following step is to configure the 'Fotoapparat' instance. What is an instance? When I search on Google I only find articles talking about making a library.
I'm sorry if these are stupid question but I am a beginner and I would like to learn more about Android-Development. Thanks in advance for your time and help.
Add this line in your build.gradle(Module: app) file ->
dependecies {
//Your other dependencies...
implementation 'io.fotoapparat:fotoapparat:2.3.3'
}
And start using your code. Library is working fine.
EDIT - >
You need to learn basics of java.
To setup instance of the object you need to create a variable.
Hence in your case:
Fotoapparat yourVariableName = new FotoapparatFotoapparat
.with(context)
.into(cameraView) // view which will draw the camera preview
.previewScaleType(ScaleType.CenterCrop) // we want the preview to fill the view
.photoResolution(ResolutionSelectorsKt.highestResolution()) // we want to have the biggest photo possible
.lensPosition(LensPositionSelectorsKt.back()) // we want back camera
.focusMode(SelectorsKt.firstAvailable( // (optional) use the first focus mode which is supported by device
FocusModeSelectorsKt. continuousFocusPicture(),
FocusModeSelectorsKt.autoFocus(), // in case if continuous focus is not available on device, auto focus will be used
FocusModeSelectorsKt.fixed() // if even auto focus is not available - fixed focus mode will be used
))
.flash(SelectorsKt.firstAvailable( // (optional) similar to how it is done for focus mode, this time for flash
FlashSelectorsKt.autoRedEye(),
FlashSelectorsKt.autoFlash(),
FlashSelectorsKt.torch()
))
.frameProcessor(myFrameProcessor) // (optional) receives each frame from preview stream
.logger(LoggersKt.loggers( // (optional) we want to log camera events in 2 places at once
LoggersKt.logcat(), // ... in logcat
LoggersKt.fileLogger(this) // ... and to file
))
.build();
And start using yourVariableName.

how to capture a screenshot?

I know that there are a lot of questions about capturing screenshots, and I have checked most of them. They have the same answer (with small code variations).
I have following method for screenshot capturing:
#NonNull
public static Bitmap takeScreenShot(Window window) throws IOException {
final View rootView = window.getDecorView().getRootView();
final boolean drawingCacheEnabled = rootView.isDrawingCacheEnabled();
rootView.setDrawingCacheEnabled(true);
try {
return Bitmap.createBitmap(rootView.getDrawingCache());
} finally {
rootView.setDrawingCacheEnabled(drawingCacheEnabled);
}
}
And you can use it like these: takeScreenShot(getActivity().getWindow())
However these approach has several limitations:
If you have some dialogs on the screen they will not be captured on
screenshot.
Will it work with hardware accelerated views? According
to documentation:
When hardware acceleration is turned on, enabling the
drawing cache has no effect on rendering because the system uses a
different mechanism for acceleration which ignores the flag
Screenshot contains black boxes
instead of GLviews. (e.g. when you app has maps.). It seems to be as a result of 2nd point.
So my question is, is there any solution without rooting that can solve at least some of my issues?
Check out the following GitHub repo (not mine!): https://github.com/AndroidDeveloperLB/ScreenshotSample
Also, the following will be useful reading:
How to properly take a screenshot, globally?

WebRTC for Android : VideoRendererGUI take a screenshot in the video call

The demand is that saving a video frame in the video call. I have made a demo that take a screenshot through the GLSurfaceView's method "onDrawFrame". But when I use the webrtc, it have its own renderer "VideoRendererGUI" .And then when I want to override it, I find it can't be overrided. the main part code :
vsv = (GLSurfaceView) findViewById(R.id.glviewchild_call);
vsv.setPreserveEGLContextOnPause(true);
vsv.setKeepScreenOn(true);
VideoRendererGui.setView(vsv, new Runnable() {
#Override
public void run() {
init();
}
});
And If you have another way to take a screenshot, you can also share with me.
Thanks a lot!
If you use a SurfaceViewRenderer to display the stream, you can use the solution in this answer to capture a frame on the call.
Basically, using surfaceViewRenderer.AddFrameListener with a class that implements EGLRenderer.FrameListener
I will assume that the SurfaceViewRenderer of the peer you want to take a screenshot of is called remotePeerSurfaceViewRenderer, also I will asume that the button that you will use to take a screenshot is called btnScreenshot
So all what you need to do is as "Webo80" said in the answer above use the FrameListener, the issue is the FrameListener implementation of the webrtc takes only the first frame available once the Listener is attached to the SurfaceViewRenderer, so my approach to do that is by attaching the webrtc implementation of the FrameListsner at the second I need to take a screenshot and remove it once it is taken:
btnScreenshot.setOnClickListener((view)-> {
remotePeerSurfaceViewRenderer.addFrameListsner(new EglRenderer.FrameListener() {
#Override
public void onFrame(Bitmap bitmap) {
runOnUiThread(() -> {
/*
do what ever you want with the bitmap for example
imgView.setImageBitmap(bitmap);
*/
localVideoView.removeFrameListener(this);
});
}
}, 1);
})
Important note:
1. Please don't forget to runOnUiThread as Iam doing
2. Please don't forget to remove the listener inside the button onClick() method
I have tried this solution and it is working more than fine, if you want to make your custom solution you have to completely implement the interface "EglRenderer.FrameListener"
I am sorry to say due to unavailability of canvas and other facilities in Android It's not possible to capture screenshot programatically using WebRTC. One can dodge this situation by animating the app's UI and capturing the screenshot manually , store it at configured location and exchange it with other party.

QR scan in a half screen using zxing library xamarin android

In Xamarin android QR scan using zxing is much easy as it requires only 3 lines of codes.
MobileBarcodeScanner.Initialize(Application);
var scanner = new ZXing.Mobile.MobileBarcodeScanner();
var result = await scanner.Scan();
string qrCode = result.ToString();
But it always opens a default view with full screen even if I set it inside oncreate event or button click. What I really need is having qr scan in half screen instead of full screen. remaining othert half screen will be used to add few buttons.
If anyone knows how to do it please let me know I have spent more than 3-4 days to find the answer for this component. Also if there are any other useful library than zxing for qr scanning let me know.
Thanks,
Muthu
As #SushiHangover mentioned, use the ZXingScannerFragment to achieve this. Take a look at the sample here.

Taking Screenshots Using Qt C++ on Android

thanks for checking my question out!
I'm currently working on a project using Qt C++, which is designed to be multi-platform. I'm a bit of a newcoming to it, so I've been asked to set up the ability to take screenshots from within the menu structure, and I'm having issues with the Android version of the companion app.
As a quick overview, it's a bit of software that send the content of a host PC's screen to our app, and I've been able to take screenshots on the Windows version just fine, using QScreen and QPixmap, like so:
overlaywindow.cpp
{
QPixmap screenSnapData = screenGrab->currentBackground();
}
screenGrabber.cpp
{
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( QApplication::desktop()->winId() );
}
Unfortunately, Android seems to reject QScreen, and with most suggestions from past Google searches suggesting the now-deprecated QPixmap::grab(), I've gotten a little stuck.
What luck I have had is within the code for the menu itself, and QWidget, but that isn't without issue, of course!
QFile doubleCheckFile("/storage/emulated/0/Pictures/Testing/checking.png");
doubleCheckFile.open(QIODevice::ReadWrite);
QPixmap checkingPixmap = QWidget::grab();
checkingPixmap.save(&doubleCheckFile);
doubleCheckFile.close();
This code does take a screenshot, but only of the button strip currently implemented, and not for the whole screen. I've also taken a 'screenshot' of just a white box with the screen's dimensions by using:
QDesktopWidget dw;
QWidget *screen=dw.screen();
QPixmap checkingPixmap = screen->grab();
Would anyone know of whether there was an alternative to using QScreen to take a screenshot in Android, or whether there's a specific way to get it working as compared to Windows? Or would QWidget be the right track? Any help's greatly appreciated!
as i can read in Qt doc : In your screenGrabber.cpp :
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( QApplication::desktop()->winId() );
replace with :
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( 0 ); // as 0 is the id of main screen
If you want to take a screenshot of your own widget, you can use the method QWidget::render (Qt Doc):
QPixmap pixmap(widget->size());
widget->render(&pixmap);
If you want to take a screenshot of another app/widget than your app, you should use the Android API...

Categories

Resources