WPF 프로그램의 데이터 값에서 16 비트 회색 음영 이미지를 만들고 싶습니다. 현재 PixelFormats.Gray16이 설정된 WriteableBitmap을 사용하고 있습니다.WPF에서 16 비트 + 회색 음영 이미지 만들기
그러나이 작업을 수행 할 수없고 Microsoft 페이지 (http://msdn.microsoft.com/en-us/magazine/cc534995.aspx)는 WriteableBitmap을 통해 쓰기 불가능한 Gray16 형식을 나열합니다. 하지만 어떻게 이런 식으로 하나를 만들지 제안하지 않습니다.
현재 내 코드는i
이미지의 높이와
j
폭을 나타내는 루프 내에서 작동하고,이 같은 같습니다
short dataValue = GetDataSamplePixelValue(myDataValue);
//the pixel to fill with this data value:
int pixelOffset = ((i * imageWidth) + j) * bytesPerPixel;
//set the pixel colour values:
pixels[pixelOffset] = dataValue;
나는이 가진 이미지를 얻을 할을하지만 그것은 단지 무리입니다 세로 줄 흑백. 위의 예제에서 short
이 byte
으로 변경된 경우 8 비트 회색조 데이터 만 사용하면 문제가 없습니다.
누구나 WPF를 사용하여 픽셀 당 16 비트 이상의 그레이 스케일 이미지를 만드는 방법을 알고 있습니까? 이 이미지는 궁극적으로 저장해야합니다.
모든 조언을 주시면 감사하겠습니다.
나는 약간의 편집을 완료했으며 이제 Gray16 PixelFormat을 사용하여 합리적인 이미지를 얻고 이것 또한
편집
. 이미지 프로그램의 색상 수가 256을 제공하기 때문에 사실 16 비트인지는 알기가 매우 어렵습니다. 이미지가 WPF 또는 이미지 프로그램에 의해 제약을 받기 때문에 이것이 맞는지 확실하지 않습니다. 외관상으로는 많은 이미지 프로그램이 하위 8 비트를 무시하므로이를 지원하지 않습니다. 지금은 내가 가지고있는 것을 고수 할 것입니다.정보에 대한 코드는 다음과 같이 인이 예 startLine 및 shiftFactor에서
myBitmap = new WriteableBitmap((int)visualRect.Width, (int)visualRect.Height, 96, 96, PixelFormats.Gray16, null);
int bytesPerPixel = myBitmap.Format.BitsPerPixel/8;
ushort[] pixels = new ushort[(int)myBitmap.PixelWidth * (int)myBitmap.PixelHeight];
//if there is a shift factor, set the background colour to white:
if (shiftFactor > 0)
{
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = 255;
}
}
//the area to be drawn to:
Int32Rect drawRegionRect = new Int32Rect(0, 0, (int)myBitmap.PixelWidth, (int)myBitmap.PixelHeight);
//the number of samples available at this line (reduced by one so that the picked sample can't lie beyond the array):
double availableSamples = myDataFile.DataSamples.Length - 1;
for (int i = 0; i < numDataLinesOnDisplay; i++)
{
//the current line to use:
int currentLine = ((numDataLinesOnDisplay - 1) - i) + startLine < 0 ? 0 : ((numDataLinesOnDisplay- 1) - i) + startLine;
for (int j = 0; j < myBitmap.PixelWidth; j++)
{
//data sample to use:
int sampleToUse = (int)(Math.Floor((availableSamples/myBitmap.PixelWidth) * j));
//get the data value:
ushort dataValue = GetDataSamplePixelValue(sampleToUse);
//the pixel to fill with this data value:
int pixelOffset = (((i + shiftFactor) * (int)myBitmap.PixelWidth) + j);
//set the pixel colour values:
pixels[pixelOffset] = dataValue;
}
}
//copy the byte array into the image:
int stride = myBitmap.PixelWidth * bytesPerPixel;
myBitmap.WritePixels(drawRegionRect, pixels, stride, 0);
이미 설정하고, 사용자가 shiftFactor 오직 비제로, 시청 정보 파일 데이터의 어느 시점에서 의존되고 화면보다 작은 데이터 파일의 경우이 값을 사용하여 이미지를 세로로 가운데에 맞 춥니 다.
WriteableBitmap에 PixelFormats.Gray16에 문제가 있다는 증거는 없습니다. 귀하의 궁금한 점은 무엇입니까? 어떤 코드가 이미지를 다루고 잘못된 결과를 설명하려고하면 어떨까요? –
나는 내가 이해하고 있는지 잘 모르겠다. 2^16은 65536 개의 고유 한 색상을 제공하고 2^8은 256을 제공합니다. – Greg
이미지를 저장하고 저장된 이미지를로드 한 다음 코드에서 자신의 히스토그램을 생성하여 실제로 올바른 색상 수를 얻었는지 확인하십시오. 다른 프로그램을 신뢰할 수 없다면 스스로 만드십시오! – djdanlib