全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1128
推到 Plurk!
推到 Facebook!

請問從image1修改RGB資料後存到image2的問題

尚未結案
perking
一般會員


發表:9
回覆:5
積分:2
註冊:2004-10-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-08-05 00:02:39 IP:59.105.xxx.xxx 未訂閱
各位大哥:          小弟現在要從image1修改RGB資料後存到image2,下面是程式, 我的問題所在是,當我秀圖秀到image2的時候,都只有秀出1/3的範圍而已,還有就是要請教,為什麼我處理的圖都是bmp檔案,但是有些可以秀出1/3張修改後的圖,有些就沒辦法秀出來呢?? 下面是我的程式碼,希望大哥大姊們指導~~  
 
 //---------------------------------------------------------------------------    #include 
#pragma hdrstop
#include <math.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
void ShowImage( TImage *image, int W,int H,Byte *source );
//將影像顯示在TImage的物件內
void Compareyuv( Byte *,int w,int h);
Byte *BitsArray,*BitsArray1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Button1Click(TObject *Sender)
{
     Graphics::TBitmap *bmp=new Graphics::TBitmap();
     OpenPictureDialog1->Execute();
     Form1->PageControl1->ActivePage = TabSheet1 ;
     Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName) ;
     bmp->Width = Image1->Picture->Width;
     bmp->Height = Image1->Picture->Height;
     BitsArray = new Byte[bmp->Width*bmp->Height*3];
     Form1->Image1->Stretch=((Form1->Image1->Width>bmp->Width)&&(Form1->Image1->Height>bmp->Height ) )  ? false : true ;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Button2Click(TObject *Sender)
{
      int W,H,Row ;
      Graphics::TBitmap *bitmap = Form1->Image1->Picture->Bitmap;
      bitmap->PixelFormat= pf24bit ;
      W= bitmap->Width;
      H= bitmap->Height;
      for( Row=0 ;Row< H ;Row++ )  //Restore the Bitmap from the array       {   Move(bitmap->ScanLine[Row], &BitsArray[W*Row],W);   }
      Compareyuv(BitsArray,W,H);
       Form1->Caption=IntToStr(W)+" x "+IntToStr(H);
   //  Form1->PageControl1->ActivePage = TabSheet2 ;
   //  Image2->Refresh();        }
//---------------------------------------------------------------------------
void Compareyuv(Byte *ptr,int W,int H)
{   Byte dif;
    int i,j,Row;
    int R,G,B ;
    int Y1,Y2;
    for( Row=0;Row< H ; Row++ )
    {
               for(j=0;jG&&G>B)
             {   dif=R-B;
                 if(dif>50)
                 {
                 int  y =   (0.299*R) + (0.587*G) + (0.114*B);
                 int  u =  -(0.147*R) - (0.289*G) + (0.436*B) ;
                 int  v =   (0.615*R) - (0.515*G) - (0.1*B) ;
                
                 Y1=-0.14756*u*u+70.52187*u-8193.7928;
                 Y2=-2.80476*u*u+1346.5095*u-161380.9945;
                 if(v<17||v>67)
                    {                        ptr[Row*W+j*3]=0;
                    ptr[Row*W+j*3+1]=0;
                    ptr[Row*W+j*3+2]=0;
                    }
                 else if(16<=v<=67&&Y1<=y<=Y2)
                    {                        ptr[Row*W+j*3]=B;
                    ptr[Row*W+j*3+1]=G;
                    ptr[Row*W+j*3+2]=R;                        }                      }
             }
             else
             {
               ptr[Row*W+j*3]=0;
               ptr[Row*W+j*3+1]=0;
               ptr[Row*W+j*3+2]=0;
            
             }              }        }        ShowImage( Form1->Image2,W,H, BitsArray );
}
//------------------------------------------------------------------------
void ShowImage( TImage *image ,int W,int H,Byte *source )
{
  int Row;
  Graphics::TBitmap *bitmap;
  bitmap = image->Picture->Bitmap;
  bitmap->PixelFormat= pf24bit ;
  bitmap->Width = W;
  bitmap->Height= H;
  image->Stretch= ( (image->Width>bitmap->Width)&&(image->Height>bitmap->Height ) )  ? false : true ;
  for( Row=0 ;RowScanLine[Row],W)  ;      image->Invalidate();
}
//--------------------------------------------------------------------------     
good for you!! 發表人 - perking 於 2005/08/05 00:11:39
------
good for you!!
justdo
高階會員


發表:2
回覆:359
積分:222
註冊:2004-08-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-08-05 09:05:36 IP:221.169.xxx.xxx 未訂閱
雖然影像的寬度為 W,但是每一個pixel都是由三個byte組成 所以影像寬度為W的影像,在讀取每一行的時候實際要讀取 3*W 個byte 因此你Move函式的地方都需要修改一下 另外建議你用ScanLine搜尋本站,會找到很多相關的討論
perking
一般會員


發表:9
回覆:5
積分:2
註冊:2004-10-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-08-05 16:43:09 IP:59.104.xxx.xxx 未訂閱
引言: 雖然影像的寬度為 W,但是每一個pixel都是由三個byte組成 所以影像寬度為W的影像,在讀取每一行的時候實際要讀取 3*W 個byte 因此你Move函式的地方都需要修改一下 另外建議你用ScanLine搜尋本站,會找到很多相關的討論
這位大哥你好 小弟對move指令有點疑惑,是否可以請教您呢? 我曾經把move的count數改成w*3 但是,雖然image2可以完整跑出來,可是, 只是把1/3那部份的圖貼了三次= =" 怎半~~><" good for you!!
------
good for you!!
justdo
高階會員


發表:2
回覆:359
積分:222
註冊:2004-08-17

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-08-07 21:03:42 IP:221.169.xxx.xxx 未訂閱
Button2Click函式
for( Row=0 ;Row< H ;Row   ) 
   {Move(bitmap->ScanLine[Row], &BitsArray[3*W*Row],3*W);}
ShowImage函式亦同 Compareyuv函式也是一樣:
               for(j=0;j3*W j*3]);
              G =int ( ptr[Row*3*W j*3 1]);
             R =int ( ptr[Row*3*W j*3 2]);
其他地方也是一樣比照處理 其他地方就沒詳細檢查了... 另外,你有找ScanLine的相關文章來看了嗎?
perking
一般會員


發表:9
回覆:5
積分:2
註冊:2004-10-14

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-08-10 21:40:12 IP:211.74.xxx.xxx 未訂閱
引言: Button2Click函式
for( Row=0 ;Row< H ;Row   ) 
   {Move(bitmap->ScanLine[Row], &BitsArray[3*W*Row],3*W);}
ShowImage函式亦同 Compareyuv函式也是一樣:
               for(j=0;j3*W j*3]);
              G =int ( ptr[Row*3*W j*3 1]);
             R =int ( ptr[Row*3*W j*3 2]);
其他地方也是一樣比照處理 其他地方就沒詳細檢查了... 另外,你有找ScanLine的相關文章來看了嗎? < face="Verdana, Arial, Helvetica"> 嗯嗯~有去惡補了...感謝大大的提醒!! 我已經順利把程式跑出來了~~ 再三感謝 大哥的幫忙~~ 道行真是高深莫測阿~~ good for you!! 發表人 - perking 於 2005/08/10 21:41:44
------
good for you!!
系統時間:2024-04-30 0:43:47
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!