C
C#7mo ago
Dinny

Adding red, green, and blue pixels into a list after being red form the input file

using System;
using System.IO;
using System.Collections.Generic;

namespace Module_12
{

public class Program
{
static void Main(string[] args)
{
// Open the input and output file.
FileStream inputFile = new("ScrambledFlag.ppm", FileMode.Open, FileAccess.Read);
StreamReader reader = new(inputFile);
FileStream outputFile = new("UnscrambledFlag.ppm", FileMode.Create, FileAccess.Write);
StreamWriter writer = new(outputFile);

//read header of input file
while (!reader.EndOfStream)
{

string? nextLine = reader.ReadLine();

if ( nextLine != null )
{
string[] nextItem = nextLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (nextItem.Length == 0) { continue; }

//reading header and converting to int
string? p = reader.ReadLine();
int x = Convert.ToInt32(nextItem[0]);
int y = Convert.ToInt32(nextItem[1]);
int z = Convert.ToInt32(reader.ReadLine());

List<Pixel> pixels = new List<Pixel>(x * y);

for (int i = 0; i < pixels.Count; i++)
{
int first;
int second;
int third;


pixels.Add();
}



//writing header to output file
//write header to output file
writer.WriteLine(p);
}
}

}
}
}
using System;
using System.IO;
using System.Collections.Generic;

namespace Module_12
{

public class Program
{
static void Main(string[] args)
{
// Open the input and output file.
FileStream inputFile = new("ScrambledFlag.ppm", FileMode.Open, FileAccess.Read);
StreamReader reader = new(inputFile);
FileStream outputFile = new("UnscrambledFlag.ppm", FileMode.Create, FileAccess.Write);
StreamWriter writer = new(outputFile);

//read header of input file
while (!reader.EndOfStream)
{

string? nextLine = reader.ReadLine();

if ( nextLine != null )
{
string[] nextItem = nextLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (nextItem.Length == 0) { continue; }

//reading header and converting to int
string? p = reader.ReadLine();
int x = Convert.ToInt32(nextItem[0]);
int y = Convert.ToInt32(nextItem[1]);
int z = Convert.ToInt32(reader.ReadLine());

List<Pixel> pixels = new List<Pixel>(x * y);

for (int i = 0; i < pixels.Count; i++)
{
int first;
int second;
int third;


pixels.Add();
}



//writing header to output file
//write header to output file
writer.WriteLine(p);
}
}

}
}
}
3 Replies
Dinny
Dinny7mo ago
my issue lies at the for loop
Kao
Kao7mo ago
Well you need to tell a bit more about the issues you have Do you have an error? Is the behaviour different from your expectations? If yes tell us about both. Etc
Dinny
Dinny7mo ago
there is no error, but i am unsure how to proceed. mt ptof states that we must "Create a list of pixels (type List<Pixel>) to store the pixels read from the input file" and "Using the constructor in the Pixel class, read in all the pixels from the input image and add them into the list." my prof** my idea was to create three different variable to store the red, green, and blue pixels (the input file is a list of numbers, but i must take three at a time to get a pixel color to put in the poutput file) in the input file, the first three numbers equal to a color btw (either red, gree, or blue"