Showing posts with label codex. Show all posts
Showing posts with label codex. Show all posts

Thursday, 6 February 2014

Write text on a image C#

 Write text on an image c# code:



 FileStream fs = new FileStream(@"d:\certificate.jpg", FileMode.Open, FileAccess.Read);
            System.Drawing.Image image = System.Drawing.Image.FromStream(fs);
            fs.Close();

            Bitmap b = new Bitmap(image);
            Graphics graphics = Graphics.FromImage(b);


            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            SizeF s = graphics.MeasureString("[The Employee Name]", new Font("Thaoma", 70, FontStyle.Bold));
            RectangleF rectf = new RectangleF(950, 1450, 1200, 150);
            float fontScale = Math.Max(s.Width / rectf.Width, s.Height / rectf.Height);

            // graphics.DrawString("[The Employee Name]", new Font("Thaoma", 70, FontStyle.Bold), Brushes.Black, 1000, 1450, sf);

            using (Font font = new Font("Thaoma", 70 / fontScale, GraphicsUnit.Point))
            {
                //Employee Name
                graphics.DrawString("[The Employee Name]", new Font("Thaoma", 70, FontStyle.Bold), Brushes.Black, rectf, sf);

            }
            graphics.DrawString("01/01/2014", new Font("Thaoma", 45), Brushes.Black, 1200, 2100);//Date
            graphics.DrawString("My Office", new Font("Thaoma", 45), Brushes.Black, 1200, 2300);//Held at

            b.Save(@"d:\certificate1.jpg", image.RawFormat);

            image.Dispose();
            b.Dispose();
:) Enjoy

Saturday, 2 November 2013

how to select nth row in sql server without using row_number() and without using order by?

how to select nth row in sql server without using row_number() and without using order by??
Also without using cursors.(cursor can be one of the solution, but it decreases the performance when there are lacs of records.)

 

 

Solution:

 

declare @NewId bigint,@NewFname varchar(20),@NewLname varchar(20),@NewSalary money   select top 5 @NewId =eid,@NewFname = fname @NewLname=lname,@NewSalary=salary from Tbl_Emp_Detail   select @NewId ,@NewFname,@NewLname,@NewSalary

 

OR

declare @NewId bigint   select top 5 @NewId=eid from Tbl_Emp_Deatail   select * from Tbl_Emp_Detail where eid=@NewId

 

 

Here replace top 5 by top 'n' 

view my answer in codeproject.com

thank you :)

Sunday, 11 November 2012

Want to Execute/Run your Programs online???

Do you wan to compile and run your programs online instead of installing heavy IDEs in your PC ??

Then go to following sites..:

1.Ideone.com

2.codepad.org

And many other such sites are available, just get them from google.!. 

In Ideone.com you can compile/ debug C,C++,C#,JAVA,Perl,PHP.etc etc more than 40 languages.

Instead of installing huge IDEs its a better and simpler way to compile your simple programs..

Enjoy :)

Sunday, 14 October 2012

how to swap two numbers without using temporary variable and without using arithmetic operators.?

In previous post i had mentioned about how to swap two numbers without using temporary variable. But how to swap two numbers without using temporary variable as well as without using arithmetic operators.?

You might  have seen this question in any of the coding competitions or technical interviews.

It can be done using xor  operator

So i think its quite tricky than the previous question (previous post). Because students will not be familiar with these kind of operators. 

So i think it might be helpful for many students or coding geeks..

 

The code for the same is given below:

 

#include
void main()
{
    //swapping without using temporary variable
    //as well as without using arithmetic operators
    int a=100,b=200;


    printf("\nBefore swapping a:%d, b=%d",a,b);

    a=a^b;
    b=a^b;
    a=a^b;

    printf("\nAfter swapping a:%d, b=%d",a,b);

    getch();

}


output: 


Before swapping a:100, b=200
After swapping a:200, b=100

Also see my previous post on how to swap two numbers without using temporary variable and using arithmetic operators. 


how to swap two numbers without using temporary variable.?

Its very easy to swap two numbers using temporary variable. but how to swap without using temporary variable.?

This is one of the question in most of the coding competitions and technical interviews.

So i think it might be helpful for many students or coding geeks..

It can be done using arithmetic operators

The code for the same is given below:

 

#include
void main()
{
    //swapping without using temporary variable
    //but usng arithmetic operators
    int a=15,b=20;
    clrscr();

    printf("\nBefore swapping a:%d, b=%d",a,b);

    a=a+b;
    b=a-b;
    a=a-b;

    printf("\nAfter swapping a:%d, b=%d",a,b);

    getch();

}


output:

 Before swapping a:15, b=20