線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1438
推到 Plurk!
推到 Facebook!

關於浮水印的問題

尚未結案
yuck
一般會員


發表:7
回覆:3
積分:2
註冊:2008-11-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-01-05 10:20:25 IP:140.117.xxx.xxx 訂閱
在參考包子版大的程式後
包子版大是將字嵌入程式中
我想改寫為嵌入圖片進去
但後來我看嵌入浮水印圖片的bitplane 發現嵌入圖片的那個bit為全黑 並不是嵌入的圖片
所以想問板大這是什麼問題


改寫的程式如下

[code cpp]
void __fastcall TForm10::Button1Click(TObject *Sender) //圖像分離
{
int i=0, j=0, k=0;
TColor Color;
BYTE bRGB;

for(i=7; i>=0; i--)
{
Graphics::TBitmap *bmp=new Graphics::TBitmap;
bmp->Width=ImageSrc->Width;
bmp->Height=ImageSrc->Height;

bmp->PixelFormat=pf24bit;
bmp->Canvas->Brush->Color=clWhite;
bmp->Canvas->FillRect(Rect(0, 0, bmp->Width, bmp->Height));

for(j=0; jWidth; j )
{
for(k=0; kHeight; k )
{
Color=ImageSrc->Canvas->Pixels[j][k];
bRGB=GetRValue(Color);
// bRGB=GetGValue(Color);
// bRGB=GetBValue(Color);
bmp->Canvas->Pixels[j][k]=((bRGB>>i) & 0x01)? clWhite: clBlack;
Application->ProcessMessages();
}
}
// bmp->SaveToFile("bmp" IntToStr(i) ".bmp");

switch(i)
{
case 7:
Image7->Picture->Bitmap->Assign(bmp);
break;
case 6:
Image6->Picture->Bitmap->Assign(bmp);
break;
case 5:
Image5->Picture->Bitmap->Assign(bmp);
break;
case 4:
Image4->Picture->Bitmap->Assign(bmp);
break;
case 3:
Image3->Picture->Bitmap->Assign(bmp);
break;
case 2:
Image2->Picture->Bitmap->Assign(bmp);
break;
case 1:
Image1->Picture->Bitmap->Assign(bmp);
break;
case 0:
Image0->Picture->Bitmap->Assign(bmp);
break;
}
delete bmp;
Application->ProcessMessages();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm10::FormCreate(TObject *Sender)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm10::Button4Click(TObject *Sender) //載入圖片
{
Graphics::TBitmap *TheBitmap,*TempBitmap;
TheBitmap=Form1->Image1->Picture->Bitmap;
//ImageSrc->Height = Form1->Image1->Height;
//ImageSrc->Width = Form1->Image1->Width;
//ImageSrc->ClientHeight = Form1->Image1->Height;
//ImageSrc->ClientWidth = Form1->Image1->Width;
ImageSrc->Picture->Assign(TheBitmap);
int H = ImageSrc->Picture->Bitmap->Height;
int W = ImageSrc->Picture->Bitmap->Width;
ImageSrc->Height = H;
ImageSrc->Width = W;
ImageSrc->ClientHeight = ImageSrc->Height;
ImageSrc->ClientWidth = ImageSrc->Width;
int z;
Rcolor = new unsigned char*[H];
for(z=0; z Rcolor[z] = new char[W];
Gcolor = new unsigned char*[H];
for(z=0; z Gcolor[z] = new char[W];
Bcolor = new unsigned char*[H];
for(z=0; z Bcolor[z] = new char[W];
for(int i=0; i {
for(int j=0; j {
Rcolor[i][j]=GetRValue(ImageSrc->Canvas->Pixels[j][i]);
Gcolor[i][j]=GetGValue(ImageSrc->Canvas->Pixels[j][i]);
Bcolor[i][j]=GetBValue(ImageSrc->Canvas->Pixels[j][i]);
}
}
}
//---------------------------------------------------------------------------

void __fastcall TForm10::Button2Click(TObject *Sender) //加入浮水印
{
if (Form1->OpenPictureDialog1->Execute())
{
Image0->Picture->LoadFromFile(Form1->OpenPictureDialog1->FileName);
}

}
//---------------------------------------------------------------------------

void __fastcall TForm10::Button3Click(TObject *Sender) //組合
{
int i=0, j=0;
BYTE Bit7, Bit6, Bit5, Bit4, Bit3, Bit2, Bit1, Bit0;
BYTE bRGB=0;
TColor Color;
Graphics::TBitmap *bmp=new Graphics::TBitmap;
bmp->Width=ImageDst->Width;
bmp->Height=ImageDst->Height;
bmp->PixelFormat=pf24bit;
for(i=0; iWidth; i )
{
for(j=0; jHeight; j )
{
Color=ImageSrc->Canvas->Pixels[i][j];
Bit7=(Image7->Canvas->Pixels[i][j]==clWhite)? 0x80: 0;
Bit6=(Image6->Canvas->Pixels[i][j]==clWhite)? 0x40: 0;
Bit5=(Image5->Canvas->Pixels[i][j]==clWhite)? 0x20: 0;
Bit4=(Image4->Canvas->Pixels[i][j]==clWhite)? 0x10: 0;
Bit3=(Image3->Canvas->Pixels[i][j]==clWhite)? 0x08: 0;
Bit2=(Image2->Canvas->Pixels[i][j]==clWhite)? 0x04: 0;
Bit1=(Image1->Canvas->Pixels[i][j]==clWhite)? 0x02: 0;
Bit0=(Image0->Canvas->Pixels[i][j]==clWhite)? 0x01: 0;
bRGB=Bit7 | Bit6 | Bit5 | Bit4 | Bit3 | Bit2 | Bit1 | Bit0;
bmp->Canvas->Pixels[i][j]=(TColor)RGB(bRGB, GetGValue(Color), GetBValue(Color));
// bmp->Canvas->Pixels[i][j]=(TColor)RGB(GetRValue(Color), bRGB, GetBValue(Color));
// bmp->Canvas->Pixels[i][j]=(TColor)RGB(GetRValue(Color), GetGValue(Color), bRGB);
Application->ProcessMessages();
}
}
ImageDst->Picture->Bitmap->Assign(bmp);
delete bmp;
int H = ImageDst->Picture->Bitmap->Height;
int W = ImageDst->Picture->Bitmap->Width;
ImageDst->Height = H;
ImageDst->Width = W;
ImageDst->ClientHeight = ImageDst->Height;
ImageDst->ClientWidth = ImageDst->Width;
int z;
Rcolor3 = new unsigned char*[H];
for(z=0; z Rcolor3[z] = new char[W];
Gcolor3 = new unsigned char*[H];
for(z=0; z Gcolor3[z] = new char[W];
Bcolor3 = new unsigned char*[H];
for(z=0; z Bcolor3[z] = new char[W];
for(int i=0; i {
for(int j=0; j {
Rcolor3[i][j]=GetRValue(ImageDst->Canvas->Pixels[j][i]);
Gcolor3[i][j]=GetGValue(ImageDst->Canvas->Pixels[j][i]);
Bcolor3[i][j]=GetBValue(ImageDst->Canvas->Pixels[j][i]);
}
}

}
//---------------------------------------------------------------------------
void __fastcall TForm10::Button5Click(TObject *Sender) //將更改後圖片傳至Form1
{
Graphics::TBitmap *TheBitmap,*TempBitmap;
TheBitmap=ImageDst->Picture->Bitmap;
ImageSrc->Height = Form1->Image1->Height;
ImageSrc->Width = Form1->Image1->Width;
//ImageSrc->ClientHeight = Form1->Image1->Height;
//ImageSrc->ClientWidth = Form1->Image1->Width;
Form1->Image2->Picture->Assign(TheBitmap);
}
//---------------------------------------------------------------------------
void __fastcall TForm10::Button6Click(TObject *Sender) //清除
{
// ImageDst->Canvas->Brush->Color=clWhite;
ImageDst->Canvas->FillRect(Rect(0, 0, ImageDst->Width, ImageDst->Height));
// Image7->Canvas->Brush->Color=clWhite;
Image7->Canvas->FillRect(Rect(0, 0, Image7->Width, Image7->Height));
//Image6->Canvas->Brush->Color=clWhite;
Image6->Canvas->FillRect(Rect(0, 0, Image6->Width, Image6->Height));
//Image5->Canvas->Brush->Color=clWhite;
Image5->Canvas->FillRect(Rect(0, 0, Image5->Width, Image5->Height));
//Image4->Canvas->Brush->Color=clWhite;
Image4->Canvas->FillRect(Rect(0, 0, Image4->Width, Image4->Height));
//Image3->Canvas->Brush->Color=clWhite;
Image3->Canvas->FillRect(Rect(0, 0, Image3->Width, Image3->Height));
//Image2->Canvas->Brush->Color=clWhite;
Image2->Canvas->FillRect(Rect(0, 0, Image2->Width, Image2->Height));
//Image1->Canvas->Brush->Color=clWhite;
Image1->Canvas->FillRect(Rect(0, 0, Image1->Width, Image1->Height));
//Image0->Canvas->Brush->Color=clWhite;
Image0->Canvas->FillRect(Rect(0, 0, Image0->Width, Image0->Height));
}
//---------------------------------------------------------------------------

void __fastcall TForm10::Button7Click(TObject *Sender) //SNR
{
if(ImageSrc->Height != ImageDst->Height ||ImageSrc->Width != ImageDst->Width )
{
int message=Application->MessageBox("Two Images sizes must be the same","Error",16);
}
else
{
double snr=0;
double snro=0,snrf=0;
int h=(ImageSrc->Height);
int w=(ImageSrc->Width);
for (int i=0;i {
for(int j=0;j {
snro=snro pow(Rcolor[i][j],2) pow(Gcolor[i][j],2) pow(Bcolor[i][j],2);
snrf=snrf pow(Rcolor3[i][j]-Rcolor[i][j],2) pow(Gcolor3[i][j]-Gcolor[i][j],2) pow(Bcolor3[i][j]-Bcolor[i][j],2);
}
}
if(snrf==0)
{
int message=Application->MessageBox("Two Images are the smae","Image2 relative Image1");
}
else
{
snr=round(10*(log(snro/snrf)/log(10)),2);
AnsiString text="SNR: ";
text =snr;
text =" dB";
int message=Application->MessageBox(text.c_str(),"Image2 relative Image1");
}
}

}
//---------------------------------------------------------------------------
[/code]
編輯記錄
yuck 重新編輯於 2009-01-05 10:24:26, 註解 無‧
系統時間:2024-03-28 17:20:41
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!