Ejemplo n.º 1
0
void ExplainCanvas::SaveAsImage(const wxString &fileName, wxBitmapType imageType)
{
	if (GetDiagram()->GetCount() == 0)
	{
		wxMessageBox(_("Nothing to be saved!"), _("Save As an image"), wxOK | wxICON_INFORMATION);
		return;
	}

	int width = 0, height = 0;
	GetVirtualSize(&width, &height);

	/*
	* Create the bitmap from the Explain window
	*/
	wxMemoryDC memDC;
	wxBitmap tempBitmap(width, height);

	memDC.SelectObject(tempBitmap);
	memDC.Clear();

	// Draw the diagram on the bitmap (Memory Device Context)
	GetDiagram()->Redraw(memDC);

	memDC.SelectObject(wxNullBitmap);

	if (!tempBitmap.SaveFile(fileName, imageType))
	{
		wxLogError(_("Could not write file \"%s\": error code %d."), fileName.c_str(), wxSysErrorCode());
	}
}
Ejemplo n.º 2
0
void gqbView::SaveAsImage(const wxString &fileName, wxBitmapType imgType)
{

	updateModelSize(NULL, true);

	if (modelSize.GetWidth() == 0 || modelSize.GetHeight() == 0)
	{
		wxMessageBox(_("Nothing to be saved!"), _("Save As an image"), wxOK | wxICON_INFORMATION);
		return;
	}

	int width = 0, height = 0;
	GetVirtualSize(&width, &height);

	/*
	* Create the bitmap from the Explain window
	*/
	wxMemoryDC memDC;
	wxBitmap tempBitmap(width, height);

	memDC.SelectObject(tempBitmap);
	memDC.Clear();

	// Draw the diagram on the bitmap (Memory Device Context)
	drawAll(memDC, false);

	memDC.SelectObject(wxNullBitmap);

	if (!tempBitmap.SaveFile(fileName, imgType))
	{
		wxLogError(_("Could not write the file %s: Errcode=%d."), fileName.c_str(), wxSysErrorCode());
	}
}
Ejemplo n.º 3
0
void ImageButton::FitToImage() {
  wxBitmap tempBitmap(filePathPrefix_ + _T("Up.png"), wxBITMAP_TYPE_PNG);
  wxASSERT_MSG(tempBitmap.IsOk(), _T("Could not load bitmap"));
  SetSize(tempBitmap.GetWidth(), tempBitmap.GetHeight());
}
void MyFrame::OnPaint(wxPaintEvent& event)
{

    wxPaintDC dc(this);
	int spacingW = 0;
	int spacingH = 0;

    if( pImage == NULL ){
        event.Skip();
    }
    else{
        wxBitmap tempBitmap(*pImage);
        SetClientSize( tempBitmap.GetWidth()*1.25, tempBitmap.GetHeight()*1.25+10 );
		spacingW = ceilf((tempBitmap.GetWidth()*1.25 - tempBitmap.GetWidth())/2);
		spacingH = ceilf((tempBitmap.GetHeight()*1.25 - tempBitmap.GetHeight())/2);
        dc.DrawBitmap(tempBitmap,(int)spacingW,(int)spacingH+25, TRUE);
    }
	// Lab 5 Area
	if(bleftDown)
		pointNumber = areaindex;
	else if(dist>=0 && dist<5){
		pointNumber = areaindex;
		int idist = (int)(floor(dist));
		SetStatusText( wxString::Format("The Distance is %d", idist),0);
	}
	// Lab 5 Area
	if((areaindex >0) && (areaindex <=pointNumber))//If in area calculation mode
	{
		//wxPoint pt(even, GetLogicalPosition(dc));
		wxPoint* acborder_pt=new wxPoint[pointNumber]; //the pointd coord to be drawn
		for(int i= 0; i<areaindex;i++)
		{
			acborder_pt[i].x=dc.LogicalToDeviceX(areaborder[i].x);
			acborder_pt[i].y=dc.LogicalToDeviceY(areaborder[i].y);
		}
		dc.SetPen(*wxRED_PEN);
		//dc.DrawLine(pt.x, pt.y, acborder_pt[areaindex].x, acborder_pt[areaindex].y);
		dc.DrawLines(areaindex, acborder_pt);
		if(areaindex == pointNumber)
		{
			dc.DrawLine( acborder_pt[pointNumber-1].x, acborder_pt[pointNumber-1].y, acborder_pt[0].x, acborder_pt[0].y);
			float farea = 0;
			int area;
			int minborder = 9999;
			for(int i=0; i<pointNumber;i++){
				if(areaborder[i].x< minborder)
					minborder = areaborder[i].x;
			}
			for (int j=0; j<pointNumber - 1; j++){
				farea = ((float)((areaborder[j].x-minborder)+(areaborder[j+1].x - minborder))/2.0)*(areaborder[j+1].y-areaborder[j].y)+farea;
			}
			farea=((float)((areaborder[pointNumber-1].x-minborder)+(areaborder[0].x - minborder))/2.0)*(areaborder[0].y-areaborder[pointNumber-1].y)+farea;
			if(farea<0) farea = -farea;
			area = (int)farea;
			SetStatusText( wxString::Format("The Area is %d", area), 1);

			areaindex = 0;
			bleftDown = !bleftDown;
			bRed = FALSE;
			pointNumber = 99;
			dist = 9999;
		}
		delete acborder_pt;
	}
    return;
}