Click here to Skip to main content
15,894,410 members
Home / Discussions / C#
   

C#

 
GeneralRe: Is this good code practice? Pin
PIEBALDconsult2-May-10 10:24
mvePIEBALDconsult2-May-10 10:24 
GeneralRe: Is this good code practice? Pin
venomation2-May-10 11:41
venomation2-May-10 11:41 
GeneralRe: Is this good code practice? Pin
PIEBALDconsult2-May-10 17:44
mvePIEBALDconsult2-May-10 17:44 
AnswerRe: Is this good code practice? Pin
venomation3-May-10 0:56
venomation3-May-10 0:56 
GeneralRe: Is this good code practice? Pin
PIEBALDconsult3-May-10 3:59
mvePIEBALDconsult3-May-10 3:59 
GeneralRe: Is this good code practice? Pin
Alaric_3-May-10 4:45
professionalAlaric_3-May-10 4:45 
GeneralRe: Is this good code practice? Pin
venomation3-May-10 5:04
venomation3-May-10 5:04 
QuestionCreate Image in WinForms vs Asp.net Pin
#realJSOP30-Apr-10 9:44
mve#realJSOP30-Apr-10 9:44 
I have some code that creates an image, and renders some text to it. In a winform app, this results in a reasonably attractive image. However, in Asp.Net, the very same code results in a very ugly image (the stroke width is uneven, and the anti-aliasing is just barely noticable). Can anyone explain why this happens, and even better, a provide solution?

If you want to try it yourself, here's the code:

// start image creation
Bitmap bmp          = new Bitmap(60, 30, PixelFormat.Format32bppArgb);
Graphics g          = Graphics.FromImage(bmp);
g.Clear(Color.Transparent);
g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.Default;
g.CompositingMode   = CompositingMode.SourceOver;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;

Font font   = new Font("MS San Serif", 17, FontStyle.Regular, GraphicsUnit.Pixel);
Size textSz = TextRenderer.MeasureText(title, font);
int x       = (int)((bmp.Width - textSz.Width) * 0.5);
int y       = (int)((bmp.Height - textSz.Height) * 0.5);
TextRenderer.DrawText(g, title, font, new Point(x, y), Color.Black );
bmp.RotateFlip(RotateFlipType.Rotate270FlipNone);
// end image creation

// only needed for the web page version
MemoryStream ms = new MemoryStream();
bmp.Save(ms,System.Drawing.Imaging.ImageFormat.Png);
Byte[] buffer = new Byte[ms.Length];
ms.Position = 0;
ms.Read(buffer, 0, (int)(ms.Length));
Response.ContentType = "image/png";
Response.BinaryWrite(buffer);
Response.Write(title);
// end of web page code

bmp.Dispose();
g.Dispose();


On the first line of code above, I had to fully qualify the last parameter in the WinForms app
(System.Drawing.Imaging.PixelFormat.Format32bppArgb)
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

AnswerRe: Create Image in WinForms vs Asp.net Pin
Luc Pattyn30-Apr-10 10:04
sitebuilderLuc Pattyn30-Apr-10 10:04 
GeneralRe: Create Image in WinForms vs Asp.net Pin
#realJSOP30-Apr-10 11:35
mve#realJSOP30-Apr-10 11:35 
GeneralRe: Create Image in WinForms vs Asp.net Pin
Luc Pattyn30-Apr-10 11:41
sitebuilderLuc Pattyn30-Apr-10 11:41 
GeneralRe: Create Image in WinForms vs Asp.net Pin
#realJSOP30-Apr-10 12:04
mve#realJSOP30-Apr-10 12:04 
GeneralRe: Create Image in WinForms vs Asp.net Pin
Luc Pattyn30-Apr-10 12:30
sitebuilderLuc Pattyn30-Apr-10 12:30 
GeneralRe: Create Image in WinForms vs Asp.net Pin
#realJSOP30-Apr-10 23:10
mve#realJSOP30-Apr-10 23:10 
GeneralRe: Create Image in WinForms vs Asp.net Pin
#realJSOP1-May-10 3:07
mve#realJSOP1-May-10 3:07 
GeneralRe: Create Image in WinForms vs Asp.net Pin
Luc Pattyn1-May-10 3:32
sitebuilderLuc Pattyn1-May-10 3:32 
GeneralRe: Create Image in WinForms vs Asp.net Pin
#realJSOP1-May-10 7:35
mve#realJSOP1-May-10 7:35 
GeneralRe: Create Image in WinForms vs Asp.net Pin
Luc Pattyn1-May-10 8:19
sitebuilderLuc Pattyn1-May-10 8:19 
GeneralRe: Create Image in WinForms vs Asp.net Pin
#realJSOP1-May-10 8:47
mve#realJSOP1-May-10 8:47 
GeneralRe: Create Image in WinForms vs Asp.net [modified] Pin
#realJSOP1-May-10 9:10
mve#realJSOP1-May-10 9:10 
GeneralRe: Create Image in WinForms vs Asp.net Pin
Luc Pattyn1-May-10 9:48
sitebuilderLuc Pattyn1-May-10 9:48 
GeneralRe: Create Image in WinForms vs Asp.net Pin
#realJSOP1-May-10 14:00
mve#realJSOP1-May-10 14:00 
QuestionPicture in Crystal Report Pin
SajjadZare30-Apr-10 8:55
SajjadZare30-Apr-10 8:55 
QuestionDirectshow.net pitch audio control Pin
akaiito30-Apr-10 7:26
akaiito30-Apr-10 7:26 
QuestionProblems with Label's Properties Pin
jonatan_55630-Apr-10 6:46
jonatan_55630-Apr-10 6:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.