У меня экран 240х128. Когда я создаю экран 256x128, все в порядке.
AppScreen = new byte[3 * 1024 * 32];
rawStride = (256 * PixelFormats.Rgb24.BitsPerPixel + 7) / 8;
myScreen = new System.Windows.Media.Imaging.WriteableBitmap(256, 128, 96, 96, PixelFormats.Rgb24, null);
myScreen = BitmapSource.Create(256, 128, 96, 96, PixelFormats.Rgb24, null, AppScreen, rawStride);
для 240 я делаю это так:
AppScreen = new byte[3 * 1024 * 32 - (16*3)];
rawStride = (240 * PixelFormats.Rgb24.BitsPerPixel + 7) / 8;
myScreen = new System.Windows.Media.Imaging.WriteableBitmap(240, 128, 96, 96, PixelFormats.Rgb24, null);
myScreen = BitmapSource.Create(240, 128, 96, 96, PixelFormats.Rgb24, null, AppScreen, rawStride);
Но я вижу черную линию, когда экран должен быть полностью зеленым.
введите описание изображения здесь
private void ScreenInit()
{
for (int i = 0; i < 4096; i++)
{
BizonScreen[i] = 0;
}
ScreenColor = Colors.LightGreen;
RenderScreen();
}
private void RenderScreen()
{
/* Przepisanie z bitowej struktury na format */
for (uint x = 0; x < 240; x++)
{
for (uint y = 0; y < 128; y++)
{
SetPixel(x, y, ScreenColor);
}
}
this.myScreen = BitmapSource.Create(240, 128, 96, 96, PixelFormats.Rgb24, null, AppScreen, rawStride);
this.myScreen.Freeze();
this.InvokeIfRequired((value) => Image_Screen.Source = value, this.myScreen);
}
private void SetPixel(uint X, uint Y, Color Color)
{
AppScreen[(X * 3) + (Y * 768)] = Color.R;
AppScreen[(X * 3) + (Y * 768) + 1] = Color.G;
AppScreen[(X * 3) + (Y * 768) + 2] = Color.B;
}
Редактировать:
AppScreen = new byte[3 * 1024 * 30];
AppScreen[(X * 3) + (Y * 3*240)] = Color.R;
AppScreen[(X * 3) + (Y * 3*240) + 1] = Color.G;
AppScreen[(X * 3) + (Y * 3*240) + 2] = Color.B;
и работать на 240.