Andrew Coates ::: MSFT

It's all about community!

May, 2007

  • Andrew Coates ::: MSFT

    Resize Images - a Thumbnail Maker

    • 1 Comments

    Nic was hanging out with Nick (a combination that's just asking for trouble if you ask me) a couple of weeks ago near my desk, and Nic was bemoaning the lack of a resizing utility. This triggered something in the back of my mind and lo! I found a post by Rick Strahl on (almost) this very thing. I tweaked the code a little to turn it into a console app from a web app and built it.

    I added a shortcut to the exe both on my desktop and in my SendTo folder so now I can right-click on an image or images and send it to the resizer and it will do its magic.

    (508k) turns into this (23k):

    Pretty cool!

    Here's the code - most of it pinched directly from Rick remember. Note that in its current form, it makes the maximum dimension of the thumbnail 120px. You can change that at the top. I've also attached a zipped version of the solution to this post. Of course, this is provided as-is with no guarantees of stability, suitability or any other -ability. Use at your own risk, contents may be hot, don't run with scissors etc.

    You could add some nice bits like:

    • the ability to detect that it had been passed a folder and have the code traverse the folder and resize all the images therein.
    • the ability to set the max size as part of the command line
    • the ability to specify an output folder for files
    • Actually handling the exceptions in ErrorResult() :)

    Anyway, enough already. Go play!

     

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;
    
    
    namespace Resizer
    {
        enum ImageSize
        {
            Default = 120,
            Small = 120,
            Medium = 240,
            Large = 480,
            Custom
        }
        class Program
        {
            static void Main(string[] args)
            {
                foreach (string Image in args)
                {
                    // string Image = args[0];
                    if (Image == null)
                    {
                        ErrorResult();
                        return;
                    }
    
    
                    int Size = (int)ImageSize.Default;
    
                    //if (args.Length > 1)
                    //{
                    //    string sSize = args[1];
                    //    if (sSize != null)
                    //        Size = Int32.Parse(sSize);
                    //}
    
                    string Path = Image;
                    Bitmap bmp = CreateThumbnail(Path, Size, Size);
    
                    if (bmp == null)
                    {
                        ErrorResult();
                        return;
                    }
    
                    string OutputFilename = null;
                    FileInfo OutputFile = new FileInfo(Path);
                    OutputFilename = OutputFile.DirectoryName + "\\" + OutputFile.Name.Remove(OutputFile.Name.Length - (OutputFile.Extension.Length)) + "[" + Size.ToString().Trim() + "]" + OutputFile.Extension;
    
                    if (OutputFilename != null)
                    {
                        try
                        {
                            bmp.Save(OutputFilename);
                        }
    
                        catch (Exception ex)
                        {
                            bmp.Dispose();
                            ErrorResult();
                            return;
                        }
                    }
    
                    bmp.Dispose();
                    
                }
    
            }
    
            private static void ErrorResult()
            {
                //throw new Exception("The method or operation is not implemented.");
            }
    
            /// 
            /// Creates a resized bitmap from an existing image on disk.
            /// Call Dispose on the returned Bitmap object
            /// 
            /// Taken from Rick Strahl's code at 
            /// http://west-wind.com/weblog/posts/283.aspx
            /// 
            /// Bitmap or null
    
            public static Bitmap CreateThumbnail(string lcFilename, int lnWidth, int lnHeight)
            {
                Bitmap bmpOut = null;
    
                try
                {
    
                    Bitmap loBMP = new Bitmap(lcFilename);
                    ImageFormat loFormat = loBMP.RawFormat;
                    decimal lnRatio;
                    int lnNewWidth = 0;
                    int lnNewHeight = 0;
    
                    //*** If the image is smaller than a thumbnail just return it
                    if (loBMP.Width < lnWidth && loBMP.Height < lnHeight)
                        return loBMP;
    
                    if (loBMP.Width > loBMP.Height)
                    {
                        lnRatio = (decimal)lnWidth / loBMP.Width;
                        lnNewWidth = lnWidth;
                        decimal lnTemp = loBMP.Height * lnRatio;
                        lnNewHeight = (int)lnTemp;
                    }
                    else
                    {
                        lnRatio = (decimal)lnHeight / loBMP.Height;
                        lnNewHeight = lnHeight;
                        decimal lnTemp = loBMP.Width * lnRatio;
                        lnNewWidth = (int)lnTemp;
                    }
    
                    // System.Drawing.Image imgOut = 
                    //      loBMP.GetThumbnailImage(lnNewWidth,lnNewHeight,
                    //                              null,IntPtr.Zero);
    
                    // *** This code creates cleaner (though bigger) thumbnails and properly
                    // *** and handles GIF files better by generating a white background for
                    // *** transparent images (as opposed to black)
    
                    bmpOut = new Bitmap(lnNewWidth, lnNewHeight);
                    Graphics g = Graphics.FromImage(bmpOut);
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
                    g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
    
                    loBMP.Dispose();
                }
                catch
                {
                    return null;
                }
                return bmpOut;
            }
        }
    }
    
  • Andrew Coates ::: MSFT

    Review - Wireless Presenter Mouse 8000

    • 3 Comments

    Disclaimer: All of the products here are Microsoft hardware and I both work for and own shares in Microsoft.

    One of the things I do a lot of is presentations. Not just PowerPoints though, I also show the computer doing things, often with me making it do those things, so I need a mouse as well (right-click-dragging with the touch pad is not a great demo technique).

    I used to travel with a Presenter 3000 and a Wireless Notebook Laser Mouse 6000

    Presenter 3000 +  Wireless Notebook Laser Mouse 6000

    Both great, but each took up a USB port and each requires batteries.

    I've recently switched to a great hybrid device - the Wireless Notebook Presenter Mouse 8000 - hold it one way and it's a conventional high-precision mouse. Press the button and turn it over and it's a wireless presenter.

    Wireless Notebook Presenter Mouse 8000

    Features

    One
    Presentation Controls
    Smoothly navigate through Microsoft Office PowerPoint® and other presentations from up to 30 feet away from your PC.

    Two
    Media Remote
    Use for multimedia presentations and control digital entertainment from the comfort of your living room sofa.

    Three
    Battery Life Indicator
    You won't get caught with a dead battery—the Battery Status LED Indicator glows red when the battery is running low.

    Four
    2.4 GHz Bluetooth® with First Connect Technology
    Connect wirelessly right out of the box with 2.4 GHz Bluetooth®.

    Five
    High Definition Laser Technology
    Microsoft® High Definition Laser Mouse products are more precise, more responsive, and deliver smoother tracking.

    Six
    Laser Pointer
    Point out essential information during presentations with the laser pointer.

    It's been rock solid and is a pleasure to use. I like to get away from the computer when I'm telling a story or talking to slides, and I haven't yet been in a room big enough for it to lose connectivity, even when I wander right down the back.

    I do miss a couple of things from my combo pack above though. The dongle doesn't slot into the mouse anywhere like the Laser Mouse 6000 does, and there's no timer like there is on the Presenter 3000.

    All-in-all I give it 9.5/10.

  • Andrew Coates ::: MSFT

    Cool bag for TechEd Australia

    • 7 Comments

    UPDATE: Oops, this isn't the speakers' bag, it's the delegate's bag!

    One of the interesting discussions around TechEd each year is "What should the speaker delegate bag look like?". Well, this year, it'll look something like this:

    Sign up now! The early-bird discount expires soon.

  • Andrew Coates ::: MSFT

    .NET and Win32 Interop - New Toolkit Available

    • 4 Comments

    While I was prepping for some VFP sessions I delivered in Hong Kong last week, I pinged yag for some pointers from his DevCon keynote. In addition to a bunch of great info on Sedna and VFP 9.0 SP2, he pointed me at a really cool resource - the Microsoft Interop Forms Toolkit 2.0. This toolkit basically installs new templates into VS2005 that bootstrap the development of .NET controls and forms that can be included into Win32 applications including VB6 and VFP.

    I developed a couple of controls that I can just drop directly onto a VFP (or VB6) form to provide things that are easy to do in .NET, but are difficult in VFP. For example, the FileSystemWatcher control is great, it raises events when things change in the file system (file created, changed, deleted etc) so your app can react to those changes.

    You can also create composite .NET controls (made up of a number of individual controls) and expose them as a single interop control.

    The source for the demo I gave in Hong Kong is attached. Build the .NET project first, and then open the VFP project. You might be missing a couple of images in the composite control, but they're just for show.

    BTW, as per Rick's great post, there's a bunch of functionality also available in the FoxPro Foundation Classes including the System Tray class, and these don't require you to use .NET. As always, choose the most appropriate tool for the job.

  • Andrew Coates ::: MSFT

    Office Business Applications - Download or Free Hard Copy

    • 3 Comments

    Office Business Applications are really taking off. These apps leverage the comprehensive platform provided by the Office System. There's a great publication available from the guys at the architecture team at Microsoft.

    Office Business Applications: Building Composite Applications Using the Microsoft Platform

    This is available online on MSDN, as a download that you can read offline or in hard copy. If you really want a hard copy, drop me a note via the contact link and I'll send you one (while stocks last).

    Update - Shipping to Australia only!

  • Andrew Coates ::: MSFT

    ReMix Australia Registrations Now Open

    • 4 Comments

    I've had a couple of questions in response to my ReMix post about when registration will open. Frank's just announced it. Register here.

    [update - tags just for Nick: auremix07 mix07]

  • Andrew Coates ::: MSFT

    Slide decks from the Hong Kong Roadmap and Futures Event

    • 1 Comments

    I've just spent a couple of days in Hong Kong culminating in 3 presentations to VFP and VB6 developers about strategies for moving their applications forward to take advantage of the platform.

    The three decks are attached. I posted some of the sample code I presented in a previous post.

    In the afternoon I was also lucky enough to be around for the presentations from the Hong Kong finalists in this year's Imagine Cup. Lots of great ideas and some savage grilling from the judges.

    Thanks to Peter Ty and Samuel Cheng for the invitation and their hospitality.

    Decks

    Session 1 - Introduction to Technology Options for End User Computing (2 MB)

    Session 2 - Visual FoxPro 9.0 Technology Roadmap (350 kB) (Note that this session was borrowed, almost in its entirety, from yag's DevCon keynote)

    Session 3 - Visual Studio 2005 and .NET Framework for End User Computing (2.3 MB)

  • Andrew Coates ::: MSFT

    NSW.NET Speed Networking Event for Business Development Managers

    • 2 Comments

    Got this note from Dan Green this morning. Sounds like a great event!

    For those of you based in New South Wales.

    We have recently launched www.nswdotnet.com.au. We are really excited about the opportunities that this will create for development companies of all sizes in NSW.

    One of the first things we have planned is a speed networking event to connect NSW.NET members with other member organizations. This is based on the popular speed dating concept but with the aim of connecting like minded organizations instead.

    The speed networking event will be held at 5:30 on the Thursday 31st May at the MLC Centre in the city. If you would like to come, or you think someone else in your company would like to attend, it's as simple as registering at the following url:

    http://www.uniqueworld.net/News/Events/EventRegistration.aspx?EventID=107

    NSW.NET Membership is free and so is this event so don't be shy about signing up.

    This is something that should appeal to Business Development Managers or Managing Directors. If it is not something you are interested in then please consider passing it on to other interested parties in your organization.

    If you would like to join the cluster to stay informed about any upcoming events or opportunities please sign up at http://www.nswdotnet.com.au.

    Regards,

    Dan Green, Founding Member

    NSW.Net ICT Cluster Committee

    I'm really looking forward to seeing this.

  • Andrew Coates ::: MSFT

    Sydney Business and Technology User Group First Meeting - it was HUGE!

    • 0 Comments

    Last night I was fortunate enough to attend the inaugural meeting of the new Sydney Business and Technology User Group (or, as I like to refer to it, sbTug). Craig Bailey announced the group a week or so ago and I was very impressed with the great turnout of people from all over the community. The group aims to be a high-level technical and business group, particularly aimed at technical managers and senior technical people (more details on the site) and provides an excellent opportunity to connect with others in the same field and to discuss important issues facing managers and senior technical people.

    The standard format for meetings is networking and dinner followed by a business topic and then a technical topic. This month, Craig delivered the business topic - 5 Mistakes Software Managers Make. I was particularly impressed with the way Craig could draw on his specific experiences to make points that are generally applicable. Very appropriately, the technical topic was delivered by Adam Cogan and was an overview of the (relatively) new Visual Studio 2005 Team Edition for Database Professionals.

    The group meets on the last Wednesday of the month, so the next one is June 27 - put it in your diary now!.

  • Andrew Coates ::: MSFT

    ReMix Australia Accommodation Deal

    • 1 Comments

    In response to a comment on my ReMix post, I pinged Monique Eagles about an accommodation deal at the Crowne Promenade. Here's her response:

    Yes i do have a response and we are terribly sorry this didn’t make it yet to the website:

    REGISTRATION AND EVENT INFORMATION PAGE

    Accommodation blurb:

    Crown Promenade Hotel is located in the heart of the action - Melbourne’s vibrant Southbank entertainment precinct. Directly linked to the exciting Crown Entertainment Complex by airbridge, Crown Promenade Hotel is also close to the CBD, the Melbourne Exhibition Centre and many of the city’s most famous arts and sporting facilities. More information on Melbourne can be found at http://www.visitmelbourne.com.au/

    Crown Promenade Hotel
    8 Whiteman Street, Southbank 3006
    Melbourne Victoria
    Reservations +61 3 9292 6688
    Facsimile +61 3 9292 6600
    Toll free (within Australia): 1800 776 612

    www.crownpromenadehotel.com.au

    There is limited accommodation being held at Crown Promenade, available to Microsoft Remix delegates:

    AUD $210 00 Inc GST and one breakfast Standard Rooms

    AUD $265.00 Inc GST and one breakfast Studios

    AUD $440.00 Inc GST and one breakfast Suites

    · The rates quoted are based on single, twin or double occupancy. Subject to availability

    · Each delegate is responsible for payment of their accommodation, credit card details will be required for each booking

    · The special conference rate of AUD $210 is only available up to 14 days out from the event and is subject to availability (after this date Crown will offer regular published hotel rates based on availability)

    · Individuals are responsible for all room and incidental charges

    · Crown Promenade cancellation policies apply to all room bookings

    · Hotel check in time is 14.00, check out time is 11.00

    · All standard rooms in Crown Promenade Hotel are configured with either one (1) King bed or two (2) Queen beds. No additional bedding is permitted in standard rooms. The maximum number of registered persons in this type of room is three (3) adults OR two (2) adults and two (2) children under 15 years of age. No additional charge will apply when utilising existing bedding

    [Tags: auremix07 mix07]

Page 1 of 2 (11 items) 12