我設法從inkCanvas上的繪圖中獲取了需要裁剪的區域的x,y,height,width
。但我無法找到合適的解決方案來裁剪該區域並將其保存爲圖像。作品inkCanvas從特定區域繪製,Windows通用應用程序
編輯: 這裏是整個故事: 我公司開發的繪圖應用程序在一年前爲Windows Phone的8.1的Silverlight。使用這個例子
http://bsubramanyamraju.blogspot.com/2014/03/windows-phone-ink-supportsignature.html
現在我試圖讓同樣的事情寡婦普遍一些不同的功能。我正在從頭開發它,因爲現在可以在win10中使用墨跡,我不能使用舊代碼,因爲它包含僅適用於Silverlight應用程序的InkPresenter。
這裏是我用來種植面積上次的代碼(這不是我自己的代碼,我得到了它的在線)
static WriteableBitmap CropImage(WriteableBitmap source,
int xOffset, int yOffset,
int width, int height)
{
// Get the width of the source image
var sourceWidth = source.PixelWidth;
// Get the resultant image as WriteableBitmap with specified size
var result = new WriteableBitmap(width, height);
// Create the array of bytes
for (var x = 0; x <= height - 1; x++)
{
var sourceIndex = xOffset + (yOffset + x) * sourceWidth;
var destinationIndex = x * width;
Array.Copy(source.Pixels, sourceIndex, result.Pixels, destinationIndex, width);
}
return result;
}
但現在說
'WriteableBitmap' does not contain a definition for 'Pixels'
在source.Pixels
和source.Pixels
,我不知道如何解決它。
我發佈了這個問題,希望能夠直接裁剪InkCanvas區域,因爲它現在是win10的一部分。
編輯2 @Jay的寬度和高度,我傳遞參數是我想相對於x和y要裁剪的區域的寬度和高度。我嘗試調試以檢查decoder.PixelWidth
和height
的值。它總是與我在參數中提供的寬度和高度相同。
所以現在如果 xoffset =185
和yoffset=100
和height
和width
在params爲50
和60
。 decoder.PixelWidth
和decoder.PixelHeight
也將與params相同。這就是,如果條件是什麼樣子
if (pixelWidth > decoder.PixelWidth - xOffset || pixelHeight > decoder.PixelHeight - yOffset)
if (60> 60 - 185 || 50> 50- 100)
if (60> -125 || 50> -50)
因此這種情況是總是如此。我哪裏錯了?
希望我在這個編輯中沒有任何錯別字。
到目前爲止您嘗試了什麼? – AVK
@AVKNaidu請檢查編輯 – saira