: : : :
This message was edited by MT2002 at 2006-2-3 18:32:15
: : : : : : : hi
: : : : : : : i have posted this message in the c beginners secito, but maybe this the right place for it. the question is the next: how can i load an image into a variable in c? i suppose this variable must be an array, which dimensions depend on the type of image. i do not know either this can be done by using a standard c library. if this is not the case, any suggestion about how to start working?
: : : : : : :
: : : : : : : thanks
: : : : : : :
: : : : : : : cacaramba
: : : : : : :
: : : : : : Well, you can use memory also to do this instead of an array. But this also depends on you use DOS or Win32. Anyway, here's a link for some C graphs library that may help you out:
: : : : : : http://www.programmersheaven.com/app/search/search.aspx?SearchMode=1&SearchTxt=c+library+graphics
: : : : : :
: : : : : : If you want to develop your own graph lib, you need to know some formats, this is a link to a File Format Encyclopedia:
: : : : : :
http://www.programmersheaven.com/search/Download.asp?FileID=923
: : : : : :
: : : : : : An array in this case does not need to be multidimensional, just a twodimensional array. But this is only if you need a constant size image, such as 100x100.
: : : : : :
: : : : : : int image[100][100]
: : : : : :
: : : : : : But, remember that you can also store image in memory.
: : : : : :
: : : : : : Or, you could just load the file directly onto the screen.
: : : : : :
: : : : : : Hope this lil info helps you out.
: : : : : : ****************
: : : : : : Any questions? Just ask!
: : : : : :
: : : : : :
GAASHIUS 
: : : : : :
: : : : : :
: : : : : :
: : : : : i also want to know how this is done. in your example, how do you assign a 100x100 bmp file for example named "trial.bmp" to the 2 dimensional array variable image. im very confused in this part. tnx!
: : : : :
: : : :
: : : : Just loop it. Example..
: : : : const int iWidth = 100, //image width/height
: : : : iHeight = 100;
: : : :
: : : : char* image; // your loaded image
: : : :
: : : : int pixels[iHeight][iWidth]; // destination (assuming 24 bpp image)
: : : :
: : : :
: : : : // copy the image
: : : : for ( int y = 0; y< iHeight; y++)
: : : : for ( int x=0; x<iWidth; x++)
: : : : pixels [y][x] = image [x+y*iWidth];
: : : :
: : : : The formula x+y*iWidth can be used to retrieve an element
: : : : (in this case, pixel) at an x/y location in linear memory.
: : : :
: : : : This will only work if "image" and "pixels" are
: : : : the same bit depth. If they are not, you will need to
: : : : convert it.
: : : :
: : : : Hope this helps!
: : : : ~mt2002
: : : :
: : : :
: : : :
: : : i have this code for comaparing two images to see if they are 100% match with each other.
: : :
: : : #include<stdio.h>
: : : #include<math.h>
: : :
: : : /* definition of both bitmaps height and width */
: : : #define BITMAPX 352
: : : #define BITMAPY 292
: : :
: : : /* structure to contain data for one pixel */
: : : typedef struct {
: : : float r,g,b; /* color data varies for each color from 0-255 */
: : : }RGB; /* they are floats just for convinience */
: : :
: : : /* two 352x292x24 bit bitmaps containing about to be compared images */
: : : RGB bitmap1[BITMAPX][BITMAPY],bitmap2[BITMAPX][BITMAPY];
: : :
: : :
: : : /* variables to hold number of pixels, current pixel and match so far */
: : : /* and match for current pixel */
: : : float pixels=BITMAPX*BITMAPY,current_pixel=0;
: : : float match=0,currentmatch=0;
: : :
: : :
: : : main()
: : : {
: : :
: : : /* now we start looping through all pixels in our bitmaps comparing */
: : : /* according pixels to each other */
: : : int posx, posy, currentpixel;
: : : for(posx=0;posx<BITMAPX;posx++){
: : : for(posy=0;posy<BITMAPY;posy++){
: : : currentpixel++;
: : :
: : : /* this is where actual comparison takes place */
: : : /* given that all three basic colors are on different axis */
: : : /* match between them can be calculated using */
: : : /* vector length equation */
: : : currentmatch=sqrt(pow(bitmap1[posx][posy].r-bitmap2[posx][posy].r,2)+pow(bitmap1[posx][posy].g-bitmap2[posx][posy].g,2)+pow(bitmap1[posx][posy].b-bitmap2[posx][posy].b,2));
: : :
: : : match=((match*currentpixel)+currentmatch)/(currentpixel);
: : : }
: : : }
: : :
: : : match=100-match/2.56;
: : :
: : : printf("%f",match);
: : : }
: : :
: : :
: : : but i cant seem to load the image properly to the two dimensional arrays that I declared. how can I for example load an image named "try.bmp" to bitmap1 and "try1.bmp" to bitmap2. thanks!
: : :
: :
: : Do you have a bitmap loader? If so, load the bitmap to heap
: : memory, and copy it to the array (as I posted).
: :
: : If you dont have a loader, making one is easy. The Win32 API
: : makes it even easier. Im assuming you dont have a loader
: : (according to your code). If so, check out
: : http://www.gamedev.net/reference/articles/article1966.asp
: :
: : Hope this helps!
: : ~mt2002
: :
:
: btw is there any conflict if i'm going to use this program on a linux platform because im using bmp images. would you recommend using a different image format then?
:
I dont know, but it shouldnt cause any conflict..As long as you
write your loader from scratch (ie; dont use Win32) it should
still be okay.