English 中文(简体)
C++ 树立形象
原标题:C++ creating image
  • 时间:2009-12-07 22:25:56
  •  标签:
  • c++
  • image

我当时没有在C++制定方案,现在我不得不写一件简单的事,而是把我nut子。

I need to create a bitmap from a table of colors: char image[200][200][3];

第一次协调是宽度、二级高度、第三色:高频。 如何这样做?

Thanks for any help. Adam

最佳回答

http://en.wikipedia.org/wiki/BMP_file_format”rel=“noretinger” http://en.wikipedia.org/wiki/BMP_file_format。

有了这一手头信息,我们就能够写出一个快速的BMP:

// setup header structs bmpfile_header and bmp_dib_v3_header before this (see wiki)
// * note for a windows bitmap you want a negative height if you re starting from the top *
// * otherwise the image data is expected to go from bottom to top *

FILE * fp = fopen ("file.bmp", "wb");
fwrite(bmpfile_header, sizeof(bmpfile_header), 1, fp);
fwrite(bmp_dib_v3_header, sizeof(bmp_dib_v3_header_t), 1, fp);

for (int i = 0; i < 200; i++)  {
 for (int j = 0; j < 200; j++) {
  fwrite(&image[j][i][2], 1, 1, fp);
  fwrite(&image[j][i][1], 1, 1, fp);
  fwrite(&image[j][i][0], 1, 1, fp);
 }
}

fclose(fp);

如果要设立负责人,我们就知道问题。

Edit: I forgot, BMP 文档预期BGR而不是RGB,我已更新该法典(没有发现任何人)。

问题回答

我建议ImageMagick,综合图书馆等。

我将首先设法查明:BMP文件格式(你用比图表示,正确吗?)是如何界定的。 然后,我将把阵列改为这种格式,并将之印制到档案中。

如果这一选择是这样,我也想设法找到一个现有的图书馆,用于编写BAMP文件,并公正使用。

如果我所说的话对你来说已经显而易见,那么我不知道你在哪一个阶段的 process。

最好把这一功能作为简单的1个层面阵列。

iii (如果是每台粉碎机的数量)

 char image[width * height * bytes];

然后,你可以接触以下阵列中的相关立场:

 char byte1 = image[(x * 3) + (y * (width * bytes)) + 0];
 char byte2 = image[(x * 3) + (y * (width * bytes)) + 1];
 char byte3 = image[(x * 3) + (y * (width * bytes)) + 2];




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签