KOD cpp: UKRYJ
void __fastcall TMainForm::BitBtn1Click(TObject *Sender)
{
if(OpenPictureDialog1->Execute())
{
Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);
try
{
BMP->LoadFromFile(OpenPictureDialog1->FileName);
BMP->PixelFormat = pf32bit;
}
catch(...)
{
TJPEGImage *jpg = new TJPEGImage();
jpg->LoadFromFile(OpenPictureDialog1->FileName);
BMP->Width = jpg->Width;
BMP->Height = jpg->Height;
BMP->Canvas->Draw(0, 0, jpg);
BMP->PixelFormat = pf32bit;
jpg->Free();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnShowFormatkiNumerDwa(TObject *Sender) {
Form2->Image->Picture->Assign(Image1->Picture);
Form2->Image2->Picture->Assign(Image1->Picture);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
DoubleBuffered = true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::BitBtn3Click(TObject *Sender)
{
Form2->Image->Picture->Assign(Image1->Picture);
Form2->Image2->Picture->Assign(Image1->Picture);
Form2->ShowModal();
}
//---------------------------------------------------------------------------
{
if(OpenPictureDialog1->Execute())
{
Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);
try
{
BMP->LoadFromFile(OpenPictureDialog1->FileName);
BMP->PixelFormat = pf32bit;
}
catch(...)
{
TJPEGImage *jpg = new TJPEGImage();
jpg->LoadFromFile(OpenPictureDialog1->FileName);
BMP->Width = jpg->Width;
BMP->Height = jpg->Height;
BMP->Canvas->Draw(0, 0, jpg);
BMP->PixelFormat = pf32bit;
jpg->Free();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnShowFormatkiNumerDwa(TObject *Sender) {
Form2->Image->Picture->Assign(Image1->Picture);
Form2->Image2->Picture->Assign(Image1->Picture);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
DoubleBuffered = true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::BitBtn3Click(TObject *Sender)
{
Form2->Image->Picture->Assign(Image1->Picture);
Form2->Image2->Picture->Assign(Image1->Picture);
Form2->ShowModal();
}
//---------------------------------------------------------------------------
być może nie kopiuje mi czegoś z formy1 image do formy2 image2?
w formie2 umieściłem:
KOD cpp: UKRYJ
// Plik źródłowy np. Unit2.cpp
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
BMP = new Graphics::TBitmap();
}
//---------------------------------------------------------------------------
void __fastcall Brightness(Graphics::TBitmap *BMP, int x)
{
for(int i = 0; i < BMP->Height; i++)
{
RGBQUAD *row = (RGBQUAD *) BMP->ScanLine[i];
for(int j = 0; j < BMP->Width; j++)
{
int b = row[j].rgbBlue;
int g = row[j].rgbGreen;
int r = row[j].rgbRed;
r += x;
g += x;
b += x;
b = (b > 255) ?255: (b < 0) ?0:b;
g = (g > 255) ?255: (g < 0) ?0:g;
r = (r > 255) ?255: (r < 0) ?0:r;
row[j].rgbBlue = (BYTE) b;
row[j].rgbGreen = (BYTE) g;
row[j].rgbRed = (BYTE) r;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::TrackBar1Change(TObject *Sender)
{
TMemoryStream *Ms = new TMemoryStream;
Ms->Position = 0;
BMP->SaveToStream(Ms);
Ms->Position = 0;
Image2->Picture->Bitmap->LoadFromStream(Ms);
delete Ms;
Brightness(Image2->Picture->Bitmap, TrackBar1->Position);
}
//---------------------------------------------------------------------------
// Plik źródłowy np. Unit2.h
//---------------------------------------------------------------------------
private:
Graphics::TBitmap *BMP;
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
BMP = new Graphics::TBitmap();
}
//---------------------------------------------------------------------------
void __fastcall Brightness(Graphics::TBitmap *BMP, int x)
{
for(int i = 0; i < BMP->Height; i++)
{
RGBQUAD *row = (RGBQUAD *) BMP->ScanLine[i];
for(int j = 0; j < BMP->Width; j++)
{
int b = row[j].rgbBlue;
int g = row[j].rgbGreen;
int r = row[j].rgbRed;
r += x;
g += x;
b += x;
b = (b > 255) ?255: (b < 0) ?0:b;
g = (g > 255) ?255: (g < 0) ?0:g;
r = (r > 255) ?255: (r < 0) ?0:r;
row[j].rgbBlue = (BYTE) b;
row[j].rgbGreen = (BYTE) g;
row[j].rgbRed = (BYTE) r;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::TrackBar1Change(TObject *Sender)
{
TMemoryStream *Ms = new TMemoryStream;
Ms->Position = 0;
BMP->SaveToStream(Ms);
Ms->Position = 0;
Image2->Picture->Bitmap->LoadFromStream(Ms);
delete Ms;
Brightness(Image2->Picture->Bitmap, TrackBar1->Position);
}
//---------------------------------------------------------------------------
// Plik źródłowy np. Unit2.h
//---------------------------------------------------------------------------
private:
Graphics::TBitmap *BMP;
//---------------------------------------------------------------------------
Z góry dziękuje za pomoc.