AS3_Val initializeBitmap( void* self, AS3_Val args ) { Bitmap * bitmap; int width, height; LPBYTE data; AS3_ArrayValue( args, "IntType, IntType, PtrType", &width, &height, &data ); bitmap = newBitmap( width, height, data ); return AS3_Ptr( bitmap ); }
// Creates a bitmap with transparent areas drawn in // the given colour. wxBitmap wxCreateMaskedBitmap(const wxBitmap& bitmap, wxColour& colour) { wxBitmap newBitmap(bitmap.GetWidth(), bitmap.GetHeight(), bitmap.GetDepth()); wxMemoryDC destDC; wxMemoryDC srcDC; srcDC.SelectObject(bitmap); destDC.SelectObject(newBitmap); wxBrush brush(colour, wxSOLID); destDC.SetBackground(brush); destDC.Clear(); destDC.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), &srcDC, 0, 0, wxCOPY, true); return newBitmap; }
void resizeWindow(Window* win, int width, int height) { bitmap* new_context = newBitmap(width, height); if (!new_context) return; int copy_w = width < win->w ? width : win->w; int copy_h = height < win->h ? height : win->h; win->w = width; win->h = height; int x, y; for (y = 0; y < copy_h; y++) for (x = 0; x < copy_w; x++) new_context->data[y*new_context->width + x] = win->context->data[y*win->context->width + x]; freeBitmap(win->context); win->context = new_context; drawWindow(win, 0); }
Window* newWindow(unsigned int width, unsigned int height, unsigned char flags, unsigned int pid) { static int next_handle = 1; Window *new_window, *temp_window; unsigned int i, bufsz; if (!(new_window = (Window*)malloc(sizeof(window)))) { printf("Coudln't allocate a new window structure"); return 0; } new_window->active = 1; new_window->pid = pid; new_window->flags = flags; new_window->x = 0; new_window->y = 0; new_window->w = width; new_window->h = height; new_window->title = (unsigned char*)0; new_window->frame_needs_redraw = 1; //Create a drawing context for the new window if (!(new_window->context = newBitmap(new_window->w, new_window->h))) { free((void*)new_window); printf("Couldn't allocate bitmap area for new window"); return (window*)0; } bufsz = new_window->w * new_window->h; //Clear new window to white for (i = 0; i < bufsz; i++) new_window->context->data[i] = RGB(255, 255, 255); new_window->handle = next_handle++; if (mouse_window) List_pop(window_list, (void*)mouse_window); //De-activate the old active window if (temp_window = (window*)List_get_at(window_list, window_list->count - (mouse_window ? 2 : 1))) { temp_window->active = 0; } if (!List_add(window_list, (void*)new_window)){ freeBitmap(new_window->context); free((void*)new_window); //re-activate the old active window if (temp_window) temp_window->active = 1; return (window*)0; } //Give the new window its initial decoration if (!(new_window->flags & WIN_UNDECORATED)) drawFrame(new_window); drawWindow(new_window, 0); //Update the titlebar on the old active window if (temp_window) drawTitlebar(temp_window, 1); if (mouse_window) { List_add(window_list, mouse_window); drawWindow(mouse_window, 0); } return new_window; }
int CWmfLoaderImpl::LoadImage(const wstring& wstrFilePath, bool* pbStop, bool bScale, int nWidth, int nHeight) { Gdiplus::Metafile metafile(wstrFilePath.c_str()); if (metafile.GetLastStatus() != Gdiplus::Ok) { return 4; } Gdiplus::MetafileHeader metafileheader; metafile.GetMetafileHeader(&metafileheader); m_nHeight = metafileheader.Height; m_nWidth = metafileheader.Width; if ( m_nWidth == 0 || m_nHeight == 0 ) { return 4; } int nCurWidth = m_nWidth; int nCurHeight = m_nHeight; // 做缩放 if (bScale)// 计算缩放率 { double dRatio = 0; double nMaxLength = nWidth>nHeight?nWidth:nHeight; double nMinLength = nWidth<nHeight?nWidth:nHeight; double nImageMaxLength = m_nWidth>m_nHeight?m_nWidth:m_nHeight; double nImageMinLength = m_nWidth<m_nHeight?m_nWidth:m_nHeight; if (nMaxLength >= nImageMaxLength && nMinLength >= nImageMinLength) // 不缩放 { } else // 缩放 { if (nMaxLength/nImageMaxLength > nMinLength/nImageMinLength) { dRatio = nMinLength/nImageMinLength; } else { dRatio = nMaxLength/nImageMaxLength; } nCurWidth = nCurWidth * dRatio; nCurHeight = nCurHeight * dRatio; } } m_hBitmap = XL_CreateBitmap(XLGRAPHIC_CT_ARGB32, nCurWidth, nCurHeight); if (m_hBitmap == NULL) { return 4; } XLBitmapInfo newBitmapInfo; XL_GetBitmapInfo(m_hBitmap, &newBitmapInfo); Gdiplus::Bitmap newBitmap(newBitmapInfo.Width, newBitmapInfo.Height, newBitmapInfo.ScanLineLength, PixelFormat32bppARGB, XL_GetBitmapBuffer(m_hBitmap, 0, 0)); Gdiplus::Graphics graphics(&newBitmap); Gdiplus::Rect rect(0, 0, nCurWidth, nCurHeight); graphics.DrawImage(&metafile, rect); if (m_hBitmap != NULL) { return 0; } return 4; }