Δημοσιεύτηκε: 14 Οκτ 2012, 01:37
Έχω κάνει τον εξής κώδικα που φορτώνει μαι εικόνα σαν unsigned char ** από ένα αρχεί και την αντιγράφει σε ένα άλλο αρχείο
Χρησιμοποιεί και τον εξής header (Imageio.h)
Και τις εξής συναρτήσεις του header (imageio.h)
Θ'ελω τις τιμές πτου πίνακων τύπου unssigned char να τους προβάλλω στην οθόνη σε ένα παράθυρο αλλα πως?
Η εικόνα είναι grayscale.
Ψ'αχνω στο youtube δίχως κανένα αποτέλεσμα
- Κώδικας: Επιλογή όλων
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include<malloc.h>
#include"imageio.h"
// ---------------------------------------------------------------
// Usefull defines
// ---------------------------------------------------------------
#define INPUT_FILENAME "lenaGrey256.raw" // defining input filename
#define OUTPUT_FILENAME "lenaGrey256out.raw" // defining output filename
#define ROWS 256 // Picture height
#define COLUMNS 256 // Picture width
#define GREYLEVELS 256 // Graylevel sampling
#define OUTPUT_ROWS ROWS // Output height
#define OUTPUT_COLUMNS COLUMNS // Output width
int main(void)
{
unsigned char **inputImage, **outputImage;//table that will store the output image
FILE *inputFile,//Input
*outputFile;//Output file
/*
Usefull variables for the loops for storing and processing the image
*/
int i = 0,
j = 0;
//----------------------------------------
//Other variables
//----------------------------------------
//-------------------------------------------------
//Main Code
//-------------------------------------------------
inputImage=load_grayscale(INPUT_FILENAME,COLUMNS,ROWS);
outputImage=alocate_image(OUTPUT_ROWS,OUTPUT_COLUMNS);
if(inputImage==NULL || outputImage==NULL)
{
exit(-1);
}
// -----------------------------------------------------------
// Processing the Image
// -----------------------------------------------------------
for (i = 0; i < OUTPUT_ROWS; i++)
{
for (j = 0; j < OUTPUT_COLUMNS; j++)
{
outputImage[i][j] = inputImage[i][j];
}
}
store_grayscale(OUTPUT_FILENAME,outputImage,OUTPUT_ROWS,OUTPUT_COLUMNS);
}
Χρησιμοποιεί και τον εξής header (Imageio.h)
- Κώδικας: Επιλογή όλων
#ifndef IMAGEIO
#define IMAGEIO
#include<stdio.h>
#include<stdlib.h>
unsigned char ** load_grayscale(unsigned char path[], unsigned int height, unsigned int width);
int store_grayscale(unsigned char * path, unsigned char **outputImage, unsigned int height, unsigned int width);
unsigned char ** alocate_image(int width, int height);
#endif
Και τις εξής συναρτήσεις του header (imageio.h)
- Κώδικας: Επιλογή όλων
#include"imageio.h"
unsigned char ** load_grayscale(unsigned char path[], unsigned int height, unsigned int width)
{
FILE *inputFile;//Input
unsigned char **inputImage;
int i,j;
if ( ((inputFile = fopen(path,"rb")) != NULL))
{
inputImage = calloc(height,sizeof(unsigned char *));
if(inputImage==NULL)
{
return NULL;
}
for (i = 0; i < height; i++)
{
inputImage[i] = calloc(width, sizeof(unsigned char));
if(inputImage[i]==NULL)
{
free(inputImage);
return NULL;
}
for (j = 0; j < width; j++)
{
fscanf(inputFile, "%c", &inputImage[i][j]);
}
}
}
else
{
fprintf(stderr,"Error loading image.");
free(inputImage);
return NULL;
}
fclose(inputFile);
return inputImage;
}
int store_grayscale(unsigned char path[], unsigned char **outputImage, unsigned int height, unsigned int width)
{
FILE *outputFile;
int i,j;
if ( ((outputFile = fopen(path,"wb")) != NULL))
{
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
fprintf(outputFile, "%c",outputImage[i][j]);
}
}
}
else
{
fprintf(stderr,"Error saving image.");
return 0;
}
fclose(outputFile);
return 1;
}
unsigned char ** alocate_image(int height, int width)
{
int i;
unsigned char **image;
if((image=(unsigned char**)calloc(height,sizeof(unsigned char *)))==NULL)
{
return NULL;
}
for(i=0;i<height;i++)
{
if((image[i]=(unsigned char*)calloc(width,sizeof(unsigned char)))==NULL)
{
free(image);
return NULL;
}
}
return image;
}
Θ'ελω τις τιμές πτου πίνακων τύπου unssigned char να τους προβάλλω στην οθόνη σε ένα παράθυρο αλλα πως?
Η εικόνα είναι grayscale.
Ψ'αχνω στο youtube δίχως κανένα αποτέλεσμα