How to write a C Program to Bitmap Triangle in C Programming language ?
#include <Windows.h>
#include <stdio.h>
#include <math.h>
#define sB 500 // nie zmieniac, działa dla wartości <= 504, chuj wie czemu
typedef unsigned long int ULint;
int main(){
FILE *obraz;
obraz = fopen("obraz.bmp", "wb");
ULint tlo[sB][sB]; // deklaracja tablicy pikseli
// RYSOWANIE TŁA
for (int i = 0; i < sB; i++){ // kolumny
for (int j = 0; j < sB; j++) // wiersze
{
tlo[i][j] = 0xFF000340;
}
}
// RYSOWANIE TRÓJKĄTA
for (int i = 0; i < sB; i++){ // kolumny
for (int j = i/2; j < sB-(i/2); j++) // wiersze
{
tlo[i][j] = 0xFFFFF77F;
}
}
BITMAPV4HEADER hdr2; // deklaracja drugiego nagłówka
hdr2.bV4Size = 108; // rozmiar struktury - nie ruszać, bo jebnie
hdr2.bV4Width = sB; // rozmiar X (long)
hdr2.bV4Height = sB; // rozmiar Y (long)
hdr2.bV4Planes = 1; // warstwy, nie zmieniać
hdr2.bV4BitCount = 32; // ilosc bitow na piksel, nie zmieniać
hdr2.bV4V4Compression = 3; // kompresja, nie zmieniać
hdr2.bV4SizeImage = hdr2.bV4Width * hdr2.bV4Height * 4; // rozmiar pliku ywjsciowego
hdr2.bV4YPelsPerMeter = 2835; // STAŁE
hdr2.bV4XPelsPerMeter = 2835; // STAŁE
hdr2.bV4ClrUsed = 0; // STAŁE
hdr2.bV4ClrImportant = 0; // STAŁE
hdr2.bV4RedMask = 0x00FF0000; // czerwona 00 FF 00 00
hdr2.bV4GreenMask = 0x0000FF00; // zielona 00 00 FF 00
hdr2.bV4BlueMask = 0x000000FF; // niebieska 00 00 00 FF
hdr2.bV4AlphaMask = 0xFF000000; // alpha FF 00 00 00
hdr2.bV4CSType = LCS_WINDOWS_COLOR_SPACE; // nie zmieniać
// hdr2.bV4Endpoints = wtf? // o chuj tu chodzi?
hdr2.bV4GammaRed = 0; // nie zmieniać
hdr2.bV4GammaGreen = 0; // nie zmieniać
hdr2.bV4GammaBlue = 0; // nie zmieniać
int size_BITMAPV4 = sizeof(hdr2.bV4Size)+ // tego tym bardziej nie ruszać!
sizeof(hdr2.bV4Width)+
sizeof(hdr2.bV4Height)+
sizeof(hdr2.bV4Planes)+
sizeof(hdr2.bV4BitCount)+
sizeof(hdr2.bV4V4Compression)+
sizeof(hdr2.bV4SizeImage)+
sizeof(hdr2.bV4YPelsPerMeter)+
sizeof(hdr2.bV4XPelsPerMeter)+
sizeof(hdr2.bV4ClrUsed)+
sizeof(hdr2.bV4ClrImportant)+
sizeof(hdr2.bV4RedMask)+
sizeof(hdr2.bV4GreenMask)+
sizeof(hdr2.bV4BlueMask)+
sizeof(hdr2.bV4AlphaMask)+
sizeof(hdr2.bV4CSType)+
sizeof(hdr2.bV4Endpoints)+
sizeof(hdr2.bV4GammaRed)+
sizeof(hdr2.bV4GammaGreen)+
sizeof(hdr2.bV4GammaBlue);
BITMAPFILEHEADER hdr1; // deklaracja nagłówka!
hdr1.bfType = 0x4D42; // sygnatura nagłówka - nie ruszaj, bo jebnie
hdr1.bfReserved1 = 0;
hdr1.bfReserved2 = 0;
hdr1.bfOffBits = size_BITMAPV4; // rozmiar struktury, też jebnie jak tkniesz
hdr1.bfSize = hdr1.bfOffBits + hdr2.bV4SizeImage;
int size_BFH = sizeof(hdr1.bfType)+ // tego tym bardziej nie ruszać!
sizeof(hdr1.bfReserved1)+
sizeof(hdr1.bfReserved2)+
sizeof(hdr1.bfOffBits)+
sizeof(hdr1.bfSize);
printf("Rozmiar struktury naglowka = %d\nRozmiar struktury DIB = %d\n", size_BFH, size_BITMAPV4); // napis tekstowy
fwrite((void*)&hdr1, sizeof(hdr1), 1, obraz); // zapis nagłówka 1
fwrite((void*)&hdr2, sizeof(hdr2), 1, obraz); // zapis nagłówka 2
fwrite(tlo, sizeof(tlo), 1, obraz); // zapis tablicy pikseli
fclose(obraz);
return 0;
}
Learn More :
Bitmap
Triangle
- Waveform Generation (Triangle Wave) C Program
- C Program To Show Pascal Triangle
- C Program to Print Floyd's Triangle
- C Program Nested Loop (inverted Triangle) C Code
- Triangle Wave in C Program
- C Program to calculate the sum of elements of upper triangle of a n*n matrix using DMA
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
- C Program to Rectangular Triangle Using Operator