Solved

converting PHP code to C#

Posted on 2009-05-06
3
825 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
ID: 24322428
0
 

Author Comment

by:ninusajil
ID: 24322451
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
ID: 24323559
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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!
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

713 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