0

变量 inputFile 保持为空,因为 fileOpenPicker 由于某种原因没有执行,这个函数曾经完美地工作它打开了一个文件资源管理器,让我选择一个我不知道是什么让它表现得像这样的图像

public async void Initiate_Matrix()
{
    FileOpenPicker fileOpenPicker = new FileOpenPicker
    {
        SuggestedStartLocation = PickerLocationId.PicturesLibrary
    };

    fileOpenPicker.FileTypeFilter.Add(".tif");
    var inputFile = await fileOpenPicker.PickSingleFileAsync();
    
    if (inputFile == null)
    {
        // The user cancelled the picking operation
        return;
    }

    using (IRandomAccessStream stream = await inputFile.OpenAsync(FileAccessMode.Read))
    {
        // Create the decoder from the stream
        BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
        PixelDataProvider pixelData = await decoder.GetPixelDataAsync();
        var bytes = pixelData.DetachPixelData();
        var a = decoder.PixelWidth;
        var b = decoder.PixelHeight;
        Color[,] array = new Color[a, b];
        for (int x = 0; x < decoder.PixelWidth; x++)
        {
            for (int y = 0; y < decoder.PixelHeight; y++)
            {
                var location = (y * (int)decoder.PixelWidth + x) * 3;
                Color color = Color.FromArgb(0, bytes[location + 0], bytes[location + 1], bytes[location + 2]);
                array[x, y] = color;
            }
        }
        matrix = array;
    }
}
4

0 回答 0