ecently, I was consulting on a Windows Mobile project where the client asked if it is possible to send images using SMS messaging. After searching high and low for a solution, I concluded that there is no easy way to do it unless you want to buy some fanciful third-party software. Basically, my client wanted to build a security system to alert security guards when someone who is under monitoring leaves the compound under surveillance. To do so, they would automate the process by sending a SMS message to the guards, with the image of the person attached. The image would be a small mug shot of that person, which is relatively small in size.
This article details the solution that I proposed and will hopefully be of use to readers who are comtemplating such implementations.
How It Works
Before you can build the application, you need to understand how to embed both text and image into an SMS message. As SMS messaging is inherently text-based, sending images (binary data) poses a challenge.
Basically, you need to "flatten" the binary data into a string of printable characters so that you can send them via SMS. Base64 encoding is well suited for this purpose; the only draw back is that it inflates your data size by about 33 percent. Hence, after encoding your binary data (image) into base64, you should optionally perform a compression to reduce the size of the data. However, do note that images (such as the .jpg format) normally do not compress well, and in some instances, the compressed data is actually much larger than the original data. Figure 1 summarizes the action you need to perform in order to send an image over SMS.
|Figure 1. Image Manipulation Lifecycle: First, flatten an image into base64 and then compress it.|
Note that you cannot simply convert a byte array into a string using the ASCII.GetString() method found in the System.Text.ASCIIEncoding class because it may return non-printable characters, which cannot be represented in an SMS message's body.
For text data, you can optionlly compress it before sending (in order to reduce its size). Generally, if you're sending a small amount of text, compression doesn't help muchin fact, this usually increases data size. However, text data that contains a lot of repeating patterms generally compresses well.
One restriction with SMS messaging is the 160-character limit. If the message length exceeds 160 characters, the message will be split into multiple messages and sent separately, then assembled on the receiving end. Fortunately, all this takes place behind the scenes. What you need to know is that when you send a 1000-character SMS message, the recipient will get the 1000-character message.
The downside is that SMS messaging is charged based number of messages sent. And you will be charged seven SMS messages when you send a 1000-character message (1000/160). For this reason, this application works best if you have a unlimited SMS plan for your mobile phone.