70 likes | 225 Views
Using Image Encoders and Decoders. Introduction. Storing and manipulating Image Image class & Bitmap class Encoder translates the data in an image object into a file Decoder translates the data in a file into an image object. Introduction. GDI+ built-in encoders & decoders
E N D
Introduction • Storing and manipulating Image • Image class & Bitmap class • Encoder translates the data in an image object into a file • Decoder translates the data in a file into an image object
Introduction • GDI+ built-in encoders & decoders • BMP, GIF, JPEG, PNG, TIFF • WMF, EMF , ICON (Only decoder) • Listing Installed Encoders • You can use GetImageEncoders() to determine which image encoders are available • Return array of ImageCodecInfo objects • 呼叫前,要先配置足夠大的空間 • GetImageEncodersSize
Retrieving the Class Identifier for an Encoder • 利用 GetEncoderClsid可以得到指定 encoder 的 class identifier (CLSID) • 內建的 MINE type encode 為 • image/bmp ; image/jpeg ;image/gif ; image/png • image/tiff; image/png CLSID encoderClsid; INT result; WCHAR strGuid[39]; result = GetEncoderClsid(L"image/png", &encoderClsid); wprintf(L"The CLSID of the PNG encoder is %s.\n", strGuid); • 傳回 image/png 的 class identifier The CLSID of the PNG encoder is {557CF406-1A04-11D3-9A73-0000F81EF32E}.
簡單的影像處理 Bitmap * image = new Bitmap (L"rain1.BMP"); // Step 5: 進行影像處理 int Height=image->GetHeight(); int Width=image->GetWidth(); Color c; for(int y=0;y<Height;y++) for(int x=0;x<Width;x++){ image->GetPixel(x,y,&c); int gray=(c.GetR()+c.GetG()+c.GetB())/3; Color g(gray,gray,gray); image->SetPixel(x,y,g); } 使用 Bitmap Object 讀取指定位置上的一點 設定新的值 ImageComponent