Po wczytaniu pierwszym obraz pojawia się w okienku lecz nie działa rozmywanie, dopiero po drugim kliknięciu wczytania obrazu rozmycie zaczyna działać. Mógłbym prosić o pomoc wskazania w którym miejscu tkwi problem?
załączam kod cpp
KOD cpp: UKRYJ
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "rozmycie.h"
#include "paint.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CSPIN"
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TForm2::PokazPodglad()
{
BMP2-> Width = width;
BMP2-> Height = height;
width = Image1-> Picture-> Width;
height = Image1-> Picture-> Height;
BMP2->Width = xi;
BMP2->Height = yi;
for (i = 0; i <width-1; i++)
for (j = 0; j <height-1; j++)
{
Color = Image1->Picture->Bitmap->Canvas-> Pixels[i][j];
rgb [i][j].r_color = GetRValue(Color);
rgb [i][j].g_color = GetGValue(Color);
rgb [i][j].b_color = GetBValue(Color);
}
BMP2->Canvas->StretchDraw(Rect(0, 0, xi, yi), BMP1);
Image1->Picture->Bitmap->Assign(BMP2);
}
//---------------------------------------------------------------------------
int min (int value1, int value2){
if(value1>=value2)return value2;
else return value1;
}
int max (int value1,int value2)
{if (value1>=value2) return value1;
else return value2;}
//-----------------------------------------------------------------------------
void __fastcall TForm2::BitBtn1Click(TObject *Sender) //przycisk rozmyj
{
for (i = 1; i <width-2; i++)
{
for (j = 1; j <height-2; j++)
{
red =rgb[i-1][j-1].r_color + rgb [i][j-1].r_color + rgb [i+1][j-1]. r_color +
rgb[i-1][j].r_color+rgb[i][j].r_color+rgb[i+1][j].r_color+rgb[i-1][j+1].r_color +
rgb[i][j +1].r_color+rgb[i+1][j+1].r_color;
green=rgb[i-1][j-1].g_color+rgb[i][j-1].g_color+rgb[i+1][j-1].g_color+
rgb[i-1][j].g_color+rgb[i][j].g_color + rgb[i+1][j].g_color+
rgb[i-1][j+1].g_color+rgb[i][j+1].g_color+rgb[i+1][j+1].g_color;
blue=rgb[i-1][j-1].b_color + rgb[i][j-1].b_color+rgb[i +1][j-1].b_color+
rgb[i-1][j].b_color+rgb[i][j].b_color+rgb[i+1][j].b_color+
rgb[i-1][j+1].b_color+rgb[i][j+1].b_color+rgb[i+1][j+1].b_color;
BMP2->Canvas->Pixels[i][j]=(TColor)RGB(red/9,green/9,blue/9);
}
Image1-> Picture-> Bitmap-> Assign (BMP2);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::BitBtn2Click(TObject *Sender)
{
float degree = 0.3;
for (i = 1; i <width-1; i++){
for (j = 1; j <height-1; j++) {
red = rgb [i][j].r_color + degree *(rgb [i][j].r_color-rgb [i-1][j-1].r_color);
green = rgb [i][j].g_color + degree * (rgb [i][j].g_color-rgb [i-1][j-1].g_color);
blue = rgb [i][j].b_color + degree * (rgb [i][j].b_color-rgb [i-1][j-1].b_color);
red = min (255, max (0, red));
green = min (255, max (0, green));
blue = min (255, max (0, blue));
BMP2-> Canvas-> Pixels[i][j]= (TColor)RGB (red, green, blue);
}
Image1-> Picture-> Bitmap-> Assign (BMP2);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::BitBtn3Click(TObject *Sender)
{
Form1->Image->Picture->Assign(Image1->Picture);
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::BitBtn4Click(TObject *Sender)//przycisk wczytaj obraz
{
BMP1 = new Graphics::TBitmap();
BMP2 = new Graphics::TBitmap();
BMP1->Assign(Form1->Image->Picture->Bitmap);
xi = Form1->Image->Height;
yi = Form1->Image->Width;
PokazPodglad();
}
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "rozmycie.h"
#include "paint.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CSPIN"
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TForm2::PokazPodglad()
{
BMP2-> Width = width;
BMP2-> Height = height;
width = Image1-> Picture-> Width;
height = Image1-> Picture-> Height;
BMP2->Width = xi;
BMP2->Height = yi;
for (i = 0; i <width-1; i++)
for (j = 0; j <height-1; j++)
{
Color = Image1->Picture->Bitmap->Canvas-> Pixels[i][j];
rgb [i][j].r_color = GetRValue(Color);
rgb [i][j].g_color = GetGValue(Color);
rgb [i][j].b_color = GetBValue(Color);
}
BMP2->Canvas->StretchDraw(Rect(0, 0, xi, yi), BMP1);
Image1->Picture->Bitmap->Assign(BMP2);
}
//---------------------------------------------------------------------------
int min (int value1, int value2){
if(value1>=value2)return value2;
else return value1;
}
int max (int value1,int value2)
{if (value1>=value2) return value1;
else return value2;}
//-----------------------------------------------------------------------------
void __fastcall TForm2::BitBtn1Click(TObject *Sender) //przycisk rozmyj
{
for (i = 1; i <width-2; i++)
{
for (j = 1; j <height-2; j++)
{
red =rgb[i-1][j-1].r_color + rgb [i][j-1].r_color + rgb [i+1][j-1]. r_color +
rgb[i-1][j].r_color+rgb[i][j].r_color+rgb[i+1][j].r_color+rgb[i-1][j+1].r_color +
rgb[i][j +1].r_color+rgb[i+1][j+1].r_color;
green=rgb[i-1][j-1].g_color+rgb[i][j-1].g_color+rgb[i+1][j-1].g_color+
rgb[i-1][j].g_color+rgb[i][j].g_color + rgb[i+1][j].g_color+
rgb[i-1][j+1].g_color+rgb[i][j+1].g_color+rgb[i+1][j+1].g_color;
blue=rgb[i-1][j-1].b_color + rgb[i][j-1].b_color+rgb[i +1][j-1].b_color+
rgb[i-1][j].b_color+rgb[i][j].b_color+rgb[i+1][j].b_color+
rgb[i-1][j+1].b_color+rgb[i][j+1].b_color+rgb[i+1][j+1].b_color;
BMP2->Canvas->Pixels[i][j]=(TColor)RGB(red/9,green/9,blue/9);
}
Image1-> Picture-> Bitmap-> Assign (BMP2);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::BitBtn2Click(TObject *Sender)
{
float degree = 0.3;
for (i = 1; i <width-1; i++){
for (j = 1; j <height-1; j++) {
red = rgb [i][j].r_color + degree *(rgb [i][j].r_color-rgb [i-1][j-1].r_color);
green = rgb [i][j].g_color + degree * (rgb [i][j].g_color-rgb [i-1][j-1].g_color);
blue = rgb [i][j].b_color + degree * (rgb [i][j].b_color-rgb [i-1][j-1].b_color);
red = min (255, max (0, red));
green = min (255, max (0, green));
blue = min (255, max (0, blue));
BMP2-> Canvas-> Pixels[i][j]= (TColor)RGB (red, green, blue);
}
Image1-> Picture-> Bitmap-> Assign (BMP2);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::BitBtn3Click(TObject *Sender)
{
Form1->Image->Picture->Assign(Image1->Picture);
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::BitBtn4Click(TObject *Sender)//przycisk wczytaj obraz
{
BMP1 = new Graphics::TBitmap();
BMP2 = new Graphics::TBitmap();
BMP1->Assign(Form1->Image->Picture->Bitmap);
xi = Form1->Image->Height;
yi = Form1->Image->Width;
PokazPodglad();
}
//---------------------------------------------------------------------------
i plik nagłówkowy
KOD cpp: UKRYJ
private: // User declarations
Graphics::TBitmap *BMP1;
Graphics::TBitmap *BMP2;
void PokazPodglad();
public: // User declarations
__fastcall TForm2(TComponent* Owner);
Graphics:: TBitmap * bitmap;
int red, green, blue;
int xi,yi, i, j, width, height;
struct rgb_str {
unsigned char r_color;
unsigned char g_color;
unsigned char b_color;};
rgb_str rgb [2000][2000];
};
Graphics::TBitmap *BMP1;
Graphics::TBitmap *BMP2;
void PokazPodglad();
public: // User declarations
__fastcall TForm2(TComponent* Owner);
Graphics:: TBitmap * bitmap;
int red, green, blue;
int xi,yi, i, j, width, height;
struct rgb_str {
unsigned char r_color;
unsigned char g_color;
unsigned char b_color;};
rgb_str rgb [2000][2000];
};





