Zoom Camera2 Preview using TextureView

i have a Problem with my Preview Zoom for the Camera2 API. I am using a TextureView.

I want to zoom only the preview Stream that was showed in the TextureView.

I want to zoom the Area where i use the Zoom Gesture.

I use the SimpleOnScaleGestureListener!

I added following Code. The zoomingFactor and the x and y Position are right.

 private void updateTextureViewSize(float xPosi,float yPosi, float scale){
        float scaleX = 1.0f;
        float scaleY = 1.0f;

        float mVideoWidth = mCamcontrol.getmPreviewSize().getWidth();
        float mVideoHeight = mCamcontrol.getmPreviewSize().getHeight();

        int rotation = getWindowManager().getDefaultDisplay().getRotation();
        RectF viewRect = new RectF(0, 0, 1440, 2560);
        RectF bufferRect = new RectF(0, 0, mVideoHeight, mVideoWidth);

        bufferRect.offset(xPosi - bufferRect.centerX(), yPosi -    bufferRect.centerY());

         //16:9 faktor
        scaleX = ((mScale * scale) / 9f) * 16f;
        scaleY = ((mScale * scale) / 16f) * 9f;

        Matrix matrix = new Matrix();

        matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.FILL);
        scalefactorView.setText(String.valueOf(xPosi) + "  " + String.valueOf(yPosi));

        matrix.setScale(scaleY, scaleX, xPosi, yPosi);
        matrix.postRotate(90 * (rotation - 2), xPosi, yPosi);



read more

Failed to Connect to MySQL at localhost:3306 with user root

I use Mysql Workbench to connect my database,[Hostname Port and Username are as shown in figure ,and password is right[1]

Hostname Port and Username are as shown in figure ,and password is right.When I click Test Connection ,it show as above.But if i use 3307 in place of 3306 as port,it connect sucessfully. What matter lead that and how I fix it?

I use macbook pro and I don’t know check which my.cnf. I use sudo vim /usr/local/mysql/my.cnf in terminal .
And the my.cnf is as below:

read more

How to print byte array data to Zebra printer?

I want to print a PDF file to Zebra printer using a Java application. I have generated a PDF using Jasper reports with 2D bar codes. If I am performing manual print to Zebra printer it’s printing that PDF file but once I am trying to print the same pdf file using the Java application, the job is submitting to printer but print is not happening.

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.event.PrintJobAdapter;
import javax.print.event.PrintJobEvent;

public class ZebraPrintUtil {
    public static void main(String[] args) throws IOException, InterruptedException {
        byte[] content = convertFileToBytes("D://old files/test123.pdf");
        print(content, "ZDesigner GX420t");

    private static byte[] convertFileToBytes(String absoluteFilePath) throws IOException {
        File file = new File(absoluteFilePath);
        FileInputStream fis = new FileInputStream(file);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];

        try {
            for (int readNum;
            (readNum = fis.read(buf)) != -1;) {
                bos.write(buf, 0, readNum); // no doubt here is 0
        } catch (IOException ex) {

        } finally {
            if (fis != null) {

        byte[] bytes = bos.toByteArray();
        return bytes;

    private static boolean print(byte[] byteArray, String reqPrinterId)
            throws IOException, InterruptedException {
        boolean isPrintedSuccessfully = false;
        DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
        PrintService[] services = PrintServiceLookup.lookupPrintServices(
        flavor, null);

        if (services.length > 0) {
            PrintService myService = null;

            for (PrintService service: services) {
                if (service.getName().contains(reqPrinterId)) {
                    myService = service;

            DocPrintJob printJob = myService.createPrintJob();
            JobCompleteMonitor monitor = new JobCompleteMonitor();
            Doc document = new SimpleDoc(byteArray, flavor, null);

            try {
                printJob.print(document, null);
                System.out.println("-------------------- Print Completed " + monitor.completed);

                isPrintedSuccessfully = true;
            } catch (Exception e) {

        return isPrintedSuccessfully;

    private static class JobCompleteMonitor extends PrintJobAdapter {
        private boolean completed = false;

        public void printJobCanceled(PrintJobEvent pje) {

        public void printJobCompleted(PrintJobEvent pje) {

        public void printJobFailed(PrintJobEvent pje) {

        public void printJobNoMoreEvents(PrintJobEvent pje) {

        private void signalCompletion() {
            synchronized(JobCompleteMonitor.this) {
                completed = true;

        public synchronized void waitForJobCompletion() {
            try {
                while (!completed) {
            } catch (InterruptedException e) {


read more

Writing to text file with specific date and time in the file name

I am trying to write all my data to a text file and it is working unless I put DateTime in the file name.
The current code looks like this:

string time = DateTime.Now.ToString("d");
string name = "MyName";

I am getting this exception:

An unhandled exception of type ‘System.IO.DirectoryNotFoundException’ occurred in mscorlib.dll

But as far as I know, the File.WriteAllText() method should create a new file or overwrite already existed file.

read more