Answered by:
Draw Font in white, but font isn't white at all..

Question
-
User-1103495211 posted
I try to write some text in a image.
I want it in a rectange because i want to set the align to center in a part of the image.
It works but the quality of the written text is so very bad, it isn't even white ...
You can see where i write the text, the quality of the image is bad, you can see that on the place in the real image...
What can i do to solve that? And i whant white fonts not light blue fonts...My code is :
dbImage = ImageControl.ImageMerger.AddPNG(dbImage, ConfigurationManager.AppSettings["localPath"].ToString() + @"images\rectangleRound.png", ImageControl.PositionVertical.Top, ImageControl.PositionHorizontal.Left, 260, 190, paddingleft, paddingtop); if (Request["prijsex"] != null) { //Add Text Bitmap target = new Bitmap(260, 190, PixelFormat.Format32bppRgb); using (Graphics objGraphics = Graphics.FromImage(target)) { objGraphics.DrawImage(dbImage, 0, 0, 260, 190); // Set anti-aliasing for text to make it better looking objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; // Configure font to use for text System.Drawing.Font objFont = new Font("Arial", 10, FontStyle.Bold); //Write out the text string hexCol = "#FFFFFF"; RectangleF drawRect = new RectangleF(186, 134, 70, 20); RectangleF drawRectLeft = new RectangleF(146, 134, 70, 20); SolidBrush sb = new SolidBrush(System.Drawing.ColorTranslator.FromHtml(hexCol)); SolidBrush sred = new SolidBrush(Color.Red); StringFormat SF = new StringFormat(); SF.Alignment = StringAlignment.Center; objGraphics.DrawString("€" + Request["prijsex"].ToString(), objFont, sb, drawRect, SF); objGraphics.DrawString("€" + Request["prijsex"].ToString(), objFont, sb, drawRectLeft, SF); //Save objGraphics.Save(); } dbImage = (System.Drawing.Image)target; }
My generated image:
Saturday, April 17, 2010 6:32 AM
Answers
-
User1211441112 posted
public static void ResizeStream(int imageSize, Stream filePath, string outputPath, bool Watermark)
{
var image = Image.FromStream(filePath);int thumbnailSize = imageSize;
int newWidth, newHeight;if (image.Width > image.Height)
{
newWidth = thumbnailSize;
newHeight = image.Height * thumbnailSize / image.Width;
}
else
{
newWidth = image.Width * thumbnailSize / image.Height;
newHeight = thumbnailSize;
}var thumbnailBitmap = new Bitmap(newWidth, newHeight);
var thumbnailGraph = Graphics.FromImage(thumbnailBitmap);
thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbnailGraph.DrawImage(image, imageRectangle);if (Watermark)
{
Font font = new Font("Verdana", 24, FontStyle.Bold, GraphicsUnit.Pixel);
Color color = Color.FromArgb(50, 255, 255, 255);
SolidBrush brush = new SolidBrush(color);
Point atPoint = new Point((newWidth / 2) - (184 / 2), (newHeight / 2) - (17 / 2));
thumbnailGraph.DrawLine(new Pen(brush), new Point(0, 0), new Point(newWidth, newHeight));
thumbnailGraph.DrawLine(new Pen(brush), new Point(0, newHeight), new Point(newWidth, 0));
Color textcolor = Color.FromArgb(100, 255, 255, 255);
SolidBrush textbrush = new SolidBrush(textcolor);
thumbnailGraph.DrawString("€ Your text here", font, textbrush, atPoint);
}thumbnailBitmap.Save(outputPath, image.RawFormat);
thumbnailGraph.Dispose();
thumbnailBitmap.Dispose();
image.Dispose();
}- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, April 19, 2010 3:46 AM
All replies
-
User-1103495211 posted
I've put the original resoution in the image, after that it was something better... , but not enough...
target.SetResolution(original.HorizontalResolution, original.VerticalResolution);
Saturday, April 17, 2010 11:03 AM -
User1211441112 posted
public static void ResizeStream(int imageSize, Stream filePath, string outputPath, bool Watermark)
{
var image = Image.FromStream(filePath);int thumbnailSize = imageSize;
int newWidth, newHeight;if (image.Width > image.Height)
{
newWidth = thumbnailSize;
newHeight = image.Height * thumbnailSize / image.Width;
}
else
{
newWidth = image.Width * thumbnailSize / image.Height;
newHeight = thumbnailSize;
}var thumbnailBitmap = new Bitmap(newWidth, newHeight);
var thumbnailGraph = Graphics.FromImage(thumbnailBitmap);
thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbnailGraph.DrawImage(image, imageRectangle);if (Watermark)
{
Font font = new Font("Verdana", 24, FontStyle.Bold, GraphicsUnit.Pixel);
Color color = Color.FromArgb(50, 255, 255, 255);
SolidBrush brush = new SolidBrush(color);
Point atPoint = new Point((newWidth / 2) - (184 / 2), (newHeight / 2) - (17 / 2));
thumbnailGraph.DrawLine(new Pen(brush), new Point(0, 0), new Point(newWidth, newHeight));
thumbnailGraph.DrawLine(new Pen(brush), new Point(0, newHeight), new Point(newWidth, 0));
Color textcolor = Color.FromArgb(100, 255, 255, 255);
SolidBrush textbrush = new SolidBrush(textcolor);
thumbnailGraph.DrawString("€ Your text here", font, textbrush, atPoint);
}thumbnailBitmap.Save(outputPath, image.RawFormat);
thumbnailGraph.Dispose();
thumbnailBitmap.Dispose();
image.Dispose();
}- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, April 19, 2010 3:46 AM