Solved

converting PHP code to C#

Posted on 2009-05-06
3
827 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Converting PHP triple des decrypt to c# 9 162
Include MS Database in Winforms Project using Intellilock 5 34
aspx ascx, c# 7 41
Copy files and run psex to windows 7 only 14 44
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

737 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