3

Windows Phone 8.1 (WINRT) アプリを作成しています。fileopenpickerを使用してギャラリーから画像を選択し、それをアプリに表示しています。しかし、アプリに表示される前に、ユーザーがこの画像をトリミングできるようにしたいと考えています。

Windows Phone 8 では、幅のプロパティとトリミング オプションを自動的に使用するPhotochooser タスクを使用しました。

今、私はこれを使用しようとしています: Windows Phone 8.0: Image Crop With Rectangle

しかし、Windows Phone 8.1にはWriteableBitmap.Pixelsはありません。WriteableBitmap.Pixels の代わりに何を使用しますか?

// Create a new WriteableBitmap. The size of the bitmap is the size of the cropping rectangle
// drawn by the user, multiplied by the image size ratio.
WB_CroppedImage = new WriteableBitmap((int)(widthRatio * Math.Abs(Point2.X - Point1.X)), (int)(heightRatio * Math.Abs(Point2.Y - Point1.Y)));

// Calculate the offset of the cropped image. This is the distance, in pixels, to the top left corner
// of the cropping rectangle, multiplied by the image size ratio.
int xoffset = (int)(((Point1.X < Point2.X) ? Point1.X : Point2.X) * widthRatio);
int yoffset = (int)(((Point1.Y < Point2.Y) ? Point1.Y : Point2.X) * heightRatio);

// Copy the pixels from the targeted region of the source image into the target image, 
// using the calculated offset
if (WB_CroppedImage.Pixels.Length > 0)
{
    for (int i = 0; i < WB_CroppedImage.Pixels.Length; i++)
    {
        int x = (int)((i % WB_CroppedImage.PixelWidth) + xoffset);
        int y = (int)((i / WB_CroppedImage.PixelWidth) + yoffset);
        WB_CroppedImage.Pixels[i] = WB_CapturedImage.Pixels[y * WB_CapturedImage.PixelWidth + x];
    }

    // Set the source of the image control to the new cropped bitmap
    FinalCroppedImage.Source = WB_CroppedImage;                              
}
else
{
     FinalCroppedImage.Source = null;
}
4

1 に答える 1