/* * Load a picture, and save it */ void TestFile( char *filename, char *dstfilename, int output_index ) { GFLW_LOAD_PARAMS load_option; GFLW_BITMAP bitmap; GFLW_FILE_INFORMATION info; GFL_ERROR error; error = bitmap.LoadFromFile(filename, load_option, info); if ( error ) DisplayError( filename, error ); else { GFLW_SAVE_PARAMS save_option; save_option.SetFlags(GFL_SAVE_REPLACE_EXTENSION); save_option.SetFormat(output_index == -1 ? info.GetIndexOfFormat() : output_index); error = bitmap.SaveIntoFile(dstfilename, save_option); if ( error ) DisplayError( dstfilename, error ); GFLW_BITMAP bitmap2(bitmap); bitmap2.Empty(); } }
void DialPadPanel::createPhoneButton(const wxString& bmpFile, const wxString& bmpDown, const int btnID, const int row, const int col, const enum TONE_ID toneId, const char charRepresentation) { static int index = 0; static int lastRight = 0; static int lastBottom = 0; wxPoint pos; pos.x = lastRight; pos.y = lastBottom; wxBitmap bitmap(bmpFile,wxBITMAP_TYPE_BMP); bitmap.SetMask(new wxMask(bitmap, * (wxTheColourDatabase->FindColour("RED")))); mpButton[index] = new DialPadButton(this, btnID, bitmap, pos, wxSize(bitmap.GetWidth(),bitmap.GetHeight()), toneId, charRepresentation); if (bmpDown != "") { wxBitmap bitmap2(bmpDown,wxBITMAP_TYPE_BMP); bitmap2.SetMask(new wxMask(bitmap2, * (wxTheColourDatabase->FindColour("RED")))); mpButton[index]->SetBitmapSelected(bitmap2); } wxColor btnColor = (sipXezPhoneSettings::getInstance().getBackgroundColor()); mpButton[index]->SetBackgroundColour(btnColor); lastRight = bitmap.GetWidth() + pos.x; if (col == 2) { lastBottom = bitmap.GetHeight() + pos.y; lastRight = 0; } return; }
Z_DEFINE_TEST_CASE(Bitmap, tester, size) { Bitmap bitmap(4096); Z_EXPECT_EQ(bitmap.Size(), 4096); Bitmap bitmap2(512); Z_EXPECT_NE(bitmap2.Size(), 1024); }
bool MyApp::MakeSplash() { // First, load the original (template) splash image. int imageType = wxDetermineImageType(m_inputFilename); wxImage templateImage; if (imageType == -1 || !wxFileExists(m_inputFilename) || !templateImage.LoadFile(m_inputFilename, imageType)) { wxString msg; msg.Printf(wxT("Sorry, could not load template image %s"), (const wxChar*) m_inputFilename); wxLogMessage(msg); return FALSE; } wxString msg; msg.Printf(wxT("Creating new file %s from template file %s and text %s"), (const wxChar*) m_outputFilename, (const wxChar*) m_inputFilename, (const wxChar*) m_text); Log(msg); wxScreenDC screenDC; bool useScaling = m_antialias && (m_scaleFactor > 1); int pointSize; #if !USE_SCALING useScaling = FALSE; #endif if (useScaling) pointSize = m_scaleFactor*m_fontPointSize; else pointSize = m_fontPointSize; wxString faceName = m_fontFaceName; wxFont font(pointSize, wxDEFAULT, m_fontStyle, m_fontWeight, FALSE, faceName); screenDC.SetFont(font); int w, h, scaledW, scaledH; screenDC.GetTextExtent(m_text, & w, & h); if (useScaling) { wxFont font2(m_fontPointSize, wxDEFAULT, m_fontStyle, m_fontWeight, FALSE, faceName); screenDC.SetFont(font2); screenDC.GetTextExtent(m_text, & scaledW, & scaledH); } screenDC.SetFont(wxNullFont); wxBrush backgroundBrush(m_textBackgroundColour, wxSOLID); wxBitmap bitmap(w, h); wxMemoryDC memDC; memDC.SelectObject(bitmap); memDC.SetFont(font); memDC.SetBackgroundMode(wxTRANSPARENT); memDC.SetTextForeground(m_textForegroundColour); memDC.SetBackground(backgroundBrush); memDC.SetBrush(backgroundBrush); memDC.Clear(); memDC.DrawText(m_text, 0, 0); memDC.SelectObject(wxNullBitmap); wxImage image = bitmap.ConvertToImage(); if (m_antialias) { wxImage anti = wxAntiAlias(image); image = anti; } if (useScaling) { // Now create an image and rescale it down to the original point size image.Rescale(w/m_scaleFactor, h/m_scaleFactor); } image.SetMaskColour(m_textBackgroundColour.Red(), m_textBackgroundColour.Green(), m_textBackgroundColour.Blue()); wxBitmap bitmap2(image); // Now draw the image into the template image wxBitmap templateBitmap(templateImage); wxMemoryDC memDCTemplate; memDCTemplate.SelectObject(templateBitmap); int x, y; if (m_centre) { y = m_textPosition.y; // Currently, always start at this position x = m_textPosition.x - (image.GetWidth() / 2); } else if (m_rightJustify) { y = m_textPosition.y; // Currently, always start at this position x = m_textPosition.x - (image.GetWidth()); } else { y = m_textPosition.y; // Currently, always start at this position x = m_textPosition.x; } memDCTemplate.DrawBitmap(bitmap2, x, y, TRUE); memDCTemplate.SelectObject(wxNullBitmap); wxImage completeImage = templateBitmap.ConvertToImage(); int saveImageType = wxDetermineImageType(m_outputFilename); if (saveImageType == -1) { wxLogMessage(wxT("Sorry, unknown output image file type.")); return FALSE; } ((MyFrame*) GetTopWindow())->m_viewerWindow->SetBitmap(templateBitmap); // TODO: get the depth from the original image, and set for this image. // May have to do explicit image reduction for this to work. if (!completeImage.SaveFile(m_outputFilename, saveImageType)) { wxString msg; msg.Printf(wxT("Sorry, could not save image to %s"), (const wxChar*) m_outputFilename); wxLogMessage(msg); return FALSE; } #if 0 if (wxTheClipboard->Open()) { wxTheClipboard->Clear(); wxTheClipboard->SetData(new wxBitmapDataObject(bitmap2)); wxTheClipboard->Close(); } #endif return TRUE; }