Click here to Skip to main content
15,867,453 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
Questionmeaing of below code Pin
Member 139765087-Sep-18 22:01
Member 139765087-Sep-18 22:01 
AnswerRe: meaing of below code Pin
Richard MacCutchan7-Sep-18 22:32
mveRichard MacCutchan7-Sep-18 22:32 
AnswerRe: meaing of below code Pin
Victor Nijegorodov8-Sep-18 1:07
Victor Nijegorodov8-Sep-18 1:07 
Questionc++ sms send dll Pin
Member 139765087-Sep-18 1:07
Member 139765087-Sep-18 1:07 
AnswerRe: c++ sms send dll Pin
Richard MacCutchan7-Sep-18 2:38
mveRichard MacCutchan7-Sep-18 2:38 
AnswerRe: c++ sms send dll Pin
Victor Nijegorodov8-Sep-18 1:04
Victor Nijegorodov8-Sep-18 1:04 
AnswerRe: c++ sms send dll Pin
vidhya 360 com14-Oct-18 20:38
vidhya 360 com14-Oct-18 20:38 
QuestionSharpen filter of bmp image Pin
Jakub Bartczak27-Aug-18 21:21
Jakub Bartczak27-Aug-18 21:21 
need some help with my code, I tried in many ways to make simple filtering image with array 3x3, but cant make it. any ideas how shall I start it?

C++
<pre>#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <cmath>

using namespace std;

//BMP header
typedef struct tagBITMAPFILEHEADER {  
	unsigned short      bfType;                 
	unsigned int        bfSize;                 
	short               bfReserved1;            
	short               bfReserved2;            
	unsigned int        bfOffBits;              
} BITMAPFILEHEADER;
//BMP header
typedef struct tagBITMAPINFOHEADER {  
	unsigned int        biSize;                 
	int                 biWidth;                
	int                 biHeight;               
	unsigned short      biPlanes;               
	unsigned short      biBitCount;             
	unsigned int        biCompression;          
	unsigned int        biSizeImage;            
	int                 biXpelsPerMeter;        
	int                 biYpelsPerMeter;        
	unsigned int        biClrUses;              
	unsigned int        biClrImportant;         
} BITMAPINFOHEADER;  


int odczytajBFH(ifstream &ifs, BITMAPFILEHEADER &bfh);
int odczytajBIH(ifstream &ifs, BITMAPINFOHEADER &bih, int kursor);
void zapiszBFH(ofstream &ofs, BITMAPFILEHEADER &bfh);
void zapiszBIH(ofstream &ofs, BITMAPINFOHEADER &bih);

unsigned char* odczytajDaneObrazu(ifstream &ifs, unsigned int rozmiar, int kursor);
void odczytajRGB(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc);
unsigned char * polaczRGB(int **niebieski, int **zielony, int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc);
void zwolnij_pamiec(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, int wysokosc);
void zapiszDaneObrazu(ofstream &ofs, unsigned char *obraz, unsigned int rozmiar);



int main()
{	 	        
 BITMAPFILEHEADER bfh;
 BITMAPINFOHEADER bih;
 string str = "bitmap.bmp";
 const char * nazwa_pliku = str.c_str();
 ifstream ifs(nazwa_pliku, ios::binary) ;
	if( !ifs.is_open() )
	{
        cout << "\nBlad otwarcia pliku";
        return 0;
	}
  ofstream ofs("out.bmp", ios::binary);	
	
 int kursor = odczytajBFH(ifs, bfh);
 kursor = odczytajBIH(ifs, bih, kursor);
 zapiszBFH(ofs, bfh);
 zapiszBIH(ofs, bih);
 unsigned int rozmiar = bfh.bfSize - bfh.bfOffBits;
 int szerokosc = bih.biWidth;
 int wysokosc = bih.biHeight;
 
 unsigned char* obraz = odczytajDaneObrazu(ifs, rozmiar, kursor);
 
 // zarezerwuj miejsce w pamieci dla tablicy przechowujacej wskaźniki do wierszy ze składową B pikseli
 // i zapisz wskaźnik do niego w zmiennej niebieski
 int **niebieski = new int*[wysokosc];	
 // zarezerwuj miejsce w pamieci dla tablicy przechowujacej wskaźniki do wierszy ze składową G pikseli
 // i zapisz wskaźnik do niego w zmiennej zielony
  int **zielony = new int*[wysokosc];
 // zarezerwuj miejsce w pamieci dla tablicy przechowujacej wskaźniki do wierszy ze składową R pikseli
 // i zapisz wskaźnik do niego w zmiennej czerwony
  int **czerwony = new int*[wysokosc];
 
 // dla każdego wiersza obrazka zarezerwuj miejsce w pamięci i zapisz wskaźnik do niego w tablicy
 // powtórz dla każdej składowej RGB
 for (int i = 0; i < wysokosc; i++ )
 {
    niebieski[i] = new int [szerokosc];
    zielony[i] = new int [szerokosc];
    czerwony[i] = new int [szerokosc];
 }

 odczytajRGB(obraz, niebieski, zielony, czerwony, rozmiar, szerokosc, wysokosc );
 
 
 cout << "bfh.bfType: "<<bfh.bfType <<endl;
 cout << "bfh.bfSize: "<< bfh.bfSize <<endl;
 cout << "bfh.bfReserved1 "<<bfh.bfReserved1 <<endl;
 cout << "bfh.bfReserved1 "<<bfh.bfReserved2 <<endl;
 cout << "bfh.bfOffBits: "<<bfh.bfOffBits <<endl;
 cout<<endl; 

 cout << "bih.biSize: "<<bih.biSize <<endl;
 cout << "bih.biWidth: "<<bih.biWidth <<endl;
 cout << "bih.biHeight: "<<bih.biHeight <<endl;
 cout << "bih.biPlanes: " <<bih.biPlanes <<endl;
 cout << "bih.biBitCount: " <<bih.biBitCount <<endl;
 cout << "bih.biCompression: "<<bih.biCompression <<endl;
 cout << "bih.biSizeImage: "<< bih.biSizeImage <<endl;


unsigned char * obraz2 = polaczRGB(niebieski, zielony, czerwony, rozmiar, szerokosc, wysokosc);
zapiszDaneObrazu(ofs, obraz2, rozmiar);
zwolnij_pamiec(obraz, niebieski, zielony, czerwony, wysokosc );

	ifs.close();
	system("pause");
	return 0;
}
	
/* Funkcja odczytuje nagłówek pliku BMP ze strumienia ifstream,
   zapisuje informację w polach struktury BITMAPFILEHEADER 
   i zwraca bieżącą pozycję kursora w strumieniu */
int odczytajBFH(ifstream &ifs, BITMAPFILEHEADER &bfh)
{
 	ifs.read(reinterpret_cast<char *>(& bfh.bfType), 2); 
 	ifs.read(reinterpret_cast<char *>(& bfh.bfSize), 4); 
 	ifs.read(reinterpret_cast<char *>(& bfh.bfReserved1), 2); 
 	ifs.read(reinterpret_cast<char *>(& bfh.bfReserved2), 2); 
 	ifs.read(reinterpret_cast<char *>(& bfh.bfOffBits), 4); 
 	return ifs.tellg(); 	
}
void zapiszBFH(ofstream &ofs, BITMAPFILEHEADER &bfh)
{
 	ofs.write(reinterpret_cast<char *>(& bfh.bfType), 2); 
 	ofs.write(reinterpret_cast<char *>(& bfh.bfSize), 4); 
 	ofs.write(reinterpret_cast<char *>(& bfh.bfReserved1), 2); 
 	ofs.write(reinterpret_cast<char *>(& bfh.bfReserved2), 2); 
 	ofs.write(reinterpret_cast<char *>(& bfh.bfOffBits), 4); 
}
int odczytajBIH(ifstream &ifs, BITMAPINFOHEADER &bih, int kursor)
{

	ifs.seekg(kursor, ios::beg);
 	ifs.read(reinterpret_cast<char *>(& bih.biSize), 4); 
 	ifs.read(reinterpret_cast<char *>(& bih.biWidth), 4); 
 	ifs.read(reinterpret_cast<char *>(& bih.biHeight), 4); 
 	ifs.read(reinterpret_cast<char *>(& bih.biPlanes), 2); 
 	ifs.read(reinterpret_cast<char *>(& bih.biBitCount), 2); 
 	ifs.read(reinterpret_cast<char *>(& bih.biCompression), 4); 
 	ifs.read(reinterpret_cast<char *>(& bih.biSizeImage), 4); 
 	ifs.read(reinterpret_cast<char *>(& bih.biXpelsPerMeter), 4); 
 	ifs.read(reinterpret_cast<char *>(& bih.biYpelsPerMeter), 4); 
 	ifs.read(reinterpret_cast<char *>(& bih.biClrUses), 4); 
 	ifs.read(reinterpret_cast<char *>(& bih.biClrImportant), 4); 
 	
 	kursor = ifs.tellg();
 	
	return kursor;
}
void zapiszBIH(ofstream &ofs, BITMAPINFOHEADER &bih)
{
	ofs.write(reinterpret_cast<char *>(& bih.biSize), 4); 
 	ofs.write(reinterpret_cast<char *>(& bih.biWidth), 4); 
 	ofs.write(reinterpret_cast<char *>(& bih.biHeight), 4); 
 	ofs.write(reinterpret_cast<char *>(& bih.biPlanes), 2); 
 	ofs.write(reinterpret_cast<char *>(& bih.biBitCount), 2); 
 	ofs.write(reinterpret_cast<char *>(& bih.biCompression), 4); 
 	ofs.write(reinterpret_cast<char *>(& bih.biSizeImage), 4); 
 	ofs.write(reinterpret_cast<char *>(& bih.biXpelsPerMeter), 4); 
 	ofs.write(reinterpret_cast<char *>(& bih.biYpelsPerMeter), 4); 
 	ofs.write(reinterpret_cast<char *>(& bih.biClrUses), 4); 
 	ofs.write(reinterpret_cast<char *>(& bih.biClrImportant), 4); 
 	
}

/* Funkcja przepisuje, począwszy od pozycji kursor,
   kolejne bajty ze strumienia ifstream do pamięci 
   i zwraca wskaźnik do zapisanych danych          */

unsigned char* odczytajDaneObrazu(ifstream &ifs, unsigned int rozmiar, int kursor)
{
	// to nie jest bezwzględnie konieczne, ale eleganckie
	ifs.seekg(kursor, ios::beg);
	unsigned char *obraz = new unsigned char[rozmiar];
	ifs.read(reinterpret_cast<char*>(obraz), rozmiar);	
	return obraz;	
}
void zapiszDaneObrazu(ofstream &ofs, unsigned char *obraz, unsigned int rozmiar)
{
	ofs.write(reinterpret_cast<char*>(obraz), rozmiar);	
	
}

void odczytajRGB(unsigned char *obraz, int **niebieski, int **zielony, 
     int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc)
{
	int zerowe_bajty = rozmiar/wysokosc - 3*szerokosc;
	int k = 0;
    for (int i = 0; i < wysokosc; i++)
		{for (int j = 0; j < szerokosc; j++)
		{
             niebieski[i][j]=obraz[k++];
             zielony[i][j]=obraz[k++];
             czerwony[i][j]=obraz[k++];
	
		}
	
		k+=zerowe_bajty;	
	}		
}

unsigned char *polaczRGB(int **niebieski, int **zielony, int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc)
{
	int zerowe_bajty = rozmiar/wysokosc - 3*szerokosc;
	unsigned char * obraz = new unsigned char [rozmiar];
	for (int k = 0; k < rozmiar; k++)
		obraz[k] = 0;
	int k = 0;
    for (int i = 0; i < wysokosc; i++)
		{for (int j = 0; j < szerokosc; j++)
		{
             obraz[k++]=niebieski[i][j];
             obraz[k++]=zielony[i][j];
             obraz[k++] = czerwony[i][j];
		}
		
		k+=zerowe_bajty;	
	}
	return obraz;		
}

void zwolnij_pamiec(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, int wysokosc)
{
     for(int i = 0; i < wysokosc; i++)
     { 
       delete [] niebieski[i];
       niebieski[i] = NULL;
       delete [] zielony[i];
       zielony[i] = NULL;
       delete [] czerwony[i];
       czerwony[i] = NULL;
     }
     delete [] niebieski;
     niebieski = NULL;
     delete [] zielony;
     zielony = NULL;
     delete [] czerwony;
     czerwony = NULL;
     delete [] obraz;
     obraz = NULL;
}     

AnswerRe: Sharpen filter of bmp image Pin
Jochen Arndt27-Aug-18 22:56
professionalJochen Arndt27-Aug-18 22:56 
Questionplease explain this lines of code Pin
Hiếu Ngô2-Aug-18 18:18
Hiếu Ngô2-Aug-18 18:18 
AnswerRe: please explain this lines of code Pin
Richard MacCutchan2-Aug-18 21:47
mveRichard MacCutchan2-Aug-18 21:47 
AnswerRe: please explain this lines of code Pin
Jochen Arndt2-Aug-18 22:29
professionalJochen Arndt2-Aug-18 22:29 
NewsC++/CLI support comes to ReSharper C++ Pin
John Schroedl23-Jul-18 6:22
professionalJohn Schroedl23-Jul-18 6:22 
QuestionTo find the angle of turn in a car racing game in C++/SFML Pin
Tarun Jha21-Jul-18 23:39
Tarun Jha21-Jul-18 23:39 
AnswerRe: To find the angle of turn in a car racing game in C++/SFML Pin
John Schroedl23-Jul-18 6:41
professionalJohn Schroedl23-Jul-18 6:41 
GeneralRe: To find the angle of turn in a car racing game in C++/SFML Pin
Tarun Jha25-Jul-18 7:36
Tarun Jha25-Jul-18 7:36 
QuestionSmall RAII-like cleanup class in C++/CLI Pin
John Schroedl15-Jun-18 9:08
professionalJohn Schroedl15-Jun-18 9:08 
QuestionInformation Edit Source code for c++ Pin
Member 1165875229-May-18 19:48
Member 1165875229-May-18 19:48 
AnswerRe: Information Edit Source code for c++ Pin
Richard MacCutchan29-May-18 21:05
mveRichard MacCutchan29-May-18 21:05 
AnswerRe: Information Edit Source code for c++ Pin
Jochen Arndt30-May-18 2:55
professionalJochen Arndt30-May-18 2:55 
QuestionError On a Project I'm Working On. (Sorry If Not descriptive enough, 1st time) Pin
CyberFaggot9-May-18 15:53
CyberFaggot9-May-18 15:53 
AnswerRe: Error On a Project I'm Working On. (Sorry If Not descriptive enough, 1st time) Pin
Richard MacCutchan11-May-18 21:19
mveRichard MacCutchan11-May-18 21:19 
QuestionPrint causes in afxtls.cpp Pin
Erich Ruth19-Apr-18 5:37
Erich Ruth19-Apr-18 5:37 
AnswerRe: Print causes in afxtls.cpp Pin
Richard Andrew x6413-May-18 7:22
professionalRichard Andrew x6413-May-18 7:22 
QuestionWhat is the alternative of _kbhit_ in linux ? Pin
Tarun Jha16-Apr-18 4:04
Tarun Jha16-Apr-18 4:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.