Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Sherihan

macrumors newbie
Original poster
Jul 21, 2013
1
0
I have the following C# coding to convert an uploaded bitmap image to Hex. I need to follow the algorithm to come ip with the same goal in objective C. Assume I have a UIImageView with an image selected from the Picture gallery. I need to convert this selected image to Hex and write to a text file.

Someone please give me a help to convert this code to Objective C. I have some knowledge in IOS development but have not much knowledge in Image processing.

This is my code,

Code:
Bitmap bm1 = (Bitmap)pictureBox1.Image;

            int PictureWidth = pictureBox1.Image.Width;
            int PictureHeight = pictureBox1.Image.Height;
            int PictureX;
            int PictureY;

            int NVImageWidth;
            int NVImageHeight;

            NVImageWidth = PictureWidth;
            NVImageHeight = PictureHeight;

            int Quotient;
            int Remainder;
            int wp;

            wp = 0;

            StreamWriter sw = new StreamWriter("D:\\Test.txt");

            for (PictureX = 0; PictureX <= PictureWidth - 1; PictureX++)
            {
                for (PictureY = 0; PictureY <= NVImageHeight - 1; PictureY++)
                {
                    Color c1 = bm1.GetPixel(PictureX, PictureY);

                    if ((PictureY % 8) == 0)
                    {
                        wp = 0;
                        wp = (c1.G!=0) ? 0 : 1;
                    }
                    else if ((PictureY % 8) == 7)
                    {
                        wp = (wp << 1) | ((c1.G!=0) ? 0 : 1);
                        sw.Write(string.Format("%{0:x2}", wp));
                    }
                    else
                    {
                        wp = (wp << 1) | ((c1.G!=0) ? 0 : 1);
                    }
                }
            }

            sw.Close();

even if someone has a better approach to do the same task, please do share your code with me

Thanks in advance
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.