다음 코드는 문자열을 가져 와서 메모리에있는 비트 맵에 추가 한 다음 BMP 파일로 저장합니다. 내가 가지고있는 코드는 다음과 같습니다.비트 맵 만들기 및 C# 파일 저장 비트 맵에 비어있는 텍스트 제공
string sFileData = "Hello World";
string sFileName = "Bitmap.bmp";
Bitmap oBitmap = new Bitmap(1,1);
Font oFont = new Font("Arial", 11, FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);
int iWidth = 0;
int iHeight = 0;
using (Graphics oGraphics = Graphics.FromImage(oBitmap))
{
oGraphics.Clear(Color.White);
iWidth = (int)oGraphics.MeasureString(sFileData, oFont).Width;
iHeight = (int)oGraphics.MeasureString(sFileData, oFont).Height;
oBitmap = new Bitmap(oBitmap, new Size(iWidth, iHeight));
oGraphics.DrawString(sFileData, oFont, new SolidBrush(System.Drawing.Color.Black), 0, 0);
oGraphics.Flush();
}
oBitmap.Save(sFileName, System.Drawing.Imaging.ImageFormat.Bmp);
나는 페인트의 BMP 파일을 볼 때 내가 가진 문제는, 비트 맵의 크기가 배경이 흰색, 올바르게 정의되어 있지만 텍스트가 자신입니까?
내가 뭘 잘못하고 있니?
+1 문제가 발견되기 전에 +1하지만 정의되기 전에'oGraphics'를 사용하기 때문에 예제가 작동하지 않습니다 –
아, 지금 업데이트 중입니다 ... –