J
John J. Hughes II
The following code throws a out of memory exception, I have another function
that does the same thing using the bitmap lock but its way slow. Anyone
know how to fix this one?
public static Bitmap GetClonedBitmap(int width, int height, string str, Font
font, StringAlignment Alignment)
{
Rectangle r = new Rectangle(1, 1, width-1, height-1);
using (Bitmap tmpBmp = new Bitmap(width, height))
{
using (Graphics g = Graphics.FromImage(tmpBmp))
{
g.FillRectangle(Brushes.White, r);
using (StringFormat sf = new
StringFormat(StringFormat.GenericDefault))
{
sf.Alignment = Alignment;
sf.Trimming = StringTrimming.None;
sf.LineAlignment = StringAlignment.Center;
sf.FormatFlags = StringFormatFlags.NoWrap;
g.DrawString(str, font, Brushes.Black, r, sf);
return tmpBmp.Clone(r, PixelFormat.Format1bppIndexed);
}
}
}
}
Regards,
John
that does the same thing using the bitmap lock but its way slow. Anyone
know how to fix this one?
public static Bitmap GetClonedBitmap(int width, int height, string str, Font
font, StringAlignment Alignment)
{
Rectangle r = new Rectangle(1, 1, width-1, height-1);
using (Bitmap tmpBmp = new Bitmap(width, height))
{
using (Graphics g = Graphics.FromImage(tmpBmp))
{
g.FillRectangle(Brushes.White, r);
using (StringFormat sf = new
StringFormat(StringFormat.GenericDefault))
{
sf.Alignment = Alignment;
sf.Trimming = StringTrimming.None;
sf.LineAlignment = StringAlignment.Center;
sf.FormatFlags = StringFormatFlags.NoWrap;
g.DrawString(str, font, Brushes.Black, r, sf);
return tmpBmp.Clone(r, PixelFormat.Format1bppIndexed);
}
}
}
}
Regards,
John