Knockout SVG Image Binding not Working. Solution Found!

This post is about an issue I faced in Knockout to bind svg <image> and it was not showing the image inside the svg, even with correct binding with xlink:href

My first attempt was,


If you notice that, Image is not showing in the svg box.
Reason: Because xlink:href attribute needs to be there even with empty value to initialize the HTML svg image.

So, your image tag should be like this
<image height="500" id="img1" width="500" xlink:href=""
        data-bind="attr:{'xlink:href': image}"></image>


Solution, with empty xlink:href attribute


Hope this may help to somebody with the same problem!
Continue Reading...

Android Drag-Drop Button - A custom component for android developers

See on Github

This is an open source android drag button custom component. You can use it on your project to show a drag-able icon and perform any action after user dragged to the edge of the component.

drag drop button screenshot
screenshot

Import aar file on releases directory to your android project to include drag-drop button. Or you can download entire project and open from Android studio and compile to match with your sdk version, then you can import generated aar file to your real project.

Example usage of the drag-drop-button

This is a sample code for drag button inserting into ui and handling events.

xml code to put drag-drop button on the activity
<com.mili.dragdropbutton.DragButton
    android:id="@+id/dragBtn"
    android:layout_width="200dp"
    android:layout_height="200dp"
    custom:imageBtnSizePercentage="0.25"
    custom:dragEndThresholdPercentage="0.10"
    custom:arrowCount="4"
    custom:arrowColor="#42f46e"
    custom:iconFileName="icon2.png">
</com.mili.dragdropbutton.DragButton>

Note:
Needs to define custom namespace on parent tag as
xmlns:custom="http://schemas.android.com/apk/res-auto"

See activity_main.xml on test project for complete source code.


Java code to handle events
DragButton dragButton = (DragButton) findViewById(R.id.dragBtn);
dragButton.setOnDraggedListener(new DragButton.OnDraggedListener() {
    @Override    public void onDragged(DragButton view, MotionEvent e) {
        Log.i("DragBtn", "Dragged");
    }
});
dragButton.setOnDragStartedListener(new DragButton.OnDragStartedListener() {
    @Override    public void onDragStarted(DragButton view, MotionEvent e) {        
        Log.i("DragBtn", "Drag started");
    }
});
dragButton.setOnDragEndedListener(new DragButton.OnDragEndedListener() {
    @Override    public void onDragEnded(DragButton view, MotionEvent e) {
        Log.i("DragBtn", "Drag ended");
    }
});
See MainActivity.java on test project for complete source code.


Custom Attributes on xml

imageBtnSizePercentage
Size of the center icon to draw related to the size of the button. Example- 1 will draw the center icon on entire button, 0.5 will draw half of the size of the button. Any value between 0-1.

dragEndThresholdPercentage
Indicate the percentage area of the threshold to fire the dragged event. Any value between 0-1.


arrowCount
Number of arrow to show the drag direction. Any positive integer value

arrowColor
Color of the arrows in hex format. Example- #42f46e

iconFileName
Path to the image file for center icon on assert folder. 512x512 is the recommended size. 
Example- icon2.png
 
Continue Reading...

How to install Adobe Flash Player plug-in for Firefox on Ubuntu

Click here to check flash player on your browser

Adobe flash player is also a plug-in for for Mozilla Firefox to view flash videos (ex: youtube videos) and play flash on-line games, etc. Therefore flash player became essential plug-in for most of the web browsers until HTML 5 take place (because HTML 5 has new capabilities those can challenge to flash player such as video playing).

This article describe how to install Adobe Flash Player plug-in for Firefox on Ubuntu

You might be think, is this a very harder thing?

Yes, some times.

Because, Ubuntu software center and Synaptic package manager can use to install flash player plug-in for some Ubuntu versions and it will simply works. But some Ubuntu distribution such as Ubuntu 16.04 needs to follow following few steps to make it work correctly.

Step 1- Download latest Adobe Flash Player Plug-in form here.(Select download option as 'tar.gz for other Linux')

Step 2- Extract downloaded file into any directory. (extracted file should be .so format)

Step 3- Open terminal (Application --> Accessories --> Terminal or Ctrl+Alt+T)

Step 4- Type following command

sudo -i

Now it will prompt you the Password. Now enter the password and press enter  

Step 5- Goto directory that contain extracted .so file using cd command (Ex: cd Downlods)

Step 6- Copy that .so file into /usr/lib/mozilla/plugins directory. To copy that file use following command.

cp [fileName].so /usr/lib/firefox-addons/plugins

(Ex: cp libflashplayer.so /usr/lib/firefox-addons/plugins)

Step 7- Restart the system to make changes appear to Firefox.

It is better to close all the Firefox related windows before copy the .so file. Remember you should restart the system to make plug-in work correctly (Not only restart Firefox)

If this article helpful to some one please do not forget to comment about it.

See how to do this from videos!


Continue Reading...

Is flash player installed?

This page allows you to check whether your browser has flash player installed.
and detect the installed flash player version.
The check perfectly works on Firefox and Chrome.
Check how you can install flash, if it says NO!
Click here to read how to install, or watch following videos. Adobe flash player is also a plug-in for for Mozilla Firefox to view flash videos (ex: youtube videos) and play flash on-line games, etc. Therefore flash player became essential plug-in for most of the web browsers until HTML 5 take place (because HTML 5 has new capabilities those can challenge to flash player such as video playing). This article describe how to install Adobe Flash Player plug-in for Firefox on Ubuntu

YES!
Congratulations! Flash player has installed
NO!
Flash player has not installed or blocked by browser


This page allows you to check whether your browser has flash player installed. and detect the installed flash player version. The check perfectly works on Firefox and Chrome.

Check how you can install flash, if it says NO!


Click here to read how to install, or watch following videos





This page is using JavaScript Flash Detection Library (Flash Detect) by Carl S. Yestrau. So thanks for creating such a nice library!
Continue Reading...

Simple SignalR chat program

SignalR is a library which enables real-time web functionality and bi-directional communication between server and connected clients. That's mean SignalR server can force clients to get updated and/or client(s) can force server to get updated. Also SignalR supports web sockets.

Before start coding for SignalR let's clarify some keywords on SignalR.

SignalR Server
SignalR server is a .net program that runs on a server machine. This handles all the requests (or function calls) made by clients and responsible for updating corresponding clients also.

SignalR Client
SignalR client is either a .net program or a web app which run on client machine. These clients can connect or disconnect to a SignalR server.

SignalR Hub
SignalR hub is the intermediate party which handle communication between SignalR server and SignalR client(s). This hub is already implemented by the library itself, so we don't need to code for this!

Simple Idea...
Simply if you have a web SignalR client, SignalR server can directly call your javascript function. Also your web client can directly call SignalR server function.


Note - SignalR client can be either a web (HTML/Javascript) app or a .net desktop app.

First let's create SignalR server app now!


SignalR Server
SignalR server is a .net program that runs on a server machine. You can follow these steps to create SignalR server in Visual Studio.

Step 1
Create a new winform project in Visual Studio.



Step 2
Since SignalR is a library, we need to add set of dll files to our project as references. The easiest way to add references and its' dependencies is Nuget. Nuget is a smart library management tool in visual studio. Let's add relavant libraries for SignalR. First right click on project references and open Nuget package manager dialog box.

Step 3
Type "signalr self host" in search box and click on install on the first item of the search result. Make sure the id is equal to "Microsoft.AspNet.SignalR.SelfHost".

Step 4
Next search as "Owin Cors" and install the item which the id is "Microsoft.Owin.Cors".

Step 5
 Next search as "Microsoft AspNet SignalR Client" and install the item which the id is "Microsoft.AspNet.SignalR.Client".


Note- Step 3,4 and 5 will add several dll files and its' dependencies automatically.

Step 6
Now we are done with Nuget, next reference can be added using system references. Therefore close Nuget package manager and open Reference Manager dialog.

Step 7
Then add "System.Net.Http" reference and click on ok.

After these all the steps, you should be able to see all the references as on following image.


Step 8
Next let's create a class to manage signalR connection. Right click on the project and select "Add-->Class" then change the class name as SignalRServer and click ok. Since that project that we are going to do is a winform signalR server, let's create a server class as follows.
class SignalRServer
{
    private IDisposable SignalR { get; set; }
    public const string ServerURI = "http://localhost:8181";

    public bool StartServer()
    {
        try
        {
            SignalR = WebApp.Start(ServerURI);
        }
        catch (TargetInvocationException)
        {
            return false;
        }

        Console.WriteLine("Server started at " + ServerURI);
        return true;
    }

    public void StopServer()
    {
        if (SignalR != null)
            SignalR.Dispose();
    }
}

Code Explained...

private IDisposable SignalR { get; set; }
public const string ServerURI = "http://localhost:8181";
'SignalR' is the server instance of the class, and here it defines the server url for the server that we are going to run.

public bool StartServer()
{
    try
    {
        SignalR = WebApp.Start(ServerURI);
    }
    catch (TargetInvocationException)
    {
        return false;
    }
    Console.WriteLine("Server started at " + ServerURI);
    return true;
}
This method responsible for starting the server. Note that it is starting the server as a web app and accepting the server url which we defined already within the class.

public void StopServer()
{
    if (SignalR != null)
        SignalR.Dispose();
}
Here, it is just disposing the signalr server instance then it will allow to close the signalr connections.

All together, this is a simple signalr server class which handle simple basic signalr operations.

Next time I will discuss how to create singnalR client in both winform and web !

Continue Reading...

Simple AForge.net tutorial - getting start with AForge


AForge.NET is a powerful C# framework designed for the fields of Computer Vision and Artificial Intelligence, image processing, neural networks, genetic algorithms, machine learning, robotics, etc.

This is a simple and quick tutorial that describes how to setup Visual Studio environment to work with AForge.net. At the end of this tutorial you will have a C# project with all the required dll files for AForge.net and a simple few line code to convert RBG C# Bitmap image to grayscale  image.



Download complete Visual Studio project.


 

Step 1 - Create new project

Open Visual Studio IDE and create a new project, Goto File-->New-->Project

Create a C# winform Application project by selecting Windows Forms Application from the list and give it a proper name and folder to save the project

Step 2 - Add references for AForge.net

Open solution explorer and right click on your project then select Manage NuGet Packages...
This will open a new window to manage your references via NuGet. NuGet is a nice way to keep your references, But this required your computer connected to internet. Therefore make sure your dev machine connected to internet when you try next step.

Now, simply search for aforge on the search box and click on install button on the AForge.Imaging library. So this will take few seconds to download all the dependencies and the library itself to your project.

 Note that the coolest thing in the NuGet is that you do not need to worry about dependencies of a library, it will take care of all required libraries for the one that you want to install.

After you are done with the installation, your References for the project will looks like this,

Step 3 - Create winform

Now, let's do some UI to do our magic. Click on tool bar and draw a button. You can give it a proper name and text.

 I called my button as Process and named it as btnProcess. So let's make some code in the next step.

Step 4 - Code it !!!

Double click on the Process button in your winform designer and Visual Studio will open the code view and automatically add a Click event for your button. So let's do our coding inside the click event, then it will execute the code when you click on the Process button.

Since this code needs to convert an RGB image to grayscale, we need to apply a filter on AForge.net called Grayscale. Therefore we need to create the filter first.

Type Grayscale in the code and Visual Studio will give you an error says that "The type or namespace name 'Grayscale' could not be found (are you missing a using directive or an assembly reference?)". That's mean, we didn't import AForge namespace to this file still.
To fix this error, either you can type using AForge.Imaging.Filters; or Right on Grayscale and select Resolve-->using AForge.Imaging.Filters;
Either case your code should be like this and note that you will have using AForge.Imaging.Filters; at the top of your file.

Now, type the following code to open an image and apply the grayscale filter and save it back to the disk.
Grayscale filter = new Grayscale(0.2, 0.2, 0.2);

Bitmap img = (Bitmap)Image.FromFile("test.jpg");
Bitmap grayImage = filter.Apply(img);
grayImage.Save("grayImage.jpg");

Code Explained...
Grayscale filter = new Grayscale(0.2, 0.2, 0.2);
This will create the AForge filter named Grayscale and I am setting Red, Green, and Blue coefficients to 0.2, you can change this value and test, so it will give you different results.



Bitmap img = (Bitmap)Image.FromFile("test.jpg");
Here, I am opening a jpg file into a System.Drawing.Bitmap type object. Note that, if your image is in a different path, you need to type the full path of the jpg file instead of test.jpg.


Bitmap grayImage = filter.Apply(img);
This is the place that magic happens, img is our source image and this will return a filter applied Bitmap type object. So grayImage is the output image.


grayImage.Save("grayImage.jpg");
This will save the output image to the disk, so we can open it as a normal jpg image and view the result.

Now, you can build your project. Go to Build-->Build Solution from the main menu.

If every thing went well without any error in your code, you may see success on the Output window as follows,

Step 5 - One more before run...

Note that all the path for our jpg files are relative paths, which means that is not a the full path to the file. So this means all the paths are relative the directory where our exe file located on, in this case it will located on your bin/debug folder of the Visual Studio project. Therefore go to your project folder and put test.jpg file in the bin/debug folder as shown here,

Step 6 - Run the code

Ok, Now your project is ready to run and test. so go to Debug-->Start Debugging or press F5 to run your project.

Then you will see your winform and click on process button.

If every thing went well, you will see a jpg file in your bin/debug folder named grayImage.jpg and it is the grayscale image for the test.jpg image.



Download complete Visual Studio project.


Filtered Image Source Image
Continue Reading...

Debug PHP code in Netbeans

Netbeans is a powerful IDE for PHP and many other development environments. is it possible to debug your PHP project in Netbeans? run your PHP code line by line and look at your variable values in real time? The answer is Yes! even you can have many watch expressions to examine variable values and execute your PHP code line by line. You just need to follow these 4 steps to enable PHP debugging in your Netbeans IDE!

Note - Netbeans version 8.0.2 has used for this article

 

 

Step1: Set php.exe file location on your web server.

Click on Tools-> Options to open Options dialog box on Netbeans then go to PHP tab and set the php.exe file location (I am using xampp server, your path also will be similar to "F:\xampp\php\php.exe" if you use xampp, or if you use wamp server your path will similar to "F:\wamp\bin\php\php5.4.12\php.exe")








 

 

Step2: Setup debugging on Netbeans

Go to Debugging tab on Options dialogbox and set the values as you can see on following screenshot. Then click on Apply and OK to save your changes.

 

 

 

 

 

 

 

 

 

Step3: Setup php.ini file

Copy following lines to the end of your php.ini file.
Note - you can find this file on a similar location as  "F:\xampp\php\php.ini" if you are using xampp, or "F:\wamp\bin\php\php5.4.12\php.ini" if you are using wamp server.

[xdebug]
xdebug.remote_enable = on
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = "F:\xampp\tmp"
xdebug.remote_handler = dbgp
xdebug.remote_host = localhost
xdebug.remote_port = 9000

Note - you can change xdebug.profiler_output_dir = "F:\xampp\tmp" to match with your own folder

Step4: Restart your web server and Netbeans IDE to apply the changes that we made.



Now your IDE ready for debug your project. click on icon or Debug->Debug Project to start debugging on Netbeans. once you start debugging your browser will open the web page and you can put some break points on your code, then these break points will hit depends on your user actions on your web page. So you can examine your variable values and program execution using following icons on netbeans IDE. (or you can find the same actions on Debug menu on the IDE)

 
Continue Reading...

Convert Opencv Mat to C# Bitmap

Conversion from Opencv Mat to C# bitmap isn't a difficult task. But this conversion needs to be done from the primitive level of both Opencv Mat and C# Bitmap. Simply all the images are created from set of bytes, therefore it is necessary to create System.Drawing.Bitmat from bytes of cv::Mat. Also you will need to do this conversion in a CLI project. Total instructions can be found in following 2 articles.
  1. Call Opencv functions from C#
  2. Call Opencv functions from C# with bitmap



This article describes how to convert C# Bitmap to Opencv Mat.
Convert C# Bitmap to Opencv Mat

If you already know how to create and configure CLI project in visual studio, simply use following function in CLI project to convert Opencv Mat to C# Bitmap.

System::Drawing::Bitmap^ MatToBitmap(Mat srcImg){
    int stride = srcImg.size().width * srcImg.channels();//calc the srtide
    int hDataCount = srcImg.size().height;
   
    System::Drawing::Bitmap^ retImg;
       
    System::IntPtr ptr(srcImg.data);
   
    //create a pointer with Stride
    if (stride % 4 != 0){//is not stride a multiple of 4?
        //make it a multiple of 4 by fiiling an offset to the end of each row


       
//to hold processed data
        uchar *dataPro = new uchar[((srcImg.size().width * srcImg.channels() + 3) & -4) * hDataCount];

        uchar *data = srcImg.ptr();

        //current position on the data array
        int curPosition = 0;
        //current offset
        int curOffset = 0;

        int offsetCounter = 0;

        //itterate through all the bytes on the structure
        for (int r = 0; r < hDataCount; r++){
            //fill the data
            for (int c = 0; c < stride; c++){
                curPosition = (r * stride) + c;

                dataPro[curPosition + curOffset] = data[curPosition];
            }

            //reset offset counter
            offsetCounter = stride;

            //fill the offset
            do{
                curOffset += 1;
                dataPro[curPosition + curOffset] = 0;

                offsetCounter += 1;
            } while (offsetCounter % 4 != 0);
        }

        ptr = (System::IntPtr)dataPro;//set the data pointer to new/modified data array

        //calc the stride to nearest number which is a multiply of 4
        stride = (srcImg.size().width * srcImg.channels() + 3) & -4;

        retImg = gcnew System::Drawing::Bitmap(srcImg.size().width, srcImg.size().height,
            stride,
            System::Drawing::Imaging::PixelFormat::Format24bppRgb,
            ptr);
    }
    else{

        //no need to add a padding or recalculate the stride
        retImg = gcnew System::Drawing::Bitmap(srcImg.size().width, srcImg.size().height,
            stride,
            System::Drawing::Imaging::PixelFormat::Format24bppRgb,
            ptr);
    }
   
    array^ imageData;
    System::Drawing::Bitmap^ output;

    // Create the byte array.
    {
        System::IO::MemoryStream^ ms = gcnew System::IO::MemoryStream();
        retImg->Save(ms, System::Drawing::Imaging::ImageFormat::Png);
        imageData = ms->ToArray();
        delete ms;
    }

    // Convert back to bitmap
    {
        System::IO::MemoryStream^ ms = gcnew System::IO::MemoryStream(imageData);
        output = (System::Drawing::Bitmap^)System::Drawing::Bitmap::FromStream(ms);
    }

    return output;
}

Continue Reading...