就是用戶把圖片輸入到程式里,程式把圖片變成黑白并且變成矩陣來存盤各個點的灰度資訊,該怎么操作?想把處理程序分為好幾個模塊,應該寫在哪,怎么合起來?
希望能有細致的講解,,,謝謝啦
uj5u.com熱心網友回復:
用TBitMap->LoadFromFile加載圖片,然后設定PixelFormat 為黑白,再保存#include <memory> //For STL auto_ptr class
void __fastcall TForm1::Button1Click(TObject *Sender)
{
std::auto_ptr<Graphics::TBitmap> Bitmap(new Graphics::TBitmap);
std::auto_ptr<Graphics::TBitmap> BigBitmap(new Graphics::TBitmap);
TRGBTriple *ptr, *bigPtr; // Use a (byte *) for pf8bit color.
TPixelFormat pixForm, bigpixForm;
try
{
Bitmap->LoadFromFile("../littlefac.bmp");
pixForm = Bitmap->PixelFormat;
bigpixForm = BigBitmap->PixelFormat;
Bitmap->PixelFormat = pf24bit;
BigBitmap->PixelFormat = pf24bit;
BigBitmap->Height = Bitmap->Height * 2;
BigBitmap->Width = Bitmap->Width * 2;
for (int y = 0; y < Bitmap->Height; y++)
{
ptr = reinterpret_cast<TRGBTriple *>(Bitmap->ScanLine[y]);
for (int x = 0; x < Bitmap->Width; x++)
{
int bx = x * 2;
int by = y * 2;
bigPtr = reinterpret_cast<TRGBTriple *>(BigBitmap->ScanLine[by]);
bigPtr[bx] = ptr[x];
bigPtr[bx + 1] = ptr[x];
bigPtr = reinterpret_cast<TRGBTriple *>(BigBitmap->ScanLine[by + 1]);
bigPtr[bx] = ptr[x];
bigPtr[bx + 1] = ptr[x];
}
}
Canvas->Draw(0, 0, Bitmap.get());
Canvas->Draw(200, 200, BigBitmap.get());
}
catch (...)
{
ShowMessage("Could not load or alter bitmap");
}
}
uj5u.com熱心網友回復:
如果你看下OpenCV,是相當簡單的事兒!轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/97283.html
標籤:基礎類
下一篇:opencv的問題,求高手指教
