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:
if (data.trim().length() == 0) {
return "";
}
int aHeight;
int aWidth;
int i, j, k;
Byte bb;
String st;
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!!!