Page 1 of 5 in the Silverlight category Next Page
# Thursday, 07 April 2011

Have you ever been caught in the situation during a presentation when you just would like people to be able to see what your webcam is looking at, and you just have to kept asking yourself which chat program can just show your webcam contents?

I have, therefore I decided to just whip up a quick Silverlight application to dump the webcam visuals onto the screen.

Here you go :- M2SimpleCameraVisualizer

Oh.. it's installable for offline access, just right click for the Install option.

Thursday, 07 April 2011 09:49:52 (Malay Peninsula Standard Time, UTC+08:00)  #    Comments [1]  | 
# Saturday, 11 September 2010

Even before my little keyboardless adventure, I've always known that a Windows 7 Tablet PC's biggest disadvantage is that not many apps are optimized to be run by touch. So I guess I need to start writing some myself, here's the first thing I finished a while back for my UH900, An extremely simple RSS reader. EXTREMELY simple, mainly because I wrote it just to help navigate through some feeds on the UH900. Also because I wrote it while waiting to see the Doctor one day.

It's a Silverlight 4 based application, so you'll need to grab that runtime to try it out.

Marauderz Simple RSS Reader

Saturday, 11 September 2010 02:33:53 (Malay Peninsula Standard Time, UTC+08:00)  #    Comments [0]  | 
# Wednesday, 14 July 2010

Ok, I've nabbed the new Beta developer tools for Windows Phone 7 (and still cursing the fact that no offline installer is available) dropped it into a test VHD and did a quick test project to test out wheter the previous Silverlight 4 port of the library works on the phone (and also in Silverlight 3) and... well.. it works without a hitch, so if you were looking for a QRCode library for use in  Windows Phone 7.

Download it here.


Wednesday, 14 July 2010 22:59:24 (Malay Peninsula Standard Time, UTC+08:00)  #    Comments [0]  | 
# Friday, 25 June 2010

Google has a great barcode reading program/library in the form of ZXing. They had a CSharp branch already but not a Silverlight one. So I looked through the code a little and ported the QRCode portion of the library for Silverlight use by doing the following

  • Replaced System.Collections.Arraylist with System.Collections.Generic.List <Object>
  • Replaced System.Collections.HashTable with System.Collections.Generic.Dictionary <Object,Object>
  • Removed all Serializable attribute markings
  • Forced all calls to System.Text.Encoding to use UTF-8 as the encoding type.

While the first two changes might have a performance impact to the code, it's the LAST change that worries me since it deals with encoding, specifically I worry about exactly how well can the code deal with NON English content... oh well, that's a challenge for another day I guess.

What is that you say? Talk is cheap.. then GIVE IT A TRY!! How does it work? Create some tags.. save the tags as PNGs, then Read some tags by loading images which contains tags. Or.... Take a PICTURE of a tag using your webcam! Oh.. if your webcam can't take nice sharp images, you might want to invest in an autofocusing camera like the Microsoft LifeCam HD-5000.


What's that you say? It's an Open Source project therefore I need to contribute my code back into the trunk? Well.. sure... the source for the sample along with the lib is here.

The code was compiled for Silverlight 4, technically I don't *think* I used anything that won't allow it to work with Silverlight 3 though.

As to how to actually contribute it back in the trunk errr.. I guess I'll have to get in touch with the guys that's handling the project.

So.. 2 things that need to be done now.

  • See how to integrate with RawVideoStream and read tags off a LIVE video stream
  • See if the library works with Windows Phone 7

The 2nd would be a bit more difficult since I DON'T HAVE A WINDOWS PHONE 7 device! :P

Friday, 25 June 2010 00:03:57 (Malay Peninsula Standard Time, UTC+08:00)  #    Comments [0]  | 
# Friday, 19 March 2010

UPDATE : This code doesn't work properly, go here for a properly working one.

I needed to resize an image in Silverlight and then save it out as a JPEG. I could have just used a transform on it then rendered it to a WriteableBitmap but the transforms were optimized for realtime performance and doesn't work too well when you need to maintain quality.

I stumbled upon a Bicubic Resize code in a library called AForge.Net and it was in C#, so it was simple enough for me to convert it to VB for me to use it in Silverlight. And since I DIDN'T find a lot of Bicubic Interpolation .Net resize code on the net, I'm gonna just put this copy up here.

As a bonus I kept on my comments in so you guys can see what was going through my head as I was working my way through the code.

Bicubic Interpolation
''' <summary>
  ''' Bicubically resize the src bitmap to the dest bitmap
  ''' </summary>
  ''' <param name="src"></param>
  ''' <param name="dest">Destination Bitmap, should be initialized to the requested size.</param>
  ''' <remarks>Original Source For This Function -</remarks>    
  Sub Resize(ByVal src As Imaging.WriteableBitmap, ByVal dest As Imaging.WriteableBitmap)

      Dim startTime As DateTime = Now

      Dim srcwidth As Integer = src.PixelWidth
      Dim srcHeight As Integer = src.PixelHeight

      Dim destWidth As Integer = dest.PixelWidth
      Dim destHeight As Integer = dest.PixelHeight

      Dim xFactor As Double = srcwidth / destWidth
      Dim yFactor As Double = srcHeight / destHeight

      'Coordinates of src points and  coefficients.. WTF?
      Dim ox, oy, dx, dy, k1, k2 As Double
      Dim ox1, oy1, ox2, oy2 As Integer

      'new color values
      Dim r, g, b As Double

      Dim xmax As Integer = srcwidth - 1
      Dim ymax As Integer = srcHeight - 1

      For y As Integer = 0 To destHeight - 1
          'this is getting the original Y pixel if I'm not mistaken
          oy = y * yFactor - 0.5F
          'WHY is this necessary?
          oy1 = oy
          'WTF? It's getting the FRACTIONAL difference between
          'oy and oy1?
          dy = oy - oy1

          For x As Integer = 0 To destWidth - 1
              'same WTF as with the Y values,
              'maybe will make more sense later?
              ox = x * xFactor - 0.5F
              ox1 = ox
              dx = ox - ox1

              r = 0
              g = 0
              b = 0

              'this loop is to gather the interpolated
              'values of 2 pixels surrounding the current one
              For n As Integer = -1 To 2
                  'this gets the Y coefficient

                  k1 = BicubicKernel(dy - n)

                  'this seems to be getting the new
                  'Y pixel where the interpolated
                  'value comes from
                  oy2 = oy1 + n

                  'this is to ensure we're in the right spot
                  If oy2 < 0 Then
                      oy2 = 0
                  ElseIf oy2 > ymax Then
                      oy2 = ymax
                  End If

                  For m As Integer = -1 To 2
                      'for X coefficient
                      k2 = k1 * BicubicKernel(m - dx)

                      ox2 = ox1 + m

                      If ox2 < 0 Then
                          ox2 = 0
                      ElseIf ox2 > xmax Then
                          ox2 = xmax
                      End If

                      'get original pixel color
                      ' Dim origColor As Color = source.GetPixel(ox2, oy2)

                      'writablebitmap pixel is AARRGGBB
                      Dim srcColor As Integer = src.Pixels(ox2 + (srcwidth * oy2))

                      'set interpolated values
                      r += k2 * ((srcColor >> 16) And &HFF)
                      g += k2 * ((srcColor >> 8) And &HFF)
                      b += k2 * (srcColor And &HFF)

              'after calculating coefficients we have our new color               
              dest.Pixels(x + (destWidth * y)) = &HFF000000 Or (r << 16) Or (g << 8) Or b

      Dim endTime As DateTime = Now
      Diagnostics.Debug.WriteLine(String.Format("Time taken to squish {0}x{1} to {2}x{3} : {4} seconds", srcwidth, srcHeight, destWidth, destHeight, endTime.Subtract(startTime).TotalSeconds))

  End Sub

  Shared Function BicubicKernel(ByVal x As Double) As Double

      If x > 2.0 Then
          Return 0.0
      End If

      Dim a, b, c, d As Double
      Dim xm1 As Double = x - 1.0
      Dim xp1 As Double = x + 1.0
      Dim xp2 As Double = x + 2.0

      If xp2 <= 0 Then
          a = 0
          a = xp2 * xp2 * xp2
      End If

      If xp1 <= 0 Then
          b = 0
          b = xp1 * xp1 * xp1
      End If

      If x <= 0 Then
          c = 0
          c = x * x * x
      End If

      If xm1 <= 0 Then
          d = 0
          d = xm1 * xm1 * xm1
      End If
      Return (0.16666666666666666 * (a - (4.0 * b) + (6.0 * c) - (4.0 * d)))

  End Function

There's one caveat though, I didn't do any Alpha premultiplication with this code, which basically means if your images have a non FULLY opaque region, the results won't be pretty. Here's your homework assignment if you want to have that functionality.

I learnt 2 things while porting this code.

  1. Don't use Math.Pow() if your code is time sensitive, ie. it needs to work REALLY REALLY fast. Like in a game render loop. Takes a bit longer to run math.pow(x,3) instead of x*x*x. Not saying you shouldn't use it, just don't use it when MILISECONDS matter.
  2. Visual Basic's IIF statement isn't good for performance as well since BOTH true and false statements seem to be evaluated and does execution time is wasted when execution time matters. Better to use the usual IF..ELSE..ENDIF construct.

After my little exercise in dabbling with this, THEN I find a WriteBitmapEx library which pretty much seems to be a very useful class for raw manipulation of images in Silverlight, check it out!

Friday, 19 March 2010 00:24:20 (Malay Peninsula Standard Time, UTC+08:00)  #    Comments [0]  | 
# Wednesday, 25 November 2009

Here's a picture of exactly how large the Silverlight Twitterboard was at TNE was.

Wednesday, 25 November 2009 23:26:03 (Malay Peninsula Standard Time, UTC+08:00)  #    Comments [0]  | 
# Tuesday, 24 November 2009

The Microsoft Silverlight powered Twitter board makes another appearance in The New Efficiency launch event at KLCC today!


And this time it's being projected on a HUGE projection screen on the wall.

Tuesday, 24 November 2009 17:27:04 (Malay Peninsula Standard Time, UTC+08:00)  #    Comments [0]  | 
# Thursday, 19 November 2009

Well, Silverlight 4 has been announced and the Beta tools have been made available for developers to try out. And you can grab said Beta tools from this location.

The new features have been nicely summarized here. It still doesn't have native 3D scene creation support ala WPF but it reads out like a laundry list of feature requests made by developers. Web cam support, printing support, full network library support. etc. etc. But to me... there's one little bullet point stood out that had me grinning non stop.

FULL TRUST Out Of Browser Application Support.

If you're familiar with Silverlight 3 you'll of course have heard about Out Of Browser (OOB) support which allows an application to be installed then invoked like a normal application on the user's desktop. There was just one little... deficiency in that feature. The application would be run through a sandbox with some tight security restrictions that limited the OOB app to be a FULL BLOWN application.

This was of course due to the people at MS not wanting to cause another hysteria that had people crying fowl over how much power plugin applications can have over the system. ala The ActiveX Incidents.

But Developers recognized the full potential of having full trust apps capability and I'm guessing a lot of people sent a lot of requests over to the Silverlight team about this. Also more importantly...

Adobe's AIR platform, which basically is also a deliver RIA applications through the Internet DID allow for full trust capabilities when it deployed it's applications. This gave Adobe AIR a BIG one up over Silverlight 3 because it could do things that users wanted, and developers wanted ie. Full access to user's drives and network resources (no cross domain, or site of origin needed) And it was a generally lightweight platform as well.

But of course, all that has changed now that with Silverlight 4, developers can make FULL TRUST apps. To me it means one thing, Silverlight 4 now has the potential to allow .Net developers to easily create RIA applications on both Windows and Mac platforms. With Silverlight 4, a .Net developer can now tell people that in addition to Windows Applications, Web Services, Rich Web Sites now they can also tell people they can make applications that run on the Mac! A whole new platform just opened up!

To me.. Silverlight 4 has the potential to be the new .Net Client Platform!

And I do believe that I'm not the only one who sees this. I wonder what's going on at Adobe AIR's department right now?

Thursday, 19 November 2009 22:13:42 (Malay Peninsula Standard Time, UTC+08:00)  #    Comments [0]  | 
# Monday, 02 November 2009

Spotted in the Windows 7 Malaysia launch, a live Twitter hashtag display. Powered by Silverlight.

Monday, 02 November 2009 14:15:52 (Malay Peninsula Standard Time, UTC+08:00)  #    Comments [0]  | 
# Saturday, 18 July 2009

When Blend 2 SP1 was launched along with Silverlight 2.0, I had one problem with it. While the new visual state manager concept was great in allowing designers to define how the controls looked there was still one problem. There was no way for designers to do things like dictate that clicking a button started an animation, or moved to a different place in the application. This means that if you were creating an RIA application, the programmer would first had to create the basic navigational and behavioral skeleton of the application before the designer could start work. And also if the designer wanted to test some simple flow changes it be a bit of a trouble for them to do any changes unless they happened to know a little bit of .Net programming.

If we compared Blend 2 SP1 with Adobe Flash’s development environment, Blend 2 was at a disadvantage because of this. Since there wasn’t any way for a designer to complete their ideas without asking the developer for help. And now.. we have Silverlight 3 along with the RC version of Expression Blend 3. And I’m LOVING IT!

What’s there to love? For one thing, in order to solve the problem I described above I would have accepted it MS would have just written in some more event triggers in Silverlight instead of just having the useless ONLOAD that we had in SL1 and SL2. But MS went above and beyond that. Instead of defining additional triggers, they now allow the DEVELOPERS to create their own TRIGGERS. And instead of defining additional actions to the base elements. The DEVELOPERS themselves can create their own ACTIONS that can be attached to TRIGGERS to make them functional.

Ok, I’m not making much sense without an example. Basically a TRIGGER is an event, it could be something like on mouse click, on mouse move, etc. etc. And an ACTION is well… an action that does something. Let’s explain with the earlier example of a designer wanting to add some functionality to the app they’re designing. For example:- once a button is clicked, start an animation. This was not possible in Blend 2, and in order for the designer to see the results of this effect a developer would have been needed to write the code to wire up the logic. But in Blend 3, the designer would drop a MOUSE CLICK TRIGGER onto the button and then on the trigger he would drop a PLAY STORYBOARD ACTION and set the target storyboard to the name of the storyboard they wanted to play.

But that’s nothing new to Flash users, and I wouldn’t be making it sound like a new innovation if that was just the case. The fun part about this is that because the DEVELOPER can make new TRIGGERS and ACTIONS it means that if the base ones don’t work for the application and logic you require for YOUR APPLICATION, JUST MAKE SOMETHING that YOU NEED!

And the coolness doesn’t stop there yet, other than triggers and actions. You can also develop and drop BEHAVIORS onto your elements. And this is where it gets interesting. A behavior is exactly that, it tells the element it was dropped on how to behave. An example of a behavior is like Drag To Move, Shrink On Click etc. etc. And.. the most extravagant example of behaviors comes straight from the Blend 3 samples. It’s called BeeHive and is essentially a BreakOut clone, but what’s special about it is that the whole game was written by dropping custom game behaviors like collision behavior, movement behaviors, etc. etc. onto simple Image elements and poof.. GAME!

This just makes me wondering.. when creating a SL application (or WPF for that matter) it almost seems as if that I should write my application logic as behaviors so that designers can just drop the behaviors onto the elements which they see fit so they can easily change how the UI looks without going through me.

Wow.. what a long post.. and I haven’t even talked about sample data generation… and SKETCH FLOW! Another time then.

Saturday, 18 July 2009 22:32:27 (Malay Peninsula Standard Time, UTC+08:00)  #    Comments [0]  | 
Page 1 of 5 in the Silverlight category Next Page