Solved

converting PHP code to C#

Posted on 2009-05-06
3
801 Views
Last Modified: 2012-05-06
will u please help me to convert php code to C#
my php code is

<?php
 $data = explode(",", $_POST['img']);
 $width = $_POST['width'];
 $height = $_POST['height'];
 $image=imagecreatetruecolor( $width ,$height );
 $background = imagecolorallocate( $image ,0 , 0 , 0 );
 //Copy pixels
 $i = 0;
 for($x=0; $x<=$width; $x++){
  for($y=0; $y<=$height; $y++){
   $int = hexdec($data[$i++]);
   $color = ImageColorAllocate ($image, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
   imagesetpixel ( $image , $x , $y , $color );
  }
 }
 //Output image and clean
 //header( "Content-type: image/jpeg" );
 imagejpeg($image,"files/new.jpg");
 //imagedestroy( $image );
?>
0
Comment
Question by:ninusajil
  • 2
3 Comments
 
LVL 8

Expert Comment

by:Haris V
Comment Utility
0
 

Author Comment

by:ninusajil
Comment Utility
yes, i tried but that is asking to use .net 1 frame work iam using 2.0
0
 

Accepted Solution

by:
ninusajil earned 0 total points
Comment Utility
i got it as

 int height = Convert.ToInt32(50);
            int width = Convert.ToInt32(50);
            // create the image with desired width and height
            StreamReader objReader = default(StreamReader);
            objReader = File.OpenText(Server.MapPath("data.txt"));
            string pixel = objReader.ReadToEnd();
            Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            Graphics g = Graphics.FromImage(bmp);
            // now fill the image with blank color
            g.FillRectangle(new SolidBrush(Color.White), 0, 0, bmp.Width, bmp.Height);
            // now process every POST variable which

            // contains a pixel color

            for (int rows = 0; rows < height; rows++)
            {
                // convert the string into an array of n elements

                string[] row = (pixel + rows).ToString().Split(",".ToCharArray());
                for (int cols = 0; cols < width; cols++)
                {
                    // get the single pixel color value

                    string value = row[cols];
                    // if value is not empty (empty values are the blank pixels)

                    if (value != "")
                    {
                        // get the hexadecimal string (must be 6 chars length)

                        // so add the missing chars if needed

                        value = value.PadLeft(6, Convert.ToChar("0"));
                        // Convert the hex code color string to a standard color class.

                        int R = Convert.ToInt32(value.Substring(0, 2), 16);
                        int G = Convert.ToInt32(value.Substring(2, 2), 16);
                        int B = Convert.ToInt32(value.Substring(4, 2), 16);
                        System.Drawing.Color color = Color.FromArgb(R, G, B);
                        g.FillRegion(new SolidBrush(color), new Region(new Rectangle(cols, rows, 1, 1)));
                    }
                }
            }
            bmp.Save(Server.MapPath("~/PixelImage/test.jpg"), ImageFormat.Jpeg);
            g.Dispose();
            bmp.Dispose();
            objReader.Close();
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now