Monthly Archives: May 2009

Tech Friday: The Orientator

I was thinking of an app to build for tech Friday and I remember running in to @willyfoo the other day. He mentioned he needed an application that would read in EXIF data from photographs and rotate them based on the orientation meta tag. It was quite a good exercise cause it allowed me to play around with a few things.

 

Problem 1: EXIF what?

Although I play around with photography once in a while (I bought a camera last year and I haven’t put any serious effort into it just yet), there are a few concepts which I have yet to understand. So apparently, cameras have a way of storing meta data into the photos you take. Some cameras store what its orientation is when you take a picture. So today, I brought my camera to work and took a few photographs as test photos. I found an existing library on CodeProject that will allow you to read EXIF data from photos called ExifLib.

So now, I can extract the data. The next step was understanding what code means what. http://www.impulseadventure.com/photo/exif-orientation.html gives a graphical explanation for the values of the Orientation metadata.

Problem 2: UI

To be honest, this is something that really needs to be thought through. I am guessing traditional applications would have a UI such as this that will allow you to select a file you want to “fix”. But then I thought, what if I wanted to do a batch job? I guess I could then select a directory. And then I remembered the challenge I had when I dealt with photos when uploading to facebook where my photos aren’t always in the same directory.

image

I then remembered a tweet by @MSExpression pointing to a blog post by kirupa where he talks about how you can enable drag & drop onto WPF components. So that is settled, Drag & Drop. I built a simple UI with a ListBox where you can drag your files to and an Image component where you can preview the rotated image.

image

There might be cases when the application messes up the auto orienting and you’d rather do it yourself manually. The UI allows you to select/de-select the files you want to save changes to. I have to say, it’s not the prettiest or most intuitive way to do it but I am not creative so this will have to do.

Problem 3: Preserving EXIF Data

I had originally thought it would be as easy as

     1  Bitmap bmPhoto = new Bitmap(filePath);

    2  bmPhoto.RotateFlip(RotateFlipType.Rotate180FlipNone);

but I was wrong. First, I realized that although it would successfully rotate the image, it would also bloat up the file (as it was saved without compression) plus, it would lose all the EXIF data the photos had. I don’t think this is something that @willyfoo would have wanted ^_^. So I dug around and found this post that showed you how to resize and manipulate jpegs while preserving the metadata. I did a bit of trimming as the code had stuff to resize the image, which I didn’t want to do for this round. One issue though, is because it encodes the bitmap using some parameters that i can’t figure out just yet (am just lazy too :p) It bloats the file up by a bit.

Problem 4: Saving Changes

Because my UI shows a preview of the image that was rotated, I got some errors where “the file is being used by a process” once I loaded them up into the application and tried to rename/delete them. This post on the msdn forum showed the fix for this.

You can download the code here:

Issues:

The application is functional but there is definitely a lot of room for improvement 🙂

1. Design – I think this application can be a lot nicer looking if I actually spend time on it. There’s a lot the WPF platform can do to “jazz up” the look and feel of the UI. I think my biggest challenge right now is coming up with a concept that would be cool looking enough :p

2. I’m not sure what happens if I drag&drop none images into the application. This line was supposed to take care of that:

 

    1             if (e.Data.GetDataPresent(DataFormats.Bitmap))

    2             {

    3                 ///some code here

    4             }

But for some reason, files I drag&drop into the app don’t get recognized as a Bitmap. I had to use DataFormats.FileDrop instead.

3. Bloating of image. As I mentioned in problem 3, I’m not very familiar with how encoding works so the app actually bloats the image size quite a bit. I think the following lines take care of the encoding, but when I try to step down on the encParm, it makes the image size smaller than the source. I figured, bigger is better.

    1                 System.Drawing.Imaging.Encoder enc = System.Drawing.Imaging.Encoder.Quality;

    2                 System.Drawing.Imaging.EncoderParameters encParms = new EncoderParameters(1);

    3                 System.Drawing.Imaging.EncoderParameter encParm = new EncoderParameter(enc,100L);

    4                 encParms.Param[0] = encParm;

    5                 ImageCodecInfo[] codecInfo = ImageCodecInfo.GetImageEncoders();

    6                 ImageCodecInfo codecInfoJpeg = codecInfo[1];

 

That’s it for now, until next Tech Friday!

Tech Friday!

I hereby declare that Friday mornings will now be committed to leveling up my technical knowledge. For this morning, I watched a session on http://www.visitmix.com which talked about Building Microsoft Silverlight Controls in Silverlight 3. Check out Karen Corby’s session at http://videos.visitmix.com/MIX09/T16F

Some really cool features of Silverlight 3 she talks about are Theming, Validation States, and a few others. She also does a very comprehensive walkthrough on creating a custom rating control.

Get Microsoft Silverlight

 

You can also find the code and presentation from this session on her blog at http://scorbs.com/2009/03/23/mix-09-building-microsoft-silverlight-controls/

And for more details on how the Validation works, check out this Channel9 Video:  http://channel9.msdn.com/posts/mtaulty/Silverlight-3-Beta-Validation/

Next time, I’ll start my Fridays earlier so I can actually build something.

How Do I Manage Two Twitter Accounts Using Just My Browser

Twitter has definitely become more and more popular both for work and for personal stuff. I have my personal twitter account which I use as I please: update the world about my bathroom habits, complain about unfortunate events, have random conversations with people, etc. I also have another work account which I have just started, with the goal of reaching out to the product development companies in Singapore (i have yet to think about how to go about this).

Sometimes I don’t like using the desktop clients because they tend to become a bit too heavy to keep running. So I keep twitter opened in my browser. The challenge is if I find someone interesting from my personal account and I want to follow them on my work account, it’s a bit taxing to logout-login.

Solution:

I make use of IE8’s InPrivate Browsing feature. To activate you can either press <Ctrl+Shift+P> or under Safety Menu, you can click on InPrivate Browsing.

image

You should be able to login with different credentials this way. I use the same method when I need to login with different Live IDs as well. (I think i have 7 o_O)

image

How I Upload Photos to Facebook

I just have to say, I am loving Windows 7 RC. One of things I like that is an extended part of Windows 7 is the Windows Live Essentials. On a fresh install of Windows 7, go into the search bar and type in “Windows Live Essentials” or you can search for it using your favorite search engine to get to the download portal.

image

There are a few things included in the suite but what I want to talk about today is the Windows Live Photo Gallery. It’s quite similar to Vista’s Photo Gallery but much, much better. You can either build your own plugins or download ones that have been built by others. I’ll be talking about one in particular, the Live Upload to Facebook Plugin.

Scenario is this: after importing my pictures into my machine, I want to review them before uploading them to Facebook (or flickr or whatever service you want). Think of it as quality control.

The Facebook upload control makes it easy to upload photos if you already know which photos you want. My problem is that, I import my photos into folders based on events. And rarely do I want to upload all the photos I’ve taken of an event up into facebook, or flicker.

image

What I do is use Windows Live Photo Gallery to quickly view and rate my photos 5 stars for the ones I want to upload to Facebook. (or i could do something like, 3 for facebook, 5 for flickr, etc.)

image  image

Another thing the software does is (1) identify faces in the photos and (2) allow you to tag people from your messenger list (or specify the name of someone who’s not)

image

I can then go back to the gallery:

image

And either sort:

image

or filter the photos in a specific folder:

image

And now, since I have the Live Uploader plugin installed I can easily select and publish the photos into facebook:

image

I’m prompted to select the account I want to use:

image

I can then either create a new album, or select an existing album to publish the pictures to. Straight from the software, you can also control permissions for the album

image

I can also then map my tags to my contact list on facebook for automatic tagging:

image

Once it’s done publishing, my friends will be able to see my photos published in my feed. YEY!

image 

What you’ll need?

Required:

Windows Live Photo Gallery – http://download.live.com/photogallery 

Live Upload to Facebook plugin – http://www.codeplex.com/liveuploadfacebook

Optional:

Windows 7 RC – http://www.microsoft.com/Windows/Windows-7/download.aspx

Lost!

Some things I need to know about life, I learn through running.

Today I was feeling a bit cocky and thought that my usual route here at lavender just wasn’t enough, so off I went trying to discover a new route. At first I was amused at how far I’d strayed off. After a while I got so distracted that I did lose my bearings and got myself lost. Below is how my run ended up looking like 😐

I guess what I learned is that if you’re going to be deviant, and want to “stir things up a bit”, you’ll still have to be responsible about maintaining common sense, and always have yourself in check. You should never lose yourself in the moment so much that you just follow where things lead you. You have to keep a straight head about making sure you know where you’re going, and you have to be humble enough to admit you’ve gone astray. At this point, you stop, think, recalibrate and go for it. Mistakes are part of everything. And as long as you know to realize it when it happens, and are able to correct yourself as much as possible, then you’ll be fine.

Home Run

Parents left today and there was a cry-fest outside our gate as they loaded their bags into the cab. I didn’t realize how much i missed my parents till they were leaving. This whole day while we were going around, I felt that familiar weight on my chest. I’ve always been amazed how negative emotions can actually manifest itself into physical pain/discomfort (and curious how positive emotions manifest themselves). At the start of the day, I already broke down into tears while we were eating breakfast, and throughout the day i had that heavy feeling. I broke down again when they were getting into the cab. I decided to run it off rather than go for the unhealthy alternatives, and this is how i did today:

I feel a bit better. I don’t feel the heaviness on my chest that much anymore.

DPE RC!

In an effort to get our asses in shape, a few of my colleagues and I have started running. Yes, I know I’m a bit late into the running craze but hey, better late than never ;)  I have to say, I think I have a long way to go to get in shape.

This is my run for today:

Cant wait for Tuesday! Maybe I will run on my own on before then though. Like I said, I have a lot of catching up to do.

Click Once Deployment from Windows 7 Machines

I was trying out Click Once Deployment and was getting errors when i tried installing from the published point.  I was getting the error "The required version of the .NET Framework is not installed on this computer." I found this thread when I did a search http://stackoverflow.com/questions/526264/clickonce-the-required-version-of-the-net-framework-is-not-installed-on-this-co where Tim Heuer posts a fix:

Hey all, I was updating one of my own plugins and ran into this as well, so I thought I’d ask some friends internally :-). Here’s the skinny…

The following file is missing in Win7RC .NET distribution (this is known and being addressed): %ProgramFiles%Reference AssembliesMicrosoftFrameworkv3.5RedistListFrameworkList.xml

Copy that file from a non Win7 machine (same location) to the Win7 box and your publish should work.

I’m traveling and haven’t verified yet (don’t have a non Win7 box near me), but wanted to post this for you all.

Hope this helps!

-th

Worked for me!

Battery Problems on Acer Aspire One

So I was installing Windows 7 on my Aspire One today and accidentally tripped on the power cord. It was then I realized my battery wasn’t charging. When I unplugged the AC power adapter, the battery’s LED was blinking orange. I removed the battery, and put it back again, it was still blinking. I did a quick search and found this forum: http://forum.notebookreview.com/showthread.php?t=275473 and their advice was:

1. unplug, and remove the battery

2. press power button for 30 seconds

3. plug in AC and start machine

4. If it boots up alright, replace the battery

This solution worked for me and the battery was charging up again. Thank goodness else I would have had to buy another battery pack.