Image* Image::Crop(int x, int y, int w, int h) { /* Your Work Here (section 3.2.5) */ //return NULL ; Pixel px; Image* img = new Image(w, h); for(int y_ = 0; y_ < h; y_++) { for(int x_ = 0; x_ < w; x_++) { px = GetPixel(x + x_, y + y_); img->GetPixel(x_, y_).Set(px.r, px.g, px.b, px.a); } } return img; }
void CMainDlg::OnPaint() { CPaintDC dc(this); // device context for painting if (IsIconic()) { SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon //dc.DrawIcon(x, y, m_hIcon); } else { //CDialog::OnPaint(); RECT rect; GetClientRect(&rect); int w = rect.right - rect.left; int h = rect.bottom - rect.top; COLORREF colortrans = RGB(0,255,0); HBRUSH hBrush = CreateSolidBrush(colortrans); FillRect(dc,&rect,hBrush); DeleteObject(hBrush); BITMAP bmp; GetObject(m_hBmp,sizeof(bmp),&bmp); HDC hBmpDC = CreateCompatibleDC(dc); SelectObject(hBmpDC,m_hBmp); TransparentBlt(dc,0,0,bmp.bmWidth, bmp.bmHeight,hBmpDC,0,0,bmp.bmWidth,bmp.bmHeight,RGB(0,255,0)); DeleteDC(hBmpDC); if(m_bFirst){ HRGN rgn = GetTrans(dc,GetPixel(dc,0,0),0,0,bmp.bmWidth, bmp.bmHeight); ::SetWindowRgn(m_hWnd,rgn,TRUE); m_bFirst = FALSE; } } }
/* * calculate where on the target the bolt hit * this is based on the colours of the target rings */ static void CheckHit( HDC hdc, POINT hit_point ) /**********************************************/ { DWORD colour; unsigned short points; unsigned short dialog_item; BOOL translated; colour = GetPixel( hdc, hit_point.x, hit_point.y ); switch( colour ) { case RING1: dialog_item = YELLOW; break; case RING2: dialog_item = RED; break; case RING3: dialog_item = BLUE; break; case RING4: dialog_item = BLACK; break; case RING5: dialog_item = WHITE; break; case BACKGROUND: dialog_item = MISSED; break; } /* * increment # of hits on location */ points = GetDlgItemInt( ScoreWnd, dialog_item, &translated, FALSE ); points++; SetDlgItemInt( ScoreWnd, dialog_item, points, FALSE ); /* * increment # of shots */ points = GetDlgItemInt( ScoreWnd, SHOTS, &translated, FALSE ); points++; SetDlgItemInt( ScoreWnd, SHOTS, points, FALSE ); return; } /* CheckHit */
bool CFloodFill2::DrawLineH(int x1, int x2, int y, COLORREF Color, const CRect& Rect) { if (!m_pDib) return false; if (!m_bRedEye && Color == CLR_NONE) return false; if (x1 > x2) x1^=x2, x2^=x1, x1^=x2; if (x1 < 0 && x2 < 0) return false; LONG nWidth = GetWidth(); if (x1 >= nWidth && x2 >= nWidth) return false; if (x1 < 0) x1 = 0; if (x2 >= nWidth) x2 = nWidth - 1; int x = x1; LPBYTE pPixel = DibPtrXYExact(m_pDib, x1, y); LPBYTE pEnd = DibPtrXYExact(m_pDib, x2, y); while (pPixel <= pEnd) { if (m_pBufferDib) { if (!m_bRedEye) Color = m_pBufferDib->GetPixel(x++, y); else { Color = GetPixel(x++, y); RedEyeRemove(Color); } } *pPixel++ = GetBValue(Color); *pPixel++ = GetGValue(Color); *pPixel++ = GetRValue(Color); } return true; }
void ImageWidget::mouseReleaseEvent(QMouseEvent *event) { QWidget::mouseReleaseEvent(event); // Eventlogik if (event->button() == Qt::LeftButton) { mDraw = false; // Aktualisiere Bild update(); if (mTrack) { emit ColorChanged(GetPixel()); } } }
static void PrintState(boolean *state) { int x, y; for (y = 0; y < STATE_HEIGHT; y++) { printf(" "); for (x = 0; x < STATE_WIDTH; x++) { printf(GetPixel(state, x, y) ? "X" : "O"); printf(x != STATE_WIDTH - 1 ? "," : ""); printf((x + 1) % 5 == 0 ? " " : ""); } printf("\n"); printf((y + 1) % 5 == 0 ? "\n" : ""); } }
void CSampleView::OnLButtonDown(UINT nFlags, CPoint point) { if (!m_iSize) return; if (point.y > m_clientRect.bottom) return; int Block = GetBlock(point.x); m_iSelStart = GetPixel(Block); m_iSelEnd = m_iSelStart; Invalidate(); RedrawWindow(); m_bClicked = true; CStatic::OnLButtonDown(nFlags, point); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void ContextItem::Paint(HDC hDC) { if (m_ItemID == MENUITEM_ID_FOLDER) FolderItem::Paint(hDC); else MenuItem::Paint(hDC); if (0==(m_type & MFT_OWNERDRAW)) return; RECT r; GetTextRect(&r); int w = r.right - r.left; int h = r.bottom - r.top; // the remaining margin int m = (int)imax(0, w - (m_bmp_width - m_icon_offset)); // text width int tw = w - m; HDC buf = CreateCompatibleDC(NULL); HGDIOBJ other_bmp = SelectObject(buf, m_bmp); #if 0 BitBlt(hDC, r.left, r.top, tw, h, buf, m_icon_offset, 0, SRCCOPY); #else // adjust offset according to justifications if (mStyle.MenuFrame.Justify == DT_CENTER) m /= 2; else if (mStyle.MenuFrame.Justify != DT_RIGHT) m = 0; // then plot points when they seem to have the textcolor // icons on the left are cut off COLORREF CRTXT_BB = m_bActive ? mStyle.MenuHilite.TextColor : mStyle.MenuFrame.TextColor; int x, y; for (y = 0; y < h; y++) for (x = 0; x < tw; x++) if (CRTXT_WIN == GetPixel(buf, x+m_icon_offset, y)) SetPixel (hDC, r.left+m+x, r.top+y, CRTXT_BB); #endif SelectObject(buf, other_bmp); // this let's the handler know which command to invoke eventually if (m_bActive) DrawItem(buf, m_bmp_width, h, true); DeleteDC(buf); }
ChessView::ChessView( HWND parent, Contact::ref contact ) { _HWND=parent; filePathCHESS=appRootPath+L"\\games\\chess\\chess_1.png"; bmpc=SHLoadImageFile(filePathCHESS.c_str()); /*GetObject(bmpc, sizeof(bmc), &bmc);*/ HDC hdcImage2=CreateCompatibleDC(NULL); SelectObject(hdcSKIN, bmpc); SelectObject(hdcImage2, bmpc); flagaktiv=0; transparentColorCH=GetPixel(hdcImage2, 0, 0);DeleteDC(hdcImage2); int Chesspoleinit[9][9]={ 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0 ,12,13,14,15,16,14,13,12, 0 ,11,11,11,11,11,11,11,11, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0 , 1, 1, 1, 1, 1, 1, 1, 1, 0 , 2, 3, 4, 5, 6, 4, 3, 2 }; int cvtp=1; for(int x=1;x<=8;x++){for(int y=1;y<=8;y++){ Chesspole[y][x]=Chesspoleinit[y][x]; }} BOOST_ASSERT(parent); if (windowClass==0) windowClass=RegisterWindowClass(); if (windowClass==0) throw std::exception("Can't create window class"); parentHWnd=parent; this->contact=contact; thisHWnd=CreateWindow((LPCTSTR)windowClass, _T("chat"), WS_CHILD |WS_VISIBLE, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, g_hInst, (LPVOID)this); }
VOID OnTimer(HWND hWindow, UINT uID) { POINT point = {}; static COLORREF previousColor = 0; // Получение позиции курсора в экранных координатах. GetCursorPos(&point); // Получение контекста устройства для всего экрана. HDC hDesktopDC = GetDC(NULL); // Получение цвета пикселя под курсором. g_currentColor = GetPixel(hDesktopDC, point.x, point.y); // Освобождение контекста устройства. ReleaseDC(NULL, hDesktopDC); // Проверка, отличается ли цвет текущего пикселя от цвета предыдущего. if (g_currentColor != previousColor) { // Формирование строки для последующего вывода на экран. _stprintf_s(g_szText, TEXT("\n R: %d\n G: %d\n B: %d\n\n #%.2X%.2X%.2X"), GetRValue(g_currentColor), GetGValue(g_currentColor), GetBValue(g_currentColor), GetRValue(g_currentColor), GetGValue(g_currentColor), GetBValue(g_currentColor)); // Заполнение белым цветом растрового изображения, выбранного в контекст памяти. PatBlt(g_hMemoryDC, 0, 0, g_clientRectangle.right, g_clientRectangle.bottom, WHITENESS); // Установка цвета кисти, выбранной в контекст устройства. SetDCBrushColor(g_hMemoryDC, g_currentColor); // Рисование прямоугольника, который будет заполнен цветом, соответствующим пикселю под // курсором. Rectangle(g_hMemoryDC, g_colorRectangle.left, g_colorRectangle.top, g_colorRectangle.right, g_colorRectangle.bottom); // Вывод текста, содержащего значения каждой составляющей для текущего цвета. DrawText(g_hMemoryDC, g_szText, _tcslen(g_szText), &g_textRectangle, DT_CENTER); // Отправка приложению сообщения WM_PAINT. InvalidateRect(hWindow, NULL, TRUE); } // Запоминание текущего цвета. previousColor = g_currentColor; }
void cImage::Flip() { if ( NULL != mPixels ) { cImage tImg( mHeight, mWidth, mChannels ); for ( eeUint y = 0; y < mHeight; y++ ) for ( eeUint x = 0; x < mWidth; x++ ) tImg.SetPixel( y, x, GetPixel( x, mHeight - 1 - y ) ); ClearCache(); mPixels = tImg.GetPixels(); mWidth = tImg.Width(); mHeight = tImg.Height(); tImg.AvoidFreeImage( true ); } }
/* *-------------------------------------------------------------------------------- * 函数名: BeginDraw * 功能 : 用当前画刷颜色填充封闭区域 * 参数 : CPoint ptPoint - 当前的坐标点 * 算法 : 重载函数,调用 API 函数进行填充 *-------------------------------------------------------------------------------- */ void CPaintTub::BeginDraw(const CPoint& ptPoint) { HDC hDC = m_hDC; // 得到当前坐标点的颜色 COLORREF crCurPos = GetPixel(hDC, ptPoint.x, ptPoint.y); HBRUSH hBrush = CreateSolidBrush(m_crPenColor); HBRUSH hOldBrush = (HBRUSH) SelectObject(hDC, hBrush); // 填充颜色, Windows API ExtFloodFill(hDC, ptPoint.x, ptPoint.y, crCurPos, FLOODFILLSURFACE); SelectObject(hDC, hOldBrush); DeleteObject(hOldBrush); DeleteObject(hBrush); }
int GPwritebitmap (Gbitmap_t *bitmap, FILE *fp) { Gwidget_t *widget; HDC gc; COLORREF color; char bufp[2048]; int bufi, x, y, w, h; if (!bitmap) { Gerr (POS, G_ERRNOBITMAP); return -1; } if ( bitmap->canvas < 0 || bitmap->canvas >= Gwidgetn || !Gwidgets[bitmap->canvas].inuse ) { Gerr (POS, G_ERRBADWIDGETID, bitmap->canvas); return -1; } widget = &Gwidgets[bitmap->canvas]; if (widget->type != G_CANVASWIDGET && widget->type != G_PCANVASWIDGET) { Gerr (POS, G_ERRNOTACANVAS, bitmap->canvas); return -1; } gc = CreateCompatibleDC (GC); SelectObject (gc, bitmap->u.bmap.orig); fprintf (fp, "P6\n%d %d 255\n", (int) bitmap->size.x, (int) bitmap->size.y); bufi = 0; w = bitmap->size.x; h = bitmap->size.y; for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { color = GetPixel (gc, x, y); bufp[bufi++] = GetRValue (color); bufp[bufi++] = GetGValue (color); bufp[bufi++] = GetBValue (color); if (bufi + 3 >= 2048) { fwrite (bufp, 1, bufi, fp); bufi = 0; } } } if (bufi > 0) fwrite (bufp, 1, bufi, fp); DeleteDC (gc); return 0; }
/* * tooltip_get_cursor_height - マウスカーソルの高さを取得 */ static int tooltip_get_cursor_height(const HCURSOR hcursor) { HDC hdc, mdc; HBITMAP hbmp, ret_hbmp; ICONINFO icon_info; int width, height; int x, y; // カーソルの大きさ取得 width = GetSystemMetrics(SM_CXCURSOR); height = GetSystemMetrics(SM_CYCURSOR); // カーソル(マスク)の描画 hdc = GetDC(NULL); mdc = CreateCompatibleDC(hdc); hbmp = CreateCompatibleBitmap(hdc, width, height); ret_hbmp = SelectObject(mdc, hbmp); DrawIconEx(mdc, 0, 0, hcursor, width, height, 0, NULL, DI_MASK); // カーソルの高さ取得 for (y = height - 1; y >= 0; y--) { for (x = 0; x < width; x++) { if (GetPixel(mdc, x, y) != RGB(255, 255, 255)) { break; } } if (x < width) { break; } } SelectObject(mdc, ret_hbmp); DeleteObject(hbmp); DeleteDC(mdc); ReleaseDC(NULL, hdc); // ホットスポットの位置を取得 ZeroMemory(&icon_info, sizeof(ICONINFO)); GetIconInfo(hcursor, &icon_info); if (icon_info.hbmMask != NULL) { DeleteObject(icon_info.hbmMask); } if (icon_info.hbmColor != NULL) { DeleteObject(icon_info.hbmColor); } return (((y < 0) ? height : y) - icon_info.yHotspot); }
HBITMAP createGrayBitmap( HBITMAP srcBmp, COLORREF transparent ) { HBITMAP destBmp = NULL; BITMAP bitmap; HDC dcMem = NULL, dcSrc = NULL; HBITMAP bmpOldSrc = NULL, bmpOldMem = NULL; if( ( dcMem = CreateCompatibleDC( NULL ) ) && ( dcSrc = CreateCompatibleDC( NULL ) ) ) { GetObject( srcBmp, sizeof( bitmap ), &bitmap ); if( ( destBmp = CreateBitmap( bitmap.bmWidth, bitmap.bmHeight, bitmap.bmPlanes, bitmap.bmBitsPixel, NULL ) ) ) { bmpOldMem = (HBITMAP)SelectObject( dcMem, destBmp ); bmpOldSrc = (HBITMAP)SelectObject( dcSrc, srcBmp ); if( bmpOldMem && bmpOldSrc ) { BitBlt( dcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, dcSrc, 0, 0, SRCCOPY ); for( int i = 0; i < bitmap.bmWidth; ++i ) for( int j = 0; j < bitmap.bmHeight; ++j ) { COLORREF color = GetPixel( dcMem, i, j ); if( color != transparent ) { double grayScale = GetRValue( color ) * 0.3 + GetGValue( color ) * 0.59 + GetBValue( color ) * 0.11; grayScale = grayScale / 2 + 128; color = RGB( grayScale, grayScale, grayScale ); SetPixel( dcMem, i, j, color ); } } SelectObject( dcSrc, bmpOldSrc ); SelectObject( dcMem, bmpOldMem ); } } } if( dcMem ) DeleteDC( dcMem ); if( dcSrc ) DeleteDC( dcSrc ); return destBmp; }
KHMEXP int KHMAPI khui_ilist_add_masked(khui_ilist * il, HBITMAP hbm, COLORREF cbkg) { HDC dcr,dci,dct,dcb; HBITMAP hb_oldb, hb_oldi, hb_oldt; int sx, i; int x,y; dcr = GetDC(NULL); dci = CreateCompatibleDC(dcr); dct = CreateCompatibleDC(dcr); dcb = CreateCompatibleDC(dcr); ReleaseDC(NULL,dcr); i = il->nused++; il->idlist[i] = -1; sx = i * il->cx; hb_oldb = SelectObject(dcb, hbm); hb_oldi = SelectObject(dci, il->img); hb_oldt = SelectObject(dct, il->mask); SetBkColor(dct, RGB(0,0,0)); SetTextColor(dct, RGB(255,255,255)); BitBlt(dci, sx, 0, il->cx, il->cy, dcb, 0, 0, SRCCOPY); for(y=0;y < il->cy; y++) for(x=0; x<il->cx; x++) { COLORREF c = GetPixel(dcb, x, y); if(c==cbkg) { SetPixel(dct, sx + x, y, RGB(255,255,255)); SetPixel(dci, sx + x, y, RGB(0,0,0)); } else { SetPixel(dct, sx + x, y, RGB(0,0,0)); } } SelectObject(dct, hb_oldt); SelectObject(dci, hb_oldi); SelectObject(dcb, hb_oldb); DeleteDC(dcb); DeleteDC(dct); DeleteDC(dci); return i; }
/* randomly re-place one of two points that are too close to each other, * move others that are too far from the centroid towards the centroid */ void OpticalFlow::AddNewFeatures(IplImage* rgbImage, CPointVector& features, CStatusVector& status, int last_width, int last_height, bool use_prob_distr) { ASSERT(m_pProbDistrProvider); CDoubleMatrix distances; DistanceMatrix(features, distances); // discard the highest 15percent of distances when computing centroid int discard_num_distances = (int)(0.15*(double)distances.size()); int centroid_index = FindCentroid(distances, discard_num_distances); CvPoint2D32f centroid = features[centroid_index]; // double halfwidth = last_width/2.0; // double halfheight = last_height/2.0; // double left = centroid.x-halfwidth; // double right = centroid.x+halfwidth; // double top = centroid.y-halfheight; // double bottom = centroid.y+halfheight; for (int fcnt=m_num_features_tracked; fcnt<m_target_num_features; fcnt++) { // try to find a location that was segmented as foreground color int x, y; double prob = 1.0; int prob_cnt = 0; do { x = (int) (centroid.x-last_width/2.0+(rand()%last_width)); y = (int) (centroid.y-last_height/2.0+(rand()%last_height)); x = min(x, rgbImage->width-1); y = min(y, rgbImage->height-1); x = max(x, 0); y = max(y, 0); ColorBGR* color; GetPixel(rgbImage, x, y, &color); if (use_prob_distr) { prob = m_pProbDistrProvider->LookupProb(*color); } prob_cnt++; } while (prob<MIN_PROB_FOREGROUND && prob_cnt<20); features[fcnt].x = (float)x; features[fcnt].y = (float)y; status[fcnt] = 0; } // end for fcnt }
Font::Font(Surface *fs) { newcolor= false; HDC hSurfaceDC; COLORREF color; int ch,klength, i; FontSurface = fs; hSurfaceDC = FontSurface->GetDC( false ); ascii= new TCHAR[256]; _tcscpy(ascii,TEXT(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~_")); ch=0; klength=0; for (i=0; i<256; i++) { chardata[i].length=0; chardata[i].offset=0; } for (i=0; i<fs->GetWidth(); i++) { color = GetPixel(hSurfaceDC,i,0); //if (color == RGB(255,255,255)) // doesn't work in pocketpc, only desktop pc. white is not always white ? Help me with this. if ((GetRValue(color)>0) && (GetGValue(color)>0) && (GetBValue(color)>0)) // had to use these instead. { // test for the width data on top of each char. Leave 1 blank channel when using color masks. use 255,0,255 for mask. if (klength==0) chardata[ascii[ch]].offset=i; klength++; // true, not a mask color so record length of char. } else { // it's a mask color so ignore. if (klength!=0) { chardata[ascii[ch]].length=klength; ch++; } klength=0; } } FontSurface->ReleaseDC( hSurfaceDC ); FontSurface->SetColorMask(Color(255,0,255)); }
RGBA* CClipboard::GetBitmapImageFromClipboard(int& width, int& height) { width = 0; height = 0; HBITMAP bitmap = (HBITMAP)GetClipboardData(CF_BITMAP); if (bitmap == NULL) { return NULL; } BITMAP b; GetObject(bitmap, sizeof(b), &b); HDC dc = CreateCompatibleDC(NULL); HBITMAP oldbitmap = (HBITMAP)SelectObject(dc, bitmap); width = b.bmWidth; height = b.bmHeight; if (width <= 0 || height <= 0) { width = 0; height = 0; return NULL; } RGBA* pixels = new RGBA[width * height]; if (pixels == NULL) { width = 0; height = 0; return NULL; } memset(pixels, 255, sizeof(RGBA) * width * height); // todo: GetPixel/GetR/G/BValue are extremely slow, fix it! RGBA* ptr = pixels; for (int iy = 0; iy < height; iy++) { for (int ix = 0; ix < width; ix++) { COLORREF pixel = GetPixel(dc, ix, iy); if (pixel != CLR_INVALID) { ptr->red = GetRValue(pixel); ptr->green = GetGValue(pixel); ptr->blue = GetBValue(pixel); } ptr++; } } SelectObject(dc, oldbitmap); DeleteDC(dc); return pixels; }
STATICFN DWORD NEAR ComputeInverseColor( DWORD rgb) { HBITMAP hTempBit1; HBITMAP hTempBit2; HDC hTempDC1; HDC hTempDC2; HDC hdc; HANDLE hOldObj1; HANDLE hOldObj2; DWORD rgbInv; hdc = GetDC(ghwndMain); hTempDC1 = CreateCompatibleDC(hdc); hTempDC2 = CreateCompatibleDC(hdc); /* create two temporary 1x1, 16 color bitmaps */ hTempBit1 = MyCreateBitmap(hdc, 1, 1, 16); hTempBit2 = MyCreateBitmap(hdc, 1, 1, 16); ReleaseDC(ghwndMain, hdc); hOldObj1 = SelectObject(hTempDC1, hTempBit1); hOldObj2 = SelectObject(hTempDC2, hTempBit2); /* method for getting inverse color : set the given pixel (rgb) on * one DC. Now blt it to the other DC using a SRCINVERT rop. * This yields a pixel of the inverse color on the destination DC */ SetPixel(hTempDC1, 0, 0, rgb); PatBlt(hTempDC2, 0, 0, 1, 1, WHITENESS); BitBlt(hTempDC2, 0, 0, 1, 1, hTempDC1, 0, 0, SRCINVERT); rgbInv = GetPixel(hTempDC2, 0, 0); /* clean up ... */ SelectObject(hTempDC1, hOldObj1); SelectObject(hTempDC2, hOldObj2); DeleteObject(hTempBit1); DeleteObject(hTempBit2); DeleteDC(hTempDC1); DeleteDC(hTempDC2); /* ...and return the inverted RGB value */ return rgbInv; }
/*-----------------------------------------------------------------------------\* Initialize the image model using the given image and MOG params \*-----------------------------------------------------------------------------*/ void ImageModel::Initialize(IplImage* img, MOGParams &mogParams) { m_nWidth = img->width; m_nHeight = img->height; m_nNumberOfPixels = m_nWidth * m_nHeight; m_vecPixelModels.reserve(m_nNumberOfPixels); std::vector<double> vecFeatures; vecFeatures.reserve(mogParams.nNumberOfFeatures); for (int i = 0; i < m_nNumberOfPixels; ++i) { GetPixel(img, i / m_nWidth, i % m_nWidth, vecFeatures); PixelModel *pPixelModel = new PixelModel(); pPixelModel->Initialize(mogParams.nNumberOfGaussiansPerPixel, vecFeatures, mogParams); m_vecPixelModels.push_back(pPixelModel); } }
/*-----------------------------------------------------------------------------\* Add background based on the new image and return the current model if asked for \*-----------------------------------------------------------------------------*/ void ImageModel::AddBackground(IplImage* img, MOGParams &mogParams, IplImage *bgImage, IplImage* fgImage) { std::vector<double> vecFeatures; vecFeatures.reserve(mogParams.nNumberOfFeatures); for (int i = 0; i < m_nNumberOfPixels; ++i) { int nRow = i / m_nWidth; int nCol = i % m_nWidth; GetPixel(img, nRow, nCol, vecFeatures); m_vecPixelModels[i]->AddBackground(vecFeatures, mogParams); if (fgImage != NULL) ((uchar *) (fgImage->imageData + nRow * fgImage->widthStep))[nCol] = m_vecPixelModels[i]->m_bIsForeground ? 255 : 0; if (bgImage != NULL) SetPixel(bgImage, nRow, nCol, m_vecPixelModels[i]->GetBackgroundModel()); } }
void ribi::ImageRotaterMainDialog::Rotate( const QImage& pixmapOriginal, QImage& pixmapResult, const double angle) { QImage imageOriginal = pixmapOriginal; //pixmapOriginal.toImage(); QImage imageResult = pixmapResult; //pixmapResult.toImage(); const int maxx = imageResult.width(); const int maxy = imageResult.height(); const double midx = static_cast<double>(maxx) / 2.0; const double midy = static_cast<double>(maxy) / 2.0; for (int y=0; y!=maxy; ++y) { for(int x=0; x!=maxx; ++x) { const double dx1 = static_cast<double>(x) - midx; const double dy1 = static_cast<double>(y) - midy; double dx2, dy2; //Coordinats in original Translate(dx1,dy1,angle,dx2,dy2); const double x2 = (static_cast<double>(imageOriginal.width() ) / 2.0) + dx2; const double y2 = (static_cast<double>(imageOriginal.height()) / 2.0) + dy2; if ( x2 < 1.0 || y2 < 1.0 || x2 >= imageOriginal.width() - 1.0 || y2 >= imageOriginal.height() - 1.0 ) { //Out of range //SetPixel(imageResult,x,y,qRgb(0,0,0)); imageResult.setPixel(x,y,qRgb(0,0,0)); continue; } const QRgb rgb { GetPixel(imageOriginal,x2,y2) }; imageResult.setPixel(x,y,rgb); //SetPixel(imageResult,x,y,rgb); } } pixmapResult = imageResult; //pixmapResult = QPixmap::fromImage(imageResult); }
int Paint(HDC &hdc, int width, int height) { int x[BN], y[BN]; bool stop = false; int n = 0; while (stop == false) { if (GetAsyncKeyState(VK_ESCAPE)) { _getch(); stop = true; } // Cоздаем контекст HDC hmemDC = CreateCompatibleDC(hdc); // Cоздаем битмап HBITMAP hbmpTarget = CreateCompatibleBitmap(hdc, width, height); // Выбираем битмап в контекст ::SelectObject(hmemDC, hbmpTarget); //Записывает наш bmb в память BitBlt(hmemDC, 0, 0, width, height, hdc, 0, 0, SRCCOPY); for (int i = 0; i<BN; i++) { x[i] = rand() % width; y[i] = rand() % height; if (GetPixel(hmemDC, x[i], y[i]) == RGB(0, 0, 0)) { SetPixel(hdc, x[i], y[i], RGB(randColor(), randColor(), randColor())); n++; } else { SetPixel(hdc, x[i], y[i], RGB(0, 0, 0)); n--; } } PText(hdc, Rate(n, width, height)); DeleteDC(hmemDC); // контекст отжирает уйму ресурсов, поэтому не забудем его грохнуть DeleteObject(hbmpTarget); hmemDC = NULL; Sleep(12); } return n; };
BOOL DrawKnob(HDC hdc, RECT rect, UINT state) { // Calculate dimensions int width = rect.right - rect.left; int height = rect.bottom - rect.top; // Load bitmap HBITMAP bitmap = LoadImage(hInst, "Knob", IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); // Create DC HDC hbdc = CreateCompatibleDC(hdc); // Select the bitmap SelectObject(hbdc, bitmap); // Select a brush SelectObject(hbdc, GetSysColorBrush(COLOR_BTNFACE)); // Get the colour of the centre pixel COLORREF colour = GetPixel(hbdc, width / 2, height / 2); // Flood fill the bitmap ExtFloodFill(hbdc, width / 2, height / 2, colour, FLOODFILLSURFACE); // Copy the bitmap BitBlt(hdc, rect.left, rect.top, width, height, hbdc, 0, 0, SRCCOPY); DeleteObject(bitmap); DeleteObject(hbdc); return TRUE; }
bool CGutFontUniCodeOpenGL::AccessTexture(WCHAR c, int &x, int &y) { bool bUpdateTexture = CGutFontUniCode::AccessTexture(c, x, y); if ( bUpdateTexture ) { float tX = (float)x / (float)m_iLayoutW; float tY = (float)y / (float)m_iLayoutH; float tW = 1.0f/(float)m_iLayoutW; float tH = 1.0f/(float)m_iLayoutH; int left = tX * m_iTextureW; int width = tW * m_iTextureW; int right = left + width; int top = tY * m_iTextureH; int height = tH * m_iTextureH; int bottom = top + height; unsigned char *pBuffer = new unsigned char[width*height]; unsigned char *buffer = pBuffer; for ( int y=0; y<height; y++ ) { for ( int x=0; x<width; x++ ) { COLORREF rgb = GetPixel(m_MemDC, x, y); int grayscale = GetRValue(rgb) + GetGValue(rgb) + GetBValue(rgb); grayscale /= 3; *buffer++ = grayscale; } } glBindTexture(GL_TEXTURE_2D, m_FontTexture); glTexSubImage2D(GL_TEXTURE_2D, 0, left, top, width, height, GL_ALPHA, GL_UNSIGNED_BYTE, pBuffer); delete [] pBuffer; } return true; }
int GetTrueScreenDepth(HDC hDC) { // don't think I really use/rely on this method anymore...luckily since it looks gross int RetDepth = GetDeviceCaps(hDC, BITSPIXEL); if (RetDepth = 16) { // Find out if this is 5:5:5 or 5:6:5 HBITMAP hBMP = CreateCompatibleBitmap(hDC, 1, 1); HBITMAP hOldBMP = (HBITMAP)SelectObject(hDC, hBMP); // TODO do we need to delete this? if (hOldBMP != NULL) { SetPixelV(hDC, 0, 0, 0x000400); if ((GetPixel(hDC, 0, 0) & 0x00FF00) != 0x000400) RetDepth = 15; SelectObject(hDC, hOldBMP); } DeleteObject(hBMP); } return RetDepth; }
LRESULT CImgAreaWindow::OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { if (drawing) { ReleaseCapture(); drawing = FALSE; endPaintingR(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), paletteModel.GetFgColor(), paletteModel.GetBgColor()); Invalidate(FALSE); if (toolsModel.GetActiveTool() == TOOL_COLOR) { COLORREF tempColor = GetPixel(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom()); if (tempColor != CLR_INVALID) paletteModel.SetBgColor(tempColor); } SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) ""); } return 0; }
BOOL KDIB::PlgBltGetPixel(const POINT * pPoint, HDC hSrc, int nXSrc, int nYSrc, int nWidth, int nHeight, HDC hDst) { KReverseAffine map(pPoint); map.Setup(nXSrc, nYSrc, nWidth, nHeight); for (int dy=map.miny; dy<=map.maxy; dy++) for (int dx=map.minx; dx<=map.maxx; dx++) { float sx, sy; map.Map(dx, dy, sx, sy); if ( (sx>=nXSrc) && (sx<(nXSrc+nWidth)) ) if ( (sy>=nYSrc) && (sy<(nYSrc+nHeight)) ) SetPixel(hDst, dx, dy, GetPixel(hSrc, (int)sx, (int)sy)); } return TRUE; }
static COLORREF getParentDlgBkColor(HWND hWnd) { COLORREF crRet = CLR_INVALID; if (hWnd && IsWindow(hWnd)) { HWND hWndParent = GetParent(hWnd); if (hWndParent) { RECT rc; if (GetClientRect(hWndParent, &rc)) { HDC hDC = GetDC(hWndParent); if (hDC) { HDC hdcMem = CreateCompatibleDC(hDC); if (hdcMem) { HBITMAP hBmp = CreateCompatibleBitmap(hDC, rc.right, rc.bottom); if (hBmp) { HGDIOBJ hOld = SelectObject(hdcMem, hBmp); if (hOld) { if (SendMessage(hWndParent, WM_ERASEBKGND, (WPARAM)hdcMem, 0)) { crRet = GetPixel(hdcMem, 0, 0); } SelectObject(hdcMem, hOld); } DeleteObject(hBmp); } DeleteDC(hdcMem); } ReleaseDC(hWndParent, hDC); } } } } return crRet; }