I have two bitmap images that i would like to merge together. I found that I can do that with writeablebitmap but how do I first convert these images to writeablebitmaps?
UPDATE: I could not find out a way to convert bitmaps to writeable bitmap directly so what I did was to write my bitmap in isolated storage and read it again in a stream object. After which the code given below by Xyroid can be used to merge the images and convert the merged image to bitmap.
I've done a lot of work with Silverlight, which I believe the store apps are similar to in many ways.
Consider this constructor:
The next question is, how to get 'BitmapSource' from an image? You can do it this way:
Although this assumes that the source (which is of type 'ImageSource') is actually a 'BitmapSource' instance. That said, as of Silverlight 5.0, the only class derived from ImageSource in Silverlight is BitmapSource, so I doubt that would be an issue.
So something like this may work:
Finally, there's an open source project here which may be of some help: http://writeablebitmapex.codeplex.com/
Here I am giving you the code to merge two images. WinRT's WriteableBitmap is different, the constructor of it takes height and width as argument. I have used WriteableBitmapEx for some functions.
XAML
C#
Please note you have to add
System.Runtime.InteropServices.WindowsRuntime
namespace.UPDATE 1
Suppose if you have already two
BitmapImage
img1
andimg2
, then do like this