나는 비트 맵을 만들려고 노력해 왔고, 상기 비트 맵을 사용하여 그림 상자 안에 표시해야하는 이미지를 만듭니다. 지금까지 Google은 도움이되지 않았습니다. 비트 맵은 배열에 정의 된 흑백 픽셀로 채워야하지만 지금은 Aliceblue를 사용했습니다.
코드를 실행할 때이 줄에서 "value cant be null"오류가 발생합니다.
Bitmap afbeelding = new Bitmap(resolutie, resolutie, g);
내가 시도한 것은 다음과 같습니다.
public void draw(Array array)
{
Bitmap afbeelding = new Bitmap(resolutie, resolutie, g);
for(int x = 0; x < array.Length; x++)
{
for (int y = 0; y < array.Length; y++)
{
afbeelding.SetPixel(x, y, Color.AliceBlue);
}
}
pictureBox1.Image = afbeelding;
//afbeelding = pictureBox1.CreateGraphics();
}
누구든지 이것을 해결하는 방법을 알고 있습니까? 그래픽에 DrawPixel 기능이 없기 때문에 g를 채우는 방법을 모르겠습니다.
배열에 이미지의 정의가 포함되어 있다고 가정하면 이미지를 가로 및 세로로 배열로 채우는 대신 배열의 청크로 이미지 행을 채워야합니다.
배열이 10 x 10 이미지 용이라고 가정하면 배열의 길이가 100 바이트가됩니다. 이미지의 첫 번째 행에 처음 10 바이트를 할당해야하는 식입니다. 픽셀을 그릴 지 여부도 배열 멤버의 값을 확인해야합니다.
예:
public void draw(bool[] array)
{
Bitmap afbeelding = new Bitmap(resolutieX, resolutieY);
for(int y = 0; y < resolutieY; y++)
{
for (int x = 0; x < resolutieX; x++)
{
if (array[y * resolutieX + x] == true)
afbeelding.SetPixel(x, y, Color.Black);
else
afbeelding.SetPixel(x, y, Color.White);
}
}
pictureBox1.Image = afbeelding;
}
이를 테스트하려면 (폼에 button1이 있다고 가정) :
int resolutieX = 100;
int resolutieY = 100;
Random R = new Random();
private void button1_Click(object sender, EventArgs e)
{
bool[] bArray = new bool[resolutieX * resolutieY];
for (int i = 0; i < bArray.Length; i++)
bArray[i] = R.Next(0, 2) == 1 ? true : false;
draw(bArray);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다