Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
public static string PutHangul(int x, int y, int rot, string data)
        {
            if (data.Trim().Length == 0)
                return "";

            int aHeight;
            int aWidth;
            int i, j, k;
            Byte bb;
            string st;

            Font fnt = new Font(fname, fsize, fs, GraphicsUnit.Pixel);
            Bitmap tempBmp = new Bitmap(800, 600);
            Graphics g = Graphics.FromImage(tempBmp);

            SizeF s = g.MeasureString(data, fnt);
            Bitmap bmp = new Bitmap((int)s.Width, (int)s.Height);
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
            g = Graphics.FromImage(bmp);
            g.Clear(System.Drawing.Color.White);

            st = "";
            if ((rot == 0) || (rot == 2))
            {
                aHeight = (int)s.Height;
                aWidth = (((int)s.Width + 7) >> 3) * 8;
                st += "{" + "SG;" + String.Format("{0:0000}", x) + "," + String.Format("{0:0000}", y) + "," + String.Format("{0:0000}", aWidth) + "," +
                String.Format("{0:0000}", aHeight) + ",0,";
            }
            else
            {
                aHeight = (((int)s.Height + 7) >> 3) * 8;
                aWidth = (int)s.Width;
                st += "{" + "SG;" + String.Format("{0:0000}", x) + "," + String.Format("{0:0000}", y) + "," + String.Format("{0:0000}", aHeight) + "," + String.Format("{0:0000}", aWidth) + ",0,";
            }

            Brush tBrush = new SolidBrush(Color.Black);
            try
            {
                g.DrawString(data, fnt, tBrush, 0, 0);
            }
            catch (Exception ex)
            {
                fnt.Dispose();
                tBrush.Dispose();
                bmp.Dispose();
                tempBmp.Dispose();
                throw ex;
            }
            if (rot == 0)
            {
                j = 0;
                while (j < aHeight)
                {
                    i = 0;
                    while (i < aWidth)
                    {
                        bb = 0;
                        for (k = 0; k < 4; k++)
                        {
                            if ((i + k) < bmp.Width)
                            {
                                if (bmp.GetPixel(i + k, j) == System.Drawing.Color.FromArgb(255, 0, 0, 0))
                                {
                                    bb = (byte)(bb + (1 << (3 - k)));
                                }
                            }
                        }
                        bb += 48;
                        st += Convert.ToString((char)(bb));
                        i += 4;
                    }
                    j++;
                }
            }

            if (rot == 2)
            {
                j = aHeight - 1;
                while (j >= 0)
                {
                    i = aWidth - 1;
                    while (i >= 0)
                    {
                        bb = 0;
                        for (k = 0; k < 4; k++)
                        {
                            if ((i - k) < bmp.Width)
                            {
                                if (bmp.GetPixel(i - k, j) == System.Drawing.Color.FromArgb(255, 0, 0, 0))
                                {
                                    bb = (byte)(bb + (1 << (3 - k)));
                                }
                            }
                        }
                        bb += 48;
                        st += Convert.ToString((char)(bb));
                        i -= 4;
                    }
                    j--;
                }
            }

            if (rot == 1)
            {
                j = 0;
                while (j < aWidth)
                {
                    i = aHeight - 1;
                    while (i >= 0)
                    {
                        bb = 0;
                        for (k = 0; k < 4; k++)
                        {
                            if ((i - k) < bmp.Height)
                            {
                                if (bmp.GetPixel(j, i - k) == System.Drawing.Color.FromArgb(255, 0, 0, 0))
                                {
                                    bb = (byte)(bb + (1 << (3 - k)));
                                }
                            }
                        }
                        bb += 48;
                        st += Convert.ToString((char)(bb));
                        i -= 4;
                    }
                    j++;
                }
            }

            if (rot == 3)
            {
                j = aWidth - 1;
                while (j >= 0)
                {
                    i = 0;
                    while (i < aHeight)
                    {
                        bb = 0;
                        for (k = 0; k < 4; k++)
                        {
                            if ((i + k) < bmp.Height)
                            {
                                if (bmp.GetPixel(j, i + k) == System.Drawing.Color.FromArgb(255, 0, 0, 0))
                                {
                                    bb = (byte)(bb + (1 << (3 - k)));
                                }
                            }
                        }
                        bb += 48;
                        st += Convert.ToString((char)(bb));
                        i += 4;
                    }
                    j--;
                }
            }
            st += "|}";

            fnt.Dispose();
            tBrush.Dispose();
            bmp.Dispose();
            tempBmp.Dispose();

            return st;
        }


What I have tried:

C#
if (data.trim().length() == 0) {
	    	return "";
	    }
        
	    int aHeight;
        int aWidth;
        int i, j, k;
        Byte bb;
        String st;

        // Font fnt = new Font("", fsize, fs, GraphicsUnit.Pixel);
        BufferedImage  image  = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = image.createGraphics();
        g.setColor(Color.WHITE);
        g.setFont(new Font("Monospaced", Font.BOLD, 10));
        g.drawString(data, 10, 20);
        
        st = "";


That's all. Please help me!!!
Posted
Updated 1-Feb-21 1:54am
v2

This is not a code conversion service: we are not here to translate code for you.
Even if we did, what you would end up with would not be "good code" in the target language – they are based on very different frameworks, and what makes something work in one language does not always "translate" directly into another.
So what you end up with is very poor code, that is difficult if not impossible to maintain, that can’t be upgraded nicely, and that will cause you immense headaches if the original is changed. And it’ll be a nightmare to debug if it doesn’t work "straight out of the box".
Instead, use the source code as a specification for a new app written in and for the target language / framework and write it from scratch using the original as a "template". You will get a much, much better result that will save you a lot of time in the long run.
 
Share this answer
 
Code Rewrite[^] is the best way. Agree with other answer. Converters won't give you 100% converted code. Some libraries & 3rd party components code won't be available in all languages so Converter can't convert those section.

For simple/minimal code, you can use this opensource tool.
CS2J - C# to Java conversion tool[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900