MapTileBitmapRequest.PixelData 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
CustomMapTileDataSource의 비트맵 데이터를 가져옵니다.
public:
property IRandomAccessStreamReference ^ PixelData { IRandomAccessStreamReference ^ get(); void set(IRandomAccessStreamReference ^ value); };
IRandomAccessStreamReference PixelData();
void PixelData(IRandomAccessStreamReference value);
public IRandomAccessStreamReference PixelData { get; set; }
var iRandomAccessStreamReference = mapTileBitmapRequest.pixelData;
mapTileBitmapRequest.pixelData = iRandomAccessStreamReference;
Public Property PixelData As IRandomAccessStreamReference
속성 값
비트맵 데이터입니다.
설명
CustomMapTileDataSource 는 메모리에 타일을 그리고 픽셀 스트림으로 반환할 수 있도록 지원합니다. 다음 코드 샘플에서는 메모리에서 타일을 그리는 한 가지 방법을 보여 줍니다.
// Create new custom tile source
CustomMapTileDataSource customDataSource = new CustomMapTileDataSource();
customDataSource.BitmapRequested += customDataSource_BitmapRequestedAsync;
customTileSource = new MapTileSource(customDataSource);
/// <summary>
/// BitmapRequested event handler for CustomMapTileDataSource.BitmapRequested event
/// </summary>
/// <param name="sender">sender</param>
/// <param name="args">args for ZoomLevel, X, Y and the PixelData</param>
private async void customDataSource_BitmapRequestedAsync(CustomMapTileDataSource sender, MapTileBitmapRequestedEventArgs args)
{
var deferral = args.Request.GetDeferral();
args.Request.PixelData = await CreateBitmapAsStreamAsync();
deferral.Complete();
}
/// <summary>
/// Create memory buffer with length of 256 * 256 * 4.
/// This memory buffer is holding 256 * 256 pixels
/// </summary>
/// <returns>memory buffer that fills with red opaque pixels.</returns>
private async Task<Windows.Storage.Streams.RandomAccessStreamReference> CreateBitmapAsStreamAsync()
{
int pixelHeight = 256;
int pixelWidth = 256;
int bpp = 4;
byte[] bytes = new byte[pixelHeight * pixelWidth * bpp];
for (int y = 0; y < pixelHeight; y++)
{
for (int x = 0; x < pixelWidth; x++)
{
int pixelIndex = y * pixelWidth + x;
int byteIndex = pixelIndex * bpp;
bytes[byteIndex] = 0xff; // Red
bytes[byteIndex + 1] = 0x00; // Green
bytes[byteIndex + 2] = 0x00; // Blue
bytes[byteIndex + 3] = 0x80; // Alpha (0xff = fully opaque)
}
}
// Create RandomAccessStream from byte array
InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
IOutputStream outputStream = randomAccessStream.GetOutputStreamAt(0);
DataWriter writer = new DataWriter(outputStream);
writer.WriteBytes(bytes);
await writer.StoreAsync();
await writer.FlushAsync();
return RandomAccessStreamReference.CreateFromStream(randomAccessStream);
}
Windows::Foundation::IAsyncOperation<Windows::Storage::Streams::InMemoryRandomAccessStream> TileSources::CustomRandomAccessStreamAsync()
{
const int pixelHeight{ 256 };
const int pixelWidth{ 256 };
const int bpp{ 4 };
std::array<byte, pixelHeight * pixelWidth * bpp> bytes;
for (int y = 0; y < pixelHeight; ++y)
{
for (int x = 0; x < pixelWidth; ++x)
{
int pixelIndex = y * pixelWidth + x;
int byteIndex = pixelIndex * bpp;
// Set current pixel bytes
bytes[byteIndex] = (byte)(std::rand() % 256); // Red
bytes[byteIndex + 1] = (byte)(std::rand() % 256); // Green
bytes[byteIndex + 2] = (byte)(std::rand() % 256); // Blue
bytes[byteIndex + 3] = (byte)((std::rand() % 56) + 200); // Alpha (0xff = fully opaque)
}
}
// Create RandomAccessStream from byte array
Windows::Storage::Streams::InMemoryRandomAccessStream randomAccessStream;
Windows::Storage::Streams::IOutputStream outputStream{ randomAccessStream.GetOutputStreamAt(0) };
Windows::Storage::Streams::DataWriter writer{ outputStream };
writer.WriteBytes(bytes);
co_await writer.StoreAsync();
co_await writer.FlushAsync();
co_return randomAccessStream;
}
InMemoryRandomAccessStream^ TileSources::CustomRandomAccessStream::get()
{
int pixelHeight = 256;
int pixelWidth = 256;
int bpp = 4;
Array<byte>^ bytes = ref new Array<byte>(pixelHeight * pixelWidth * bpp);
for (int y = 0; y < pixelHeight; y++)
{
for (int x = 0; x < pixelWidth; x++)
{
int pixelIndex = y * pixelWidth + x;
int byteIndex = pixelIndex * bpp;
// Set current pixel bytes
bytes[byteIndex] = (byte)(std::rand() % 256); // Red
bytes[byteIndex + 1] = (byte)(std::rand() % 256); // Green
bytes[byteIndex + 2] = (byte)(std::rand() % 256); // Blue
bytes[byteIndex + 3] = (byte)((std::rand() % 56) + 200); // Alpha (0xff = fully opaque)
}
}
// Create RandomAccessStream from byte array
InMemoryRandomAccessStream^ randomAccessStream = ref new InMemoryRandomAccessStream();
IOutputStream^ outputStream = randomAccessStream->GetOutputStreamAt(0);
DataWriter^ writer = ref new DataWriter(outputStream);
writer->WriteBytes(bytes);
create_task(writer->StoreAsync()).then([writer](unsigned int)
{
create_task(writer->FlushAsync());
});
return randomAccessStream;
}