Converting Windows Bitmaps to XNA

If you have ever wondered how to convert Windows Bitmaps into XNA textures then wonder no more. This method will do it for you. It is not particularly elegant (or fast) but it will let you take images off your PC (or the web) and put them into textures for use in XNA programs. Note that this will only work on XNA programs that are running on a Windows PC, the Xbox is not allowed to do this kind of thing at all. You need to add a reference to System.Drawing to your project and use the System.Drawing namespace.

Some of the code is a bit messy because of namespace clashes, and I'm sure there is a neater way of doing this. But it does work.

private Texture2D XNATextureFromBitmap(
              
System.Drawing.Bitmap b, GraphicsDevice device)
{
    Texture2D xnaTexture =
               new Texture2D(device, b.Width, b.Height);

    Microsoft.Xna.Framework.Graphics.Color[] dots =
         new Microsoft.Xna.Framework.Graphics.Color
                                           [b.Width * b.Height];

    int x;
    int y;
    int pos = 0;

    for (y = 0; y < b.Height; y++)
    {
        for (x = 0; x < b.Width; x++)
        {
            System.Drawing.Color sourceColor = b.GetPixel(x, y);
            dots[pos].A = 0xff;
            dots[pos].R = sourceColor.R;
            dots[pos].G = sourceColor.G;
            dots[pos].B = sourceColor.B;
            pos++;
        }
    }

    xnaTexture.
           SetData<Microsoft.Xna.Framework.Graphics.Color>(dots);

    return xnaTexture;
}

Adverts on Exams

One of my students has noticed that some institutions are now selling advertising space on their sample exam papers:

http://consumerist.com/5100958/teacher-sells-ads-on-tests-to-cover-printing-costs

I told him that I've got a few companies lined up for mine:

  • "Hutchinsons Resit Revision Aids"
  • "Johnsons Find and Destroy Lecturer Service"
  • "NeverRunOut pens Inc."
  • "The Cheater's Tattoo Parlour"

Deep Zooming with Ed

Ed Dunhill from Microsoft came to see us today as part of the Inspiration Tour. He gave an excellent talk to a whole bunch of students. One of the things he showed us was Silverlight and Deep Zoom. This is wonderful. A bit like Photosynth, but you can create your own images into which web users can zoom and zoom and zoom. And zoom. Don't take my word for it, have a look at the Hard Rock Memorabilia site.

If you want to make your own Deep Zoom pictures you can download the Deep Zoom Composer for free here.

Microsoft are Coming to See Us Tomorrow

A quick reminder to anyone at Hull who reads my blog. That's both of you...

Microsoft are coming to see us tomorrow. They are taking their Inspiration Tour on the road and will be giving their presentation starting at 2:15 pm in the Physics Large Lecture Theatre, which is in the same building as the Computer Centre, but up the big stairs and all the way to the back.

Be there, talk is of some free T shirts....

Full York

Did you go shopping in York today? You didn't? I'm surprised, because everybody else seemed to be there. I've never seen so many people in a city centre.  It was like being at a very crowded cocktail party, with no food or drink and freezing cold.  I was surprised to see so many out in the midst of the current credit-crunch but it was noticeable that only a few were actually carrying full shopping bags....

I took the little camera, and managed to take some happy snaps.

3069286986

The Ouse, once the mist had cleared a bit

Coding4Fun Micro Framework Article

Those awfully nice Coding4Fun people have put up a copy of my article about the .NET Micro Framework. This gives a sound, technical, answer to the oft asked question:

"How do I get my christmas tree lights to flash red when Rob makes a new post on his blog?"

You can find out more at: http://blogs.msdn.com/coding4fun/

And ex-Hull student spotters might be able to locate Andy and James in some of the other pictures on these hallowed pages. 

Flying Starts for Student Entrepreneurs

If you have a idea you want to turn into a software product and a yen to run your own business on the back of it you may be interested in the new Flying Start program being launched by the NCGE.

The National Council for Graduate Entrepreneurship (NCGE) is a government funded not-for-profit organisation that works with Higher Education institutions in England to promote entrepreneurship education and to provide business start-up support for students and graduates.  It has teamed up with  Microsoft and Agitavi Research to create a business start-up program for final year students, post-graduates and graduates (of up to 5 years on) who plan to launch a software business based in the UK.

The program begins with a 3 day residential course held at Wokefield Manor in Reading, on 16, 17 and 18 December 2008. Fees, accommodation and subsistence for all 3 days are included. If you are starting (or have just started) a software business and you want some professional support (and some free food) then it is well worth a look.

http://www.flyingstartonline.com/fsprogrammes/upcoming/

Last FM Rocks

I watched The Gadget Show on Five tonight. Are you surprised? They had quite a fun feature where they tried to wean one of the presenters off his Apple habit by doing things like giving him an electric shock whenever his iphone was slower than the competition.

One of the things that came out of this was a mention for last.fm as a replacement for iTunes, the Apple music store. This went down a storm with the Apple lover, and so I took a look myself.

Turns out it is wonderful. If you fancy a completely free, streamed service that will send you your favourite tunes to a PC or mobile device (the iPhone client is lovely) then you would be bonkers not to take a look.

You calibrate it by giving a few of your favourite artists and then it either plays tracks from them or suggests others you might like. All for free. If you actually want to buy any of the tracks that you are hearing you can press a button and download them there and then. The new iTunes has a feature called Genius that works like this, but it either plays your own music or suggests things that you can buy.  Last fm on the other hand gives you a free soundtrack for your life anywhere you can get a network connection, including 3G and even Edge (although I guess the quality won't be the best on low bandwidth connections).

Actually, while I'm mentioning amazing things to do with iPhones, I should really give a shout out to Shazam (you can get it for other platforms too).  It is a free application that tells you what music is playing on the radio. Let the program listen to a snatch of the song and it will go online and then more often than not come back with full details. It is truly amazing, and I've no idea how it works.

Windows 7 - Putting the win back into Windows

I've been using Windows 7 as my main desktop for a few weeks now. I love it. There are a few rough edges, but nothing that would send me back to Vista. From the point of view of what you can do with it I've not noticed much different, although I haven't looked very hard to be honest. What I have noticed is the speed. Things happen an awful lot faster. Programs load and run at the kind of rate that they should do on a machine with a 2G processor.  File copying and archive unzipping are now happening at a proper speed. People I know are digging out old and slow machines that won't run Vista very well, loading up the Windows 7 test version and turning them into useable devices, which is very interesting.

It used to be that a new operating system meant a new computer. If the final version of Windows 7 manages the same level of performance of the one I'm using it could actually reverse this trend. One of the reasons why Vista didn't work very well in the early days was that some suppliers did a pretty poor job of supporting it with drivers, leading to lots of people with brand new "Vista capable" machines that didn't work properly. This must have made Microsoft a bit upset at the time, but with Windows 7 Microsoft might just get their own back on the hardware makers, since everyone will rush out and buy the operating system and have no need to get new machines.

Need for Speed Undercover Mostly Wanted

I'm a bit of a sucker for the Need for Speed games. I think this dates from my early experiences on the Playstation 1, where you got to drive a real Ferrari  (honest) through a flickering landscape of pop up buildings. I even got one of the first steering wheel peripherals to enhance the, ahem, driving experience. I especially liked the way that you got cuffed and stuffed if you failed to outrun the police.

When I got my Xbox 360 I spent ages playing a downloaded demo of "Need for Speed: Most Wanted" where you had to break free of the cops in a large city environment. Great fun, even if number one son complained that the car handling was floaty and imprecise (it was) and the way the graphics engine chugged when there was a lot going on made him sea sick (it did). However I enjoyed it so much I even bought the game.

Because the next two Need for Speed games seemed to play down the police chase aspect I wasn't that interested in them. I think that the publisher EA probably got into a bit of hot water for making a game that encouraged you to indulge in such anti-social activities as ramming road blocks and forcing squad cars into bridge pillars. Fortunately I seem to be able to distinguish the fantasy world of video games from real life, and so this was never an issue for me, but I missed the car chases.

Until now. Need for Speed Undercover turns you into an undercover cop infiltrating the evil world of dangerous driving by being the, er, most dangerous driver of all. I read some previews of the game where the developer was talking about the advanced car mechanics they've used and the new graphical enhancements and stuff. and they had it cheap in Sainsburys when I was doing the shopping and so I bought it.

Turns out that the car handling is still floaty, and the screen still chugs when there is a lot going on. I reckon they've taken the old Most Wanted engine, changed the layout of the city a bit, turned up the brightness and shipped it.  It is still fun though (but racing purists might not like it as games like Burnout Paradise do this thing a lot better - except for the cop chases).

New Xbox 360 Experience

I fired up my Xbox 360 today and installed the new "Experience". It is a free download from Xbox Live and replaces the original "Blade" front end with a completely different look which I reckon is much easier to navigate. It also lets you create mini-avatars of yourself to use for your interaction with games and other Xbox 360 users. I've no idea where they got the idea for this. I spent a few minutes tweaking my avatar appearance to add my distinctive good looks, which was great fun. Or not.

One of the wonderful things about modern software based devices is the way that they can sprout new behaviours years after you got them thanks to the magic of the firmware upgrade. I now have what feels like a brand new replacement of my console. If you have an Xbox 360 you really must check this out.

Cheered Up by Students

Bit fed up today. I hate it when I'm not where I should be, and I had been looking forward to going to Copenhagen. Never been to Denmark before and it might be a while before I get the chance again.

The good news is that being back in the office meant that I got a steady stream of students coming by with programs to look at and projects to discuss. And that really cheered me up. I love seeing people making progress and doing stuff. Thanks folks.

Never Trust a Plane that still has a Propeller

I was supposed to fly out to Copenhagen to give a session tomorrow as part of the Windows Embedded European tour. I had all my slides with the snazzy tour template, and a bag packed with hardware to show off.

Instead I went to an airport, sat in a plane for forty minutes, had a drink of orange juice, got out of the plane, queued for an hour, found out there was no way I could get to Copenhagen in time and went home.

We had all watched the plane land, and then were told that "For safety reasons" it was not able to take off again. I reckon the people that we saw arrive in it had a lucky escape.

Such is life I suppose. I tried to be relaxed about it. The only time I got a bit cross was when I was at the desk after an hour wait and the lady there was trying to sort out my travel plans. Having determined that there were no seats on any flights out today, and that a flight tomorrow would have me arrive far too late for my session, I said that in that case there was no point in me going. "So" she said, "You are choosing not to take up our offer of an alternative flight?". I made the point that it was not a matter of choice, if I couldn't get there today there was no reason to travel. "OK." she replied "I'll put on the file that you have decided not to take up our offer". I was too tired to put up much of a fight, and anyway a prominent notice reminded me that anyone who got too shirty would have the full might of KLM to deal with. Assuming they could actually get here of course, what with their transportation technology being so ropey.

I'm very sorry that I didn't make it out to Denmark. I was looking forward to meeting up with the students and seeing some cool Lego tech. Perhaps another time.

Mini-Microsoft and Achieving Senior Level 63

Talking of good blogs to read, I quite like Mini-Microsoft. This is an anonymous manager at Microsoft giving a take on the way that the company is going. It is also sprinkled with detail about life inside Microsoft, and how to get on in the corporate environment.

Mini (if I can use that name) has just posted a good post on how to get to Senior Level 63 (apparently some exalted management level in Microsoft). I've no particular desire to scale those lofty heights, but the post is interesting because I reckon if you follow the advice in it you will do well in whatever field you are in.

Microsoft, like everwhere else I suppose, is mainly interested in promoting useful, effective people and this post gives you an insight into how to be more useful and effective.

Hard Code on the Web

I've mentioned I.M. Wrights "Hard Code" book before on this blog. It is actually written by a bloke called Eric Brechner, who adopts the I.M. Wright persona to write hard hitting, controversial, articles about software development best practice. When I mentioned the book before I said that I thought was worth a look. Having finished reading it I've changed my mind.

You must read this book. It is excellent. The even better news is that I.M. Wright also has a blog that is an equally good read. You can find it here.