Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Sunday, June 10, 2018

Using System.Drawing to create an image thumbnail cropped at 1:1

Creating a thumbnail for an image is very easy if you are developing for .Net Framework or .Net Core, since both platforms offer the System.Drawing packages. The tricky solution is cropping the image in perfect square format without distorting or stretching the image.

The following code shows how to exactly do a center crop while generating a thumbnail, the original image needs to be scaled down to match size of the thumbnail while maintaining the aspect ratio first, then moved to an offset calculated previously such that the final drawing removes the pixels that were supposed to be cut off during the cropping. The offset represents the number of pixels of that side that require to be cropped off.

It should be kept in mind that on .Net Core the package must cover all platforms. For that case there are three nuget packages available for .Net Core for Windows, Linux, and OSX each.

Saturday, August 15, 2015

WCF Services - How to consume a Service without access to it

When working on a project that contains decentralized approach, different modules are deployed on different servers by different development teams and all that needs to be integrated with each other, there can be issues regarding accessing a web service that hasn't been published for access yet or is deployed on another domain with access restriction.

To access a contract for a service that is out of reach, Visual Studio provides a tool svcutil.exe that can generate a proxy for the service. This tool needs to be executed on the machine the service is deployed to in order for it to generate the required proxy.

Executing the svcutil.exe on command line with the following command will generate the proxy
C:\path> svcutil /t:code /language=cs http://<service address> /out:MyServiceProxy.cs /config:ServiceProxy.config
Now the generated .cs file can be added to the client application project to obtain the classes and method contracts. The endpoint configuration is generated in the .config file that can pe copied to the web.config file of the client application project.

If svcutil.exe is not available in the server machine, it is available for download in the internet as WCF Test Client package.

Monday, February 16, 2015

Kendo UI Grid - Server Side Paging, Filtering and Sorting

There are a number of ways a DataSource can be handled with a Kendo UI Grid. In this article we are going to talk about binding data from a remote location on to a Kendo UI Grid with server side paging, filtering and sorting to ensure server response is smallest and light as possible for quick loading and to be able to handle if the data has thousands of records (that can lead to oversized response objects or time outs). I will give example code snippets to form an understanding of the solution.

The Grid


Below is a Kendo UI Grid declaration for which we will implement the server side manipulation.