Minggu, 23 Januari 2011

Very Simple .NET Thumbnail Creation Code


When I was working the update for my Ajax demo, I needed to create thumb nail from a director of photos. There are tons of tools out there to do this, but I thought I'd share the very simple code I used.


It takes all the jpgs in the root path and creates 160x120 thumbnails of them. It also copies the original photo into fullpath.

namespace ThumbNailer
{
class Program
{
static void Main(string[] args)
{
string rootPath = @'C:\Users\brada\Desktop\ForDemo';
string thumbPath = Path.Combine(rootPath, 'Thumb');
if (Directory.Exists(thumbPath)) DirectoryDelete(thumbPath);
Directory.CreateDirectory(thumbPath);

int imageNumber = 0;
foreach (string s in Directory.GetFiles(rootPath, '*.jpg'))
{
imageNumber++;
Console.WriteLine('{0}:{1}', imageNumber, s);
Image i = Image.FromFile(s);
Image thumb = i.GetThumbnailImage(160, 120, null, IntPtr.Zero);
thumb.Save(Path.Combine(thumbPath, GetName(imageNumber)));
}
}

static void DirectoryDelete(string directoryName)
{
foreach (string filename in Directory.GetFiles(directoryName))
{
File.Delete(filename);
}
Directory.Delete(directoryName);
}
static string GetName(int imageNumber)
{
return String.Format('{0}.jpg', imageNumber);
}
}
}

Update: A couple of folks asked me about how to do this in ASP.NET... Bertrand has a much more complete example of that here:


http://dotnetslackers.com/articles/aspnet/Generating-Image-Thumbnails-in-ASP-NET.aspx


http://weblogs.asp.net/bleroy/archive/2007/12/05/what-interpolationmode-and-compositingquality-to-use-when-generating-thumbnails-via-system-drawing.aspx



A Live Mesh Moment


While I was out in the bush near Krueger national park in South Africa recently I found a great use for Live Mesh... After a full day of seeing some excellent big game I had a ton of photos to show for my effort.

Later that night, back in the lodge, I was briefly able to get on the spotty, very low bandwidth wireless network to work for me. So I shared my pictures using live mesh and immediately shared getting a cloud hosted backup of my precious photos. As they were uploading I was thinking about how much I wanted to share this experience with my wife and kids who where half a world away and fast asleep.

I thought it would be fun to make the kitchen laptop display my latest pictures. So I "connected" to my wife's machine and effectively got a terminal server session from 10,000+ miles away. image

It was exactly like I was sitting at the keyboard of our kitchen laptop. Even over the very bad network, I was quickly able to change her screen saver to point to the new live mesh folder with my great pictures.

When they got up that morning, my five year old son was the first to notice pictures of giraffes and lions on the kitchen laptop! The magic of shared experiences through live mesh!

Throughout the trip whenever I was able to get a little network connectivity a few more pictures would get uploaded and by the time I got the MS office in Johannesburg my family had a full copy of my adventures.

Thanks Mesh.

DropThings: Open Source ASP.NET 3.5 AJAX Portal - new and improved

DropThings: Open Source ASP.NET 3.5 AJAX Portal - new and improved:

Omar AL Zabir (author of Building a Web 2.0 Portal with ASP.NET 3.5) updated his very cool ASP.NET AJAX Portal application with 3.5 features, Workflow Foundation and new C# 3.0 features. Play with it here: http://www.dropthings.com/

Check out the details...

image

.NET Framework 3.5 SP1 Allows managed code to be launched from a network share!

.NET Framework 3.5 SP1 Allows managed code to be launched from a network share!: "

This has got to be one of the most consistently asked for "features" of .NET from the start! Download .NET Framework 3.5 Service Pack 1

Run off a network share with local permissions - You have voted and we have listened! We have brought managed executables in line with native code executables in how they behave when run off a network share. Yea!

Vance has the full scoop.. If you want to send someone flowers for getting this done, it is Vance... he designed, coded, tested, cajoled, prodded, persisted and advocated strongly for the fix.

Download .NET Framework 3.5 Service Pack 1

FxCop 1.36 Released


David Kean announces FxCop 1.36 ReleaseFxCop

Here are a few of the goodness from David's blog:

  • 200+ bug fixes that reduce noise, missing analysis and rule crashes
  • Support for analyzing anonymous methods and lambda expressions
  • New option for skipping analysis over tool generated code
  • Spell checker libraries now ship in the box
  • Changes in the way references are resolved and located
  • Better support for C++/CLI and the Compact Framework
  • Language 'friendly' API names in the UI and resolutions (ie Visual Basic syntax if running over a Visual Basic binary)
  • New globalization, design and usage rules
  • New rule for targeting specific versions of the Framework (I'll talk about this in a future post)
  • Performance improvements that cut analysis by 2x and use half as much memory
  • Documentation that is now available on MSDN
  • download it now -- it is totally free! You can also tell us what you think in the Code Analysis forum.

    Book Plug: Advanced ASP.NET AJAX Server Controls For .NET Framework 3.5


    View Larger Cover ImageI recently got a copy of Advanced ASP.NET AJAX Server Controls For .NET Framework 3.5. This promises to be a great book. With .NET Framework 3.5, Ajax is really interesting the mainstream and the Ajax Server Controls make it very easy for the millions of ASP.NET developers to easily take advantage of the power Ajax offers.

    Enjoy it!

    image This is the first book in the .NET Development Series to come out since I was asked to be on the editorial board for the series. It is great to get a chance to work with John Montgomery and Don Box. While the only pay I get for this gig is free books, I am excited to be able to help connect the industry experts on the most important technologies to the widest possible audience. If you do have title or author suggestions for the .NET Development Series, please let me know.

    Building Business Applications with Silverlight?

    I'd love to hear feedback and thoughts you have about building business focused applications with Silverlight. What is motivating you to consider Silverlight? if you have already started to evaluating, what is easy or hard about it?
    Related, Blaine recently posted a survey on his blog about much the same thing focused on gathering data for Prism 2.0
    Thanks!