Scott Hanselman

Getting ready for Mono, and The Importance of Being (Using) Constant(s)'

June 9, '04 Comments [1] Posted in Programming
Sponsored By

I was poking around in the nGallery site and found these gems, as nGallery is (stunningly) Mono Compliant.  I thought that #1 really hit home when it comes to the importance of using such (often thought silly) things like System.Environment.NewLine and System.IO.Path.DirectorySeparatorChar.  If there's a constant in the Framework, it's usually there for a reason.

Rule #1:  Never, ever, ever use the \ to seperate directories when doing any file I/O. Instead, use the System.IO.Path.DirectorySeparatorChar constant. This translates directly over to the *nix world and makes for a smooth transition in Mono.

Rule #2:  Just as most of us have learned case sensitivity in .NET, carry this forward to your file I/O operations, again, and make sure all files and directories are case sensitive.

Rule #3:  Make sure you don't compile your assemblies with the /incremental flag. Mono can't support incremental compilation. For more details on what "incremental compilation". [Jason Alexander

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

XBox Live still working out the MSN Messenger integration details...

June 9, '04 Comments [0] Posted in XML | Gaming
Sponsored By

Caught this as it happened.  Looks like the new Xbox alerts are still getting their kinks worked out, as this Blue Toast Alert didn’t look the way someone intended. :)

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Virtual Keyboard for PDAs and Laptops

June 9, '04 Comments [2] Posted in Musings
Sponsored By

Oh my, it's shipping (almost and finally)Photo of a laser creating an image of a Virtual Keyboard for use on a PDA (via Larkware)  But would I use it?  It's US$99, and they say it works with pretty much any PDA. 

But would it just collect dust?

You know why I'd get it?  To run with my TabletPC when it's in slate mode as a "Just-In-Time Keyboard.

This video I think says it all, it isn't fast enough for touch typists.  But, man you could sure impress J6P on airplanes.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Scaling/Resizing/Resampling an Image in ASP.NET

June 9, '04 Comments [10] Posted in ASP.NET | DasBlog
Sponsored By

A friend was an image in C# yesterday, and was commenting on how crappy the output looked.  His code was very similar to the code in dasBlog that resizes an image when an entry is email-to-blog'ed.

/// Copyright (c) 2003, newtelligence AG. (http://www.newtelligence.com)
/// <summary>

/// This function is used for thumbnailing and gets an image encoder
/// for a given mime type, such as image/jpeg
/// </summary>
/// <param name="mimeType"></param>
/// <returns></returns>
private ImageCodecInfo GetEncoderInfo(string mimeType)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.MimeType == mimeType)
{
return codec;
}
}
return null;
}

<SNIPPET>

string absoluteFileName = Path.Combine(binariesPath, fileName);
string thumbBaseFileName = Path.GetFileNameWithoutExtension(fileName)+"-thumb.dasblog.JPG";
string thumbFileName = Path.Combine(binariesPath, thumbBaseFileName);
Bitmap sourceBmp = new Bitmap(absoluteFileName);
if ( sourceBmp.Height > siteConfig.Pop3InlinedAttachedPicturesThumbHeight )
{
Bitmap targetBmp = new Bitmap(sourceBmp,new Size(
Convert.ToInt32(Math.Round((((double)sourceBmp.Width) * (((double)siteConfig.Pop3InlinedAttachedPicturesThumbHeight) / ((double)sourceBmp.Height))),0)),
siteConfig.Pop3InlinedAttachedPicturesThumbHeight));

ImageCodecInfo codecInfo = GetEncoderInfo("image/jpeg");
Encoder encoder = Encoder.Quality;
EncoderParameters encoderParams= new EncoderParameters(1);
long compression=75;
EncoderParameter encoderParam = new EncoderParameter(encoder,compression);
encoderParams.Param[0] = encoderParam;
targetBmp.Save(thumbFileName,codecInfo,encoderParams);

string absoluteUri = new Uri( binariesBaseUri, fileName ).AbsoluteUri;
string absoluteThumbUri = new Uri( binariesBaseUri, thumbBaseFileName ).AbsoluteUri;
entry.Content += String.Format("<div class=\"inlinedMailPictureBox\"> <a href=\"{0}\"><img border=\"0\" class=\"inlinedMailPicture\" src=\"{2}\"></a> <br> <a class=\"inlinedMailPictureLink\" href=\"{0}\">{1}</a></div>",absoluteUri, fileName, absoluteThumbUri);
scalingSucceeded = true;

</SNIPPET>

This code (above) works fine for extracting an image from an email and scaling (thumbnailing) it, but the result is fairly jaggy, and one would certainly expect better resampling than is seen in the image above.

I found this article on DevEx that seemed to offer these lines as a possible solution:

    g.SmoothingMode =SmoothingMode.HighQuality;
    g.InterpolationMode =InterpolationMode.HighQualityBicubic;
    g.PixelOffsetMode =PixelOffsetMode.HighQuality;

But there doesn't appear to be any visible change (to my eye) with these added.  Should the SmoothingMode be set to 'SmoothingModeAntiAlias' instead?  Smooth resampling of an image in C# certainly seems it should be a 'solved problem.'  Perhaps I'm not Googling well.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

The SQL Queen, Kimberly Tripp, is blogging!

June 9, '04 Comments [0] Posted in Programming
Sponsored By

Everyone once in a while someone says "So-and-so is blogging" and then a whoop goes up in the Blogosphere as folks update their blog rolls and link around. 

Often starts with a post like (this reads best when you do an impression of Rick Moranis in Ghostbusters):

Well...hey...uh...everyone else is blogging, so here's mine.  I plan many good things.  I hope to see you around here.  Here's a picture of my cat.

But not Kimberly Tripp.  Not only has she started a blog, but she's already populating it with good content.  Here's a gem: Stored Procs are NOT evil.

Enjoy...I'm sure Kim will regale us with her encyclopedic knowledge of SQL Server over the coming months.  If you have SQL problems, particularly in the areas of performance and tuning, Kim is The Man, er, The Woman.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.