PDA

View Full Version : مبتدی: کار با فایل Bitmap



Collector
پنج شنبه 17 اسفند 1391, 16:39 عصر
سلام
من در مورد کار با فایل بیت مپ یعنی نوشتن و خواندن پیکسل در این فایل جستجو کردم.ولی نتونستن مورد مناسبی را پیدا کنم
از کتاب خونه WinGDI.h سعی کردم استفاده کنم اما نشد.
امکانش هست در این مورد راهنمایی فرمایید. من زیاد با ++C اشنا نیستم.

بهروز عباسی
پنج شنبه 17 اسفند 1391, 17:47 عصر
working with bitmaps in C (http://bytes.com/topic/c/answers/751843-working-bitmaps-c)
EasyBMP Cross-Platform Windows Bitmap Library (http://easybmp.sourceforge.net/)
bitmap (http://www.cplusplus.com/forum/general/1782/)
read pixel value in bmp file (http://stackoverflow.com/questions/9296059/read-pixel-value-in-bmp-file)
How can I read BMP pixel values into an array? (http://stackoverflow.com/questions/5751749/how-can-i-read-bmp-pixel-values-into-an-array)
Getting the pixel value of BMP file (http://stackoverflow.com/questions/1968561/getting-the-pixel-value-of-bmp-file)

Collector
جمعه 18 اسفند 1391, 13:03 عصر
working with bitmaps in C (http://bytes.com/topic/c/answers/751843-working-bitmaps-c)
EasyBMP Cross-Platform Windows Bitmap Library (http://easybmp.sourceforge.net/)
bitmap (http://www.cplusplus.com/forum/general/1782/)
read pixel value in bmp file (http://stackoverflow.com/questions/9296059/read-pixel-value-in-bmp-file)
How can I read BMP pixel values into an array? (http://stackoverflow.com/questions/5751749/how-can-i-read-bmp-pixel-values-into-an-array)
Getting the pixel value of BMP file (http://stackoverflow.com/questions/1968561/getting-the-pixel-value-of-bmp-file)


ممنون که جواب دادید

این کد که در لینک آخر بود را مشاهده فرمایید بایستی قسمتی از تصویر را در صفحه نمایش چاپ کند اما درست کار را انجام نمیدهد. من بقیه لینک ها را هم مشاهده کردم هر کدام خطایی به چنین شکل دارند

int image[300][300]; // first number here is 1024 pixels in my image, 3 is for RGB values
FILE *streamIn;
streamIn = fopen("2.bmp", "r");

if (streamIn == (FILE *)0)
{
printf("File opening error ocurred. Exiting program.\n");
exit(0);
}

int byte;
int count = 0;

for(int i=0; i<54; i++)
byte = getc(streamIn); // strip out BMP header

for(int i=0; i<300; i++)
{
for(int j=0; j<300; j++)
{
image[i][j] = getc(streamIn);
image[i][j] = getc(streamIn);
image[i][j] = getc(streamIn);
}
}

HDC dcDesktop = GetDC(NULL);
COLORREF Color;

for(int i=0; i<300; i++)
for(int j=0; j<300; j++)
SetPixel(dcDesktop, i+100, j+100, RGB(image[i][j], image[i][j], image[i][j]));

Collector
جمعه 18 اسفند 1391, 17:02 عصر
این کد هم هست مربوط به خواندن فایل در خروجی یک آرایه یک بعدی میدهد در حالی که عکس یک آرایه دو بعدی هست
این برنامه فقط کل باید های آن را می خواند ولی ما فقط نیاز به Color Table داریم که یک آرایه دوبعدی است.

unsigned char* readBMP(char* filename)
{
int i;
FILE* f = fopen(filename, "rb");
unsigned char info[54];
fread(info, sizeof(unsigned char), 54, f); //read the 54-byte header

// extract image height and width from header
int width = *(int*)&info[18];
int height = *(int*)&info[22];

int size = 3 * width * height;
unsigned char* data = new unsigned char[size]; //allocate 3 bytes per pixel
fread(data, sizeof(unsigned char), size, f); //read the rest of the data at once
fclose(f);

for(i = 0; i <size; i += 3)
{
unsigned char tmp = data[i];
data[i] = data[i+2];
data[i+2] = tmp;
}
return data;
}

Collector
جمعه 18 اسفند 1391, 20:43 عصر
خیلی تمیز با این کتابخانه مشکل حل شد. (http://www.partow.net/programming/bitmap/index.html)