将图像拆分为几块 Silverlight Windows Phone [英] Split an image into several pieces silverlight windows phone
问题描述
我想使用适用于 Windows Phone 7.5 的 Silverlight 将图像拆分为多个较小的图像.
I want to split an image into several smaller images using silverlight for windows phone 7.5.
首先,我想知道这是否可能(我最近在使用 Windows Phone API 时遇到了一些令人不快的惊喜),如果是,请给我一些示例,因为我完全找不到.
First of all, i want to know if this is even possible (i had some unpleasant surprises with windows phone APIs lately), and if it is, just give me some example as i have been able to find exactly none.
感谢您的帮助.
推荐答案
WriteableBitmapEx 与 Windows Phone 和有一个 Crop
方法来做到这一点.您只需要进行数学计算即可确定裁剪的宽度/高度和 X/Y 坐标.
WriteableBitmapEx is compatible with Windows Phone and has a Crop
method to do exactly that. You just need to do the math to figure out how wide/tall and X/Y coordinates to crop at.
//this creates the four quadrants of sourceBitmap as new bitmaps
int halfWidth = sourceBitmap.PixelWidth / 2;
int halfHeight = sourceBitmap.PixelHeight / 2;
WriteableBitmap topLeft = sourceBitmap.Crop(0, 0, halfWidth, halfHeight);
WriteableBitmap topRight = sourceBitmap.Crop(halfWidth, 0, halfWidth, halfHeight);
WriteableBitmap bottomLeft = sourceBitmap.Crop(0, halfHeight, halfWidth, halfHeight);
WriteableBitmap bottomRight = sourceBitmap.Crop(halfWidth, halfHeight, halfWidth, halfHeight);
在上面的示例中,我可能会偏离一个像素(未测试),但它应该可以演示 API.
I might be off by a pixel (didn't test) in my above example, but it should demonstrate the API.
这篇关于将图像拆分为几块 Silverlight Windows Phone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!