Andrew Coates ::: MSFT

It's all about community!

  • 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

    Training and More

    • 4 Comments

    I've just spent 4 days of last week on Readify's excellent Industrial Strength .NET Course, lead by the incomporable Mitch Denny. Things really started to hot up on the last day when we discussed the merits of natural vs artificial primary keys in tables (try as we might, we couldn't get Mitch to see the light <g>). Mitch also proposed the ditching entirely of SQL to be replace with an object-oriented construct something like:

    objectDataSet Customers = new objectDataSet("select * from Customers");
    objectDataSet ImportedCustomers = new objectDataSet("Select * from ImportTable");
    objectDataSet MissingCustomers = ImportedCustomers - Customers;

    An interesting overloading concept, but it leaves a lot of questions unanswered.

  • Andrew Coates ::: MSFT

    MapPoint Web Service COM wrapper and VFP Sample

    • 2 Comments

    I've been talking about this for a while, and I've finally uploaded a COM wrapper around the MapPoint Web Service and a sample VFP form that shows the Find and Render services. You can grab them both from Darren's most excellent ProjectDistributor site.

    To use them, you'll need a MapPoint WS eval account, or, if you're an MSDN subscriber Sign up for a MapPoint Web Service Developer Account. If you want to explore the SDK, you can get it here.

  • Andrew Coates ::: MSFT

    Enterprise Library Webcasts

    • 3 Comments

    As David Hayden notes in this post, the Patterns and Practices team has a series of webcasts about the recently released Enterprise Library. Some have already happened, some are still to come, but all are or will be available as recordings.

    Note: All Webcast times are Pacific Standard Time (GMT-8:00)
    To get to Australian Eastern Daylight Time (GMT+11), subtract 5 hours and add a day. After that, you're on your own. I have translated the dates into DD/MM/YYYY from the wierd format the yanks use.

    Date

    Title/Abstract

     

    3/3/2005

    11:00

     

     

    Enterprise Library Overview

    Enterprise Library is the next generation of the patterns & practices Application Blocks. This guidance is designed to assist developers with common enterprise development challenges and will deliver the most widely used blocks into a single integrated package. Our vision is to build a broad community of customers and partners using, sharing and extending their own Application Blocks that are consistent with and integrate into the patterns & practices Enterprise Library.

    Register

    4/3/2005

    11:00

     

    Enterprise Library Configuration Application Block

    Configuration data is a constant challenge for application development.  The way in which your application handles configuration data dramatically impacts its manageability.  In this webcast we will discuss the requirements for building a great configuration system and how you can leverage the configuration application block to meet these requirements.

    Register

    8/3/2005

    11:00

     

    Enterprise Library Data Access Application Block
    Discover how you can implement the recommended data access architecture using Enterprise Library to quickly build a robust and secure data access layer which supports connectivity to SQL Server, Oracle and DB2.

    Register

    10/3/2005

    11:00

     

    Enterprise Library Caching Application Block

    Properly designed caching can make your system more robust and increase performance dramatically, poorly designed caching adds unnecessary overhead and provides little benefit.  Learn how you can make use of the new caching application block to help lessen the demand on your back-end systems while increasing throughput.

    Register

    14/3/2005

    11:00

     

    Enterprise Library Logging & Instrumentation Application Block

    Properly instrumented applications are a dream to manage, they tell what is happening and when things are going wrong point you to the source of the problem quickly increasing your mean time to recovery resulting in increased system availability.  In this webcast you will learn how to use the Enterprise Library logging and instrumentation block to consistently and easily build an application that tells you where it hurts.

    Register

    17/3/2005

    11:00

     

    Enterprise Library Exception Handling Application Block

    Exceptions happen...the question is what you will do to handle them.  Poorly written applications behave unpredictably when exceptions occur and often this bad behavior results in crashes or security holes.  Learn how you can create exception policies that can be consistently and quickly applied in your application to insure predictability even when things go wrong.

    Register

    22/3/2005

    13:00

     

    Enterprise Library Cryptography Application Block

    So you have a secret...what are you going to do with that credit card number, connection string or password?  Stuff in a secret place and hope that no one ever finds it?  Of course not, you want to encrypt it.  But how?  With the Enterprise Library cryptography block you can quickly encrypt and decrypt these secrets allowing you to secure them and sleep better at night.

    Register

    24/3/2005

    9:00

     

    Enterprise Library Security Application Block

    Every enterprise needs security and within most large enterprises there are many different security systems.  Discover how Enterprise Library’s security block can help you to put a consistent API in front of many different back end implementations allowing you to use these security systems without having to become an expert in them.

    Register

    28/3/2005

    11:00

     

    Enterprise Library - Building your own application block

    So you love application blocks?  You want to create your own and share it with your colleagues, your enterprise...the world?  Great!  We want to help you.  In this session we will walk through a simple application block to consider how you can build a block that integrates with the rest of Enterprise Library.

    Register

    31/3/2005

    11:00

     

    Enterprise Library Applied

    You stand at your manager’s door working up the courage to walk in and tell them that you want to use Enterprise Library in your next project.  There are so many questions about support, licensing, maintenance and futures...good thing you listened to this webcast to understand what it means for an enterprise to adopt this library.  As you listen to real examples from enterprises like yours to understand how they are managing the risks and opportunities associated with Enterprise Library

    Register

     

  • Andrew Coates ::: MSFT

    VSTO 2.0 Demo Videos

    • 2 Comments

    I've been meaning to blog about this for ages, but better late than never I guess.

    One of the questions to which I get the most positive response when showing the great new features in VS2005 (or even VS2003 for that matter) is "Who here would laike to be able to write .NET applications that live inside Word or Excel?". Especially in financial institutions, law firms and beauracracies (but in plenty of other places as well), there are light bulbs going off over the developers' heads as they realise that their users don't have to ever leave thier beloved Office app to get the functionality they need -- no mater what that functionality is!

    Over on the VSTO 2.0 blog, Kathleen McGrath has been posting links to video tutorials showing how to do a bunch of great things in VSTO 2.0. Here's what she's posted so far:

    Dunno if that's the lot or not, but either way, these are well worth a look.

  • Andrew Coates ::: MSFT

    VSTO v3 Deployment Session

    • 3 Comments

    I had a great time over the last couple of days hanging out with Christen Boyd and some of the other folk from the VSTO team here in Seattle. This culminated yesterday with a webcast of the session I’ll be doing here next week and then again at TechEd in Sydney. As promised, here are my slides from that session.

    I’ve added one blog to the list of resources. I had the pleasure of meeting Kris Makey yesterday and his VSTO deployment blog is great. Subscribed.

    Here is a summary of the VSTO resources I list at the end of the deck:

    MSDN

    Code Gallery

    Blogs

    Webcasts/Screencasts

  • Andrew Coates ::: MSFT

    Visual FoxPro - Do we still sell that?

    • 2 Comments

    Internally, especially when I'm wearing my cool VFP 9.0 shirt, this has to be one of the most common questions I hear. Of course, the answer is YES! David Anderson has written an opinion piece on DevX entitled Visual FoxPro 9.0: Still Here, Still Relevant. The article has an interesting history of Visual FoxPro and a discussion about why it will never be a .NET CLR language.

    If you want to get more information about the history of VFP, check out www.FoxProHistory.org.

    There are a number of VFP links in the links section of this blog.

  • Andrew Coates ::: MSFT

    Canberra VSTS User Group Rocks the House

    • 2 Comments

    It's 8am and I'm sitting in the inaugural meeting of the Canberra VSTS User Group. The turn-out is amazing. Over 40 professionals are crammed into the room in the Canberra MS office. This is a sensational turn out. Kudos to Grant, Sean and Mitch.

    Grant kicked off with news, tips and tool of the month (he chose Brian Harry's TFSServerManager Power Toy).

    Andrew Lyons talked about his experience migrating a 100 developer government department (DEWR) from a VSS environment to TFS (for source control mainly). His final word(s):

    Planning is Key

    • Particularly with initial deployment
    • Disaster recovery plan
    • Security Plan

    Practice Makes Perfect

    • Non-trivial migrations need trial runs
    • A development TFS server is invaluable

    Next, Sean Ferguson talked about branching and merging in the ATO development environment. A couple of things that stood out for me were a reference to Buck Hodges' great post from 2004 on branching models and the usefulness of the TFS Power Tools (see also Brian's post).

    Finally, Stu and Rick from AFP talked about their experience with branching there. One of their main points was that there needs to be a lot of work done to introduce the TFS culture to the dev team (especially as many of the current devs have strongly entrenched opinions about the current process and are resistant to any sort of change).

    All-in-all a great first meeting and I'm looking forward to the next one on Feb 28!

  • Andrew Coates ::: MSFT

    Learning Online with Virtual Labs - ASP.NET Virtual Labs

    • 4 Comments

    Celebrate the new Financial Year with another great set of labs. ASP.NET Virtual Labs (from the MSDN Suite of Virtual Labs)

    With ASP.NET you create richer Web applications with fewer lines of code. These virtual labs teach you about the innovations that debuted with ASP.NET 1.x and introduces you to the major improvements introduced with ASP.NET 2.0. These include dozens of new controls, new Membership and Profile application services and support for creating multiple pages based on a common template using Master Pages. Begin exploring Web development with ASP.NET and Visual Web Developer 2005 Express Edition today.

    What's new in ASP.NET 2.0
    Virtual Lab Express is the fastest and easiest way to test drive Microsoft products and the Virtual Lab environment. These are 20-minute hands-on overviews of some of your favorite Microsoft products and developer tools. Try them out online now - no need to download full trial versions or dedicate test machines.

    ASP.NET 2.0 Virtual Labs

    ASP.NET Virtual Labs

    Fritz Onion's Intro to ASP.NET Virtual Labs

    You get a downloadable manual and a 90-minute block of time for each module. You can sign up for additional 90-minute blocks at any time.

  • Andrew Coates ::: MSFT

    Online Study group for Beta Exam 71-528

    • 6 Comments

    A bunch of us (keen, or is that masochistic, local developers) have signed up for the beta version of the 70-528 exam — TS: Microsoft .NET Framework 2.0 - Web-based Client Development (called 71-528 while it's in Beta).

    Exam 70-528, is one of two exams required for the "Microsoft Certified Technology Specialist: .NET Framework 2.0 Web Applications" credential. To achieve this credential you will also need to pass exam "70-536: TS: Microsoft .NET Framework 2.0 - Application Development Foundation". After achieving the Technology Specialist credential for Web applications, you will be able to achieve the "Microsoft Certified Professional Developer: Web Developer" credential by passing one additional exam: "70-547: PRO: Designing and Developing Web Applications by Using the Microsoft .NET Framework."

    All of the new exams will be Beta tested prior to general release.

    The problem with doing a Beta exam is that there’s not a lot of material to study from. To help with the study process, Tatham Oddie has set up an irc server and we’ll be chatting twice a week for a couple of hours in a study session for the next couple of weeks. I’ve done beta exams in the past (back in the days of VFP 6.0) and the chat format worked very well. It’s also great to have the chat transcript to review and for others to use as an aide.

    Update: Andrew Higginbottom points out that:

    there are some online MS courses for VS2005 (4 for webforms dev) that are free if you sign up before 8 nov and once downloaded the content is valid until feb 2006.
    I'm yet to do any but they seem OK from a quick look...
    https://www.microsoftelearning.com/visualstudio2005/default.aspx

    The schedule for study (all times Australian Eastern Daylight Time [UTC+11])

    Monday 31 October 1930 – 2130

    Wednesday 2 November 1930 – 2130

    Monday 7 November 1930 – 2130

    Wednesday 9 November 1930 – 2130

    Monday 14 November 1930 – 2130

    Wednesday 16 November 1930 – 2130

    Chat server details

    • Server: irc.fueladvance.com
    • Port: 6667 (standard)
    • Channel: #Exam71-528

    So, if you're signed up for the beta exam, or if you just want to get a head start on the new certs, please join us next Monday

Page 4 of 47 (468 items) «23456»