View Single Post
  #1 (permalink)  
Old January 14th, 2005, 01:52 AM
ck ck is offline
Authorized User
 
Join Date: Dec 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Rushing...Pls Help Me...

hi,
 do some1 know how to define the image size?? means...when i
write & read the image, the image in the temporary file will be the same with the original image size...means(my original image is 1.21MB, then when the program write into & read from the
temporary file, it also must be the same size(1.21MB)...so,
how to fix this problem??? & another problem is...do some1 know
to write & read the image into image array??? below is my codes,
pls feel free to help check & modify wat's wrong of my codes..

 thanks for ur kindness for helping.....

best regards,
ck

codes:

// Test3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "Test3.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <iostream>
#include <tchar.h>
#include <wingdi.h>
#include <string.h>
#include <wchar.h>
//#define MAX_SIZE 256
//const int MAXIMA = 512;
#define NULL_LEN 1
#define CMPLX 4

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

struct Image {
    int rows;
    int cols;
    unsigned char *data;
    unsigned char type;
};


void Img_in(Image *img);
void Img_out(Image *out);

int main()
{

    //char Bitmap[MAX_SIZE + NULL_LEN];

    char Bitmap[CMPLX * NULL_LEN];

    FILE *fp;

    if((fp = fopen("Image.RAW", "wb"))==NULL)
    {
        printf("File can't open");
    }
    else
    {
        cout << "Bitmap: ";

    //Open Directory
    _TCHAR szFileTitle[MAX_PATH] = {0};
    _TCHAR szTitle[MAX_PATH] = _TEXT("Open Dammit");

    OPENFILENAME openfile;
    memset(&openfile,0,sizeof(openfile));
    openfile.lStructSize = sizeof(openfile);
    openfile.lpstrTitle = szTitle;
    openfile.Flags = OFN_FILEMUSTEXIST;
    openfile.lpstrFile = szFileTitle;
    openfile.nMaxFile = MAX_PATH;
    openfile.lpstrFilter = ("Bitmap Files (*.bmp)\0*.bmp\0\0");

    if(GetOpenFileName(&openfile) != FALSE)
    {

        //Read the open file
        FILE *file = fopen(szFileTitle, "rb");

        //Read from the open file and write to FASS.inv all the bitmap
        while(!feof(file)){
            //fgets(Bitmap, MAX_SIZE, file);
            fgets(Bitmap, CMPLX, file);
            fputs(Bitmap, fp);
        }


        fclose(file);
    }

    fclose(fp);

    cout << endl << endl;


FILE *FASS = fopen(szFileTitle, "rb");

 if( FASS== NULL )
      printf( "The file fscanf.out was not opened\n" );
   else
   {

    //Read from tmp file and assign data to Bitmap
    //Read from tmp file and assign data to Name
    //fscanf(FASS, "%s\n", Name);
    fseek( FASS, 0L, SEEK_SET );
    fscanf(FASS, "%s\n", Bitmap);

    //Print information
    cout << "Information about the FASS";
    //cout << "\nName: " << Name;
    cout << "\nBitmap: " << Bitmap;

    fclose(FASS);
   }
    cout << endl;

    return 0;

}
}
void Img_in(Image *img)
{

    FILE *wfile;
    int i, sz;
    float *fptr;

    if((wfile = fopen("Image.RAW", "wb"))==NULL)
    {
        printf("File can't be open");
    }
    else
    {

        fptr = (float *)img->data;
        sz = img->rows * img->cols;

        for(i=0; i<sz; ++i)
            fwrite(fptr,sizeof(float),2,wfile);
        fptr += 2;
            //fwrite(&img,sizeof(struct Image),1,wfile);
        fclose(wfile);
    }
}

void Img_out(Image *out)
{
    FILE *rfile;
    int i, sz;
    float *fptr;

    if((rfile = fopen("szFileTitle", "rb"))==NULL)
    {
        printf("File can't be open");
    }
    else
    {
        fptr = (float *)out->data;
        sz = out->rows * out->cols;

        for(i=0; i<sz; ++i)
            fseek(rfile, 0L, SEEK_SET );
            fread(fptr,sizeof(float),2,rfile);
        fptr += 2;
            //fread(&out,sizeof(struct Image),1,rfile);
        fclose(rfile);
    }
}

__________________
ck.
Reply With Quote