参与“就命!! 如何使图片成为单色调的图片?”讨论的朋友请进!送分!

Friecin 2002-12-18 10:25:00
非常感谢给位,因为我几天上班后就要交公,在给位的提示下,最终搞定!!今天我特意研究了一下关于图像的编程,又在解决染色的基础上,又添加了一些其他图片处理效果,与大家分享!

thanks RomanticProgrammer(兰企鹅||南极俺最帅);
thanks invalid(空心菜之2.0开发中);
thanks beanbar(古枫)

当然,也非常感谢
weibz0525(小虫) and woainihaha(雁过无痕,注册好难)

//-------------------------------------------------------------------------------

我的代码如下:

.h文件声明:

//---------------------------------------------------------------------------

#ifndef FormPicEditH
#define FormPicEditH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <ComCtrls.hpp>
#include <Graphics.hpp>
#include <Dialogs.hpp>
#include <ExtDlgs.hpp>
#include <Buttons.hpp>
//---------------------------------------------------------------------------
class TfrmPicEdit : public TForm
{
__published: // IDE-managed Components
TPanel *Panel1;
TImage *Image1;
TTrackBar *TrackBar1;
TOpenPictureDialog *OpenPictureDialog1;
TLabel *Label1;
TTrackBar *TrackBar2;
TTrackBar *TrackBar3;
TLabel *Label2;
TLabel *Label3;
TBitBtn *BitBtn1;
TBitBtn *BitBtn2;
void __fastcall TrackBar1Change(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall BitBtn1Click(TObject *Sender);
void __fastcall BitBtn2Click(TObject *Sender);
private: // User declarations
void __fastcall AdjustBright(Graphics::TBitmap *Bmp, int delta);
public: // User declarations
__fastcall TfrmPicEdit(TComponent* Owner);
};

struct rgb_str{
unsigned char r_color;
unsigned char g_color;
unsigned char b_color;
};
//---------------------------------------------------------------------------
extern PACKAGE TfrmPicEdit *frmPicEdit;
//---------------------------------------------------------------------------
#endif


//---------------------------------------------------------------
//代码如下
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "FormPicEdit.h"
#include <algorithm.h>
#include <iostream.h>
#include <functional.h>
#include "Main.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TfrmPicEdit *frmPicEdit;
rgb_str rgb[2000][2000];
Graphics::TBitmap *bitmap;
int i,j,width,height;
//---------------------------------------------------------------------------
__fastcall TfrmPicEdit::TfrmPicEdit(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TfrmPicEdit::TrackBar1Change(TObject *Sender)
{
int red,green,blue;
for(i=0;i< width-2;i++)
for(j=0;j< height-2;j++)
{
red=abs(rgb[i][j].r_color+TrackBar1->Position);
green=abs(rgb[i][j].g_color+TrackBar2->Position);
blue=abs(rgb[i][j].b_color+TrackBar3->Position);
bitmap->Canvas->Pixels[i][j]=TColor(RGB(red,green,blue));
}
Image1->Picture->Bitmap->Assign(bitmap);

}
//---------------------------------------------------------------------------
//存放变换后的位图
void __fastcall TfrmPicEdit::FormCreate(TObject *Sender)
{
Image1->Picture=frmMain->CurrSelDBImage->Picture;
TColor color;
width=Image1->Picture->Width;
height=Image1->Picture->Height;
for(i=0;i< width-1;i++)
for(j=0;j< height-1;j++)
{
color=Image1->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);
}
bitmap=new Graphics::TBitmap;
bitmap->Width=width;
bitmap->Height=height;
}

//--------------------------------------------------------------------------------------

//图像的柔化处理


void __fastcall TfrmPicEdit::btnSmoothClick(TObject *Sender)
{
int red,green,blue;
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][j1].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;
bitmap- >Canvas- >Pixels[i][j]=RGB(red/9,green/9,blue/9);
}
Image1- >Picture- >Bitmap- >Assign(bitmap);
}

//---------------------------------------------------------------------------
//图像的锐化处理
void __fastcall TfrmPicEdit::btnSharpeClick(TObject *Sender)
{
float degree=0.3;
int red,green,blue;
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));
bitmap- >Canvas->Pixels[i][j]=RGB(red,green,blue);
}
Image1- >Picture- >Bitmap- >Assign(bitmap);


//-----------------------------------------------------------------------------------------

void __fastcall TForm1::btnEmbossClick(TObject *Sender)
{
int red,green,blue;
const int const_value=128;
for(i=0;i< width-2;i++)
for(j=0;j< height-2;j++){
red=abs(rgb[i][j].r_color-rgb[i+1][j+1].r_color+const_value);
green=abs(rgb[i][j].g_color-rgb[i+1][j+1].g_color+const_value);
blue=abs(rgb[i][j].b_color-rgb[i+1][j+1].b_color+const_value);
bitmap- >Canvas- >Pixels[i][j]=RGB(red,green,blue);
}
Image1- >Picture- >Bitmap- >Assign(bitmap);
}


//------------------------------------------------------------------------
在此谢谢大家!!



...全文
38 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
beanbar 2002-12-19
  • 打赏
  • 举报
回复
我这有本vc的高级图像编程
谁想要找我 qq 13647949
CCLIS 2002-12-19
  • 打赏
  • 举报
回复
谢谢啊,收藏。

收分。
windcsn 2002-12-19
  • 打赏
  • 举报
回复
哈哈,学习,收藏
weibz0525 2002-12-19
  • 打赏
  • 举报
回复
呵呵,楼主,客气客气,最近工作需要多研究点图象编程的东西,大家共同提高吧!不过还是不明白楼主要的单色调是什么意思?
jbz 2002-12-19
  • 打赏
  • 举报
回复
收藏。
zliang2000 2002-12-18
  • 打赏
  • 举报
回复
需要详细解释啊!!!!
binbin 2002-12-18
  • 打赏
  • 举报
回复
俺也小参与了一吧,呵呵,骗点分吧.
trancebaby 2002-12-18
  • 打赏
  • 举报
回复
柔化锐化和单色调有什么关系阿。。。
GaoLun 2002-12-18
  • 打赏
  • 举报
回复
同志们辛苦了……















倒 怎么没有人说 为人民服务 呢!
还是我说吧 我自己为人们服务

我收藏先……
invalid 2002-12-18
  • 打赏
  • 举报
回复
我代表大家来了:-)
他们做题辛苦了,先休息了!



收藏!

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧