Reputation: 546
I have an image and 9 small images. I would like to crop the image to 9 pieces and show them on 9 small images. I use Windows Phone 8. Could you have me ?
Thank you
Upvotes: 1
Views: 70
Reputation: 8161
sourceBitmap is just another WriteableBitmap
For example, lets say we have this XAML (where bigImage is the Image we want to Crop)
<ScrollViewer>
<StackPanel>
<Image x:Name="bigImage" Source="/Assets/AlignmentGrid.png"></Image>
<Image x:Name="cropImage1"></Image>
</StackPanel>
</ScrollViewer>
Then in the code behind
using System.Windows.Media.Imaging;
// using WriteableBitmapEx
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
// create a WriteableBitmap with the bigImage as its Source
WriteableBitmap wb = new WriteableBitmap((BitmapSource)this.bigImage.Source);
// calculate and crop
WriteableBitmap crop1 = wb.Crop(0, 0, 100, 100);
// set the cropImage1 image to the image that we just crop from the bigger one
this.cropImage1.Source = crop1;
}
If you want to see a great solution without using the WriteableBitmapEx (basically you gonna code your own Crop which returns a WriteableBitmap) then this webpage is for you:
Crop Image Implementation (it's actually really easy to program, just need a tad bit of algebra)
Upvotes: 1