Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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





Similar Threads
Thread Thread Starter Forum Replies Last Post
pls help me.. nilusharief003 ASP.NET 2.0 Professional 5 December 4th, 2008 08:05 AM
Pls Help me on this pubudusi Classic ASP Databases 0 August 25th, 2006 06:02 AM
Pls help me!! hoailing22 ASP.NET 1.0 and 1.1 Basics 4 June 10th, 2005 11:24 PM
Pls help me hoailing22 ASP.NET 1.0 and 1.1 Basics 3 May 24th, 2005 11:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.