Page 1 of 1

[Solved]Reading File Paths from a text File

Posted: 2012-04-25T23:27:40-07:00
by rohitkrishna
Hi every one,

Iam trying to read paths of images from a text file and load them into wands...im getting a status problem...can anyone please help me with it and i want to write all images with a different file name ..im trying something like this...

Code: Select all

int main(int argc,char **argv)
{
	MagickWand    *magick_wand;

	FILE *fp;
	fp = fopen("./filenames.txt", "r");
	char str[200];
	if (argc != 4)
	{
		(void) fprintf(stdout,"Usage: %s image \n",argv[0]);
		exit(0);
	}

	/*
	Read an image.
	*/

	MagickWandGenesis(); // to initialize the magick-wand Environment
	
	magick_wand=NewMagickWand(); // To create the wand to store image

	printf("Loading Image....");
	while(fgets(str,sizeof(str),fp) != NULL)
	{
		status=MagickReadImage(magick_wand,str); // Function to read image into wand
	
		if (status == MagickFalse)
		{
			printf ("status problem");
		}
	
		v.sbimg_wdt=v.sbimg_hgt=atoi(argv[2]);
		v.treshold=atoi(argv[3]);
	
		subimages_pxls(magick_wand,v,argv);
	
		magick_wand=DestroyMagickWand(magick_wand); // To Destroy the image in the wand
		MagickWandTerminus();// To terminate the magick-wand Environment
	}
	return(0);
}
To write the image...m is a loop variable...it is an integer..

Code: Select all

MagickBooleanType status;
		printf("Writing New Image.....");
		status=MagickWriteImages(wand,"res[m].png",MagickTrue);
		if (status == MagickFalse)
		{
			printf ("status problem");
		}
Thanks in advance.

Re: Reading File Paths from a text File

Posted: 2012-04-26T00:36:28-07:00
by anthony
What is the problem? you are having exactly. What goes wrong?

Re: Reading File Paths from a text File

Posted: 2012-04-26T09:07:19-07:00
by rohitkrishna
anthony wrote:What is the problem? you are having exactly. What goes wrong?
Im not able to read the image....im tryin to read image path from a text file....and load it in to a wand...but its not loading the image into the wand.. its giving me status problem...im reading the string from the text file in to str and passing it as an argument to the MagicKReadImage()..

Re: Reading File Paths from a text File

Posted: 2012-04-26T22:08:30-07:00
by anthony
Are you permission right. What exception errors are you getting, that will tell you what is going wrong!

Re: Reading File Paths from a text File

Posted: 2012-04-27T18:52:50-07:00
by rohitkrishna
anthony wrote:Are you permission right. What exception errors are you getting, that will tell you what is going wrong!
Its just saying status problem..nothing more...and when im writing image..its not writing just one image..its reproducing multiple images.....each time

Re: Reading File Paths from a text File

Posted: 2012-04-27T19:14:01-07:00
by rohitkrishna
rohitkrishna wrote:
anthony wrote:Are you permission right. What exception errors are you getting, that will tell you what is going wrong!
Its just saying status problem..nothing more...and when im writing image..its not writing just one image..its reproducing multiple images.....each time
Thank you for helpin...
i figured out how to read the images...but im stuck at writing the output to a different image each time....its wiriting the results to same file over and over each time.

Re: Reading File Paths from a text File

Posted: 2012-05-01T00:26:46-07:00
by anthony
From what I can tell @ syntax will not work with any filename containing a directory separator. That is it is restricted to the current directory, and the filename needs to reflect this.

This may be a security measure, though I do not have any definitive answer on this, nor have to reviewed the code. Though I will be at some point as part of my part in the ongoing IMv7 Redevelopment.

Re: Reading File Paths from a text File

Posted: 2012-05-16T09:33:44-07:00
by rohitkrishna
anthony wrote:From what I can tell @ syntax will not work with any filename containing a directory separator. That is it is restricted to the current directory, and the filename needs to reflect this.

This may be a security measure, though I do not have any definitive answer on this, nor have to reviewed the code. Though I will be at some point as part of my part in the ongoing IMv7 Redevelopment.
Thanks anthony for your suggestions...i have finally figured how to read and write different images....by reading filepaths from a file.

Re: Reading File Paths from a text File

Posted: 2012-05-17T22:08:46-07:00
by anthony
Is that file in the current directory?

Re: Reading File Paths from a text File

Posted: 2012-05-18T15:39:30-07:00
by rohitkrishna
anthony wrote:Is that file in the current directory?
NO they are in differnet directory...i mentioned paths of images in the text file..