Amadiere.com

Fourteen and a half crazy frog burpers

30th August 2010

Windows Phone 7: Getting Started Link-dump

Filed under: Windows Phone 7 — Alex Holt @ 5:25 pm

Windows Phone 7As you’re probably aware, Microsoft is finally going to attempt to enter the Smart Phone OS market with it’s new Windows Phone 7 operating system /platform / ecosystem. It’s going to have a hard time getting started (Android and particularly the iPhone OS have a gigantic lead and devoted user-base), but I think it has a good chance. Looking at some of the reviews of the hardware and it’s performance with the new OS, things are looking promising for the big M, if that is, they can pull off the marketing and get enough hardware vendors on-board.

One of the things Microsoft will be hoping on is a massive uptake of application developers, and to try and encourage that they’ve released and helped circulate a bunch of things to the community! This post hopes to point to some of the articles, videos, blogs and other sites by both Microsoft and others to help you learn and get started with WP7.

Obviously, before you get started, you want to download the various developer tools. They are currently in Beta and downloadable here. It’s been announced that the full non-Beta set of tools on the 16 September 2010. The tools are free – the only bit you pay for is a subscription that allows you to post applications to the Marketplace. That’s currently being listed as £67 GBP

Links:

Videos & Labs

More resources:

6th April 2010

Development SMTP Servers for IIS7.5 on Windows 7

Filed under: ASP.NET,C# — Tags: , , , , , — Alex Holt @ 3:43 pm

I’ve had one of them days. You know? That “simple task” that spiralled out of control and resulted in me losing half a day to it’s tricks! That task? It was sending an email from an ASP.NET (MVC2) application. Previously, I’ve always done this via setting up IIS and the SMTP server in there, but for some reason, Microsoft decided they didn’t want to include the SMTP Server in Windows 7 anymore (even ‘Ultimate’ – it might also be the case for Windows Vista). So, I had to find an alternative.

There were a few options available to me:

  • SMTP Server on Localhost: This was the obvious choice, but after trying Mercury Mail and it’s quarter of a million settings as it installed (I’m no Email Admin, so didn’t know the answer to all of them). It didn’t work and I’m not sure why. To rub salt into the would, there was no uninstall either – it proper irritated me and I gave up using it out of principal.
  • SMTP Server on Localhost that is really just a Relay. Well, sounded good – but again, it was designed by people with bigger brains than me and it failed to send to what I thought was a correctly configured IIS7.5 config pointing to my GMail account.
  • Fake Server: Something that doesn’t actually send emails, but pretends to.

The last one is the one I eventually choose and boy am I glad I did! I downloaded the excellent SMTP 4 DEV from Codeplex

  1. I don’t have 100′s of emails cluttering up my email box for starters. Win!
  2. It was so easy to set-up and it worked perfectly without a change to my code. Win!
  3. It’s free. Win!

Here is some fake code that should send an email to the localhost.

MailMessage emailMessage = new MailMessage();
string messageBody = "This is the content of the email will be awesome!";
 
emailMessage.Body = messageBody;
emailMessage.Priority = MailPriority.Normal;
emailMessage.From = new MailAddress("no-reply@amadiere.com"); // obviously, this email address doesn't exist :)
emailMessage.Subject = "The answer is 42";
emailMessage.IsBodyHtml = false;
 
SmtpClient mSmtpClient = new SmtpClient();
mSmtpClient.Host = "127.0.0.1";  // localhost
mSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
 
mSmtpClient.Send(emailMessage);

15th March 2010

Good Quality Image Resizing in C#

Filed under: C# — Tags: , , , — Alex Holt @ 8:40 pm

I encountered a little bit of a problem the other day with some image resizing code from within an ASP.NET MVC application that was misbehaving. The issue was just a general C# and ASP.NET one, not related to MVC or Webforms, but it was that for some reason the images were losing a significant amount of quality when resizing. I’m talking a pixel sharp 2000 x 2000 picture that when resized to 300 x 300, was woefully blurry. Initially, the code was simply using the GetThumbnailImage() method to produce it’s resizes, this turned out to be the mistake!

While GetThumbnailImage() is fine for small thumbnail images (the clue I guess, was in the name), it somewhat struggled on the larger versions. To fix the issue, I had to convert the image to a bitmap, faff about with it like that, then export it back to a Jpeg once I was done.

For future me (and anyone else this might help), here is the code I eventually settled on:

EncoderParameters encodingParameters = new EncoderParameters(1);
encodingParameters.Param[0] = new EncoderParameter(Encoder.Quality, 90L); // Set the JPG Quality percentage to 90%.
 
ImageCodecInfo jpgEncoder = GetEncoderInfo("image/jpeg");
 
// Incoming! This is the original image. This line can effectively be anything, but in this example it's coming from a stream.
var image = Image.FromStream(new System.IO.MemoryStream(Picture));
 
// Creating two blank canvas. One that the original image is placed into, the other for the resized version.
Bitmap originalImage = new Bitmap(image);
Bitmap newImage = new Bitmap(originalImage, 300, (image.Height * 300 / image.Width));  // Width of 300 & maintain aspect ratio (let it be as high as it needs to be).
 
// We then do some funky voodoo with the newImage. Changing it to a graphic to allow us to set the HighQualityBilinear property and resize nicely.
Graphics g = Graphics.FromImage(newImage);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
g.DrawImage(originalImage, 0, 0, newImage.Width, newImage.Height);
 
var streamLarge = new System.IO.MemoryStream();
newImage.Save(streamLarge, jpgEncoder, encodingParameters);
 
// This is the line that returns the picture to the relevant part of the model.
_event.Picture = streamLarge.ToArray();
 
// No need for all that drama for the thumbnail, the loss of quality isn't noticable.
var thumbnail = image.GetThumbnailImage(80, (image.Height*80/image.Width), null, new IntPtr(0));
var streamThumbnail = new System.IO.MemoryStream();
 
thumbnail.Save(streamThumbnail, jpgEncoder, encodingParameters);
 _event.ThumbnailPicture = streamThumbnail.ToArray();
 
// Good boy's tidy-up after themselves! :O
originalImage.Dispose();
newImage.Dispose();
thumbnail.Dispose();
streamLarge.Dispose();
streamThumbnail.Dispose();
Older Posts »

Theme designed & built for Amadiere.com by Alex Holt. Powered by WordPress