Click here to Skip to main content
15,894,630 members
Articles / Programming Languages / C#

Open Source QRCode Library

Rate me:
Please Sign up or sign in to vote.
4.92/5 (147 votes)
20 Sep 2007CPOL1 min read 6M   192.3K   421  
How to use QRCode library to encode and decode QRCode
using System;
using QRCodeImageReader = ThoughtWorks.QRCode.Codec.Reader.QRCodeImageReader;
namespace ThoughtWorks.QRCode.Geom
{
	/// <summary> This class designed to move target point based on independent axis.
	/// It allows move target coodinate on rotated, scaled and gauche QR Code image
	/// </summary>
	public class Axis
	{

        internal int sin, cos;
        internal int modulePitch;
        internal Point origin;

        virtual public Point Origin
		{
			set
			{
				this.origin = value;
			}
			
		}
		virtual public int ModulePitch
		{
			set
			{
				this.modulePitch = value;
			}
			
		}
		
		public Axis(int[] angle, int modulePitch)
		{
			this.sin = angle[0];
			this.cos = angle[1];
			this.modulePitch = modulePitch;
			this.origin = new Point();
		}
		
		public virtual Point translate(Point offset)
		{
			int moveX = offset.X;
			int moveY = offset.Y;
			return this.translate(moveX, moveY);
		}
		
		public virtual Point translate(Point origin, Point offset)
		{
			Origin = origin;
			int moveX = offset.X;
			int moveY = offset.Y;
			return this.translate(moveX, moveY);
		}
		
		public virtual Point translate(Point origin, int moveX, int moveY)
		{
			Origin = origin;
			return this.translate(moveX, moveY);
		}
		
		public virtual Point translate(Point origin, int modulePitch, int moveX, int moveY)
		{
			Origin = origin;
			this.modulePitch = modulePitch;
			return this.translate(moveX, moveY);
		}
	
		public virtual Point translate(int moveX, int moveY)
		{
			long dp = QRCodeImageReader.DECIMAL_POINT;
			Point point = new Point();
			int dx = (moveX == 0)?0:(modulePitch * moveX) >> (int) dp;
			int dy = (moveY == 0)?0:(modulePitch * moveY) >> (int) dp;
			point.translate((dx * cos - dy * sin) >> (int) dp, (dx * sin + dy * cos) >> (int) dp);
			point.translate(origin.X, origin.Y);
			return point;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Malaysia Malaysia
A programmer for a long time, and still learning everyday.

A supporter for open source solutions, and have written quite a few open source software both in .NET and Java.

https://mengwangk.github.io/

Comments and Discussions