wxwidgets saveFile - wxwidgets

Im trying to draw a simple picture and save it to a file in wxwidgets. This is the code i have so far. However this code will never create the test.png picture.
wxBitmap myBitmap;
wxMemoryDC dc;
dc.SelectObject(myBitmap);
wxFont font=dc.GetFont();
font.SetPointSize(15);
dc.SetTextForeground(*wxBLACK);
dc.DrawRectangle(0,0,50,100);
wxString s(_T("A"));
dc.DrawText(s, 5,5);
wxString test(_T("images/test.png"));
myBitmap.SaveFile(test, wxBITMAP_TYPE_PNG);
Can somebody please help me out in what I'm doing wrong...
/Mike

First a piece of general advice: Use the debug version of wxWidgets, it will often assert whenever you did something wrong.
First you call the default wxBitmap constructor, resulting in an object that can not be used as-is. If you change your first line to
wxBitmap myBitmap(200, 200);
you will instead create a bitmap of 200 pixels width and height, which can actually be selected into the dc and be painted on. Alternatively you can call wxBitmap::Create() before you use the bitmap.
Also, in order to save as a PNG file you need to register the PNG image handler (see the wxImage documentation) first. It's probably easiest to register all default image handlers by calling ::wxInitAllImageHandlers().
Finally you need to make sure that there is a subdirectory images under your current directory. Or use a file name with an absolute path. You would however get a message box at runtime if the saving of the bitmap failed.

You may need to unselect the bitmap from the DC before saving it too:
dc.SelectObject(wxNullBitmap);
myBitmap.SaveFile(test, wxBITMAP_TYPE_PNG);

Firstly I would check the return of the call to SaveFile, if it returns true then it should be succeeding, otherwise there is a failure somewhere else.
Secondly try giving a full path rather than just images/test.png as depending on the current working directory of you program it might not put the file where you think it should.

Update:
"test" = image output name.
".png" image output extention
"wxBITMAP_TYPE_PNG" = wxBitmap image type. see: http://docs.wxwidgets.org/trunk/gdicmn_8h.html#a90a1eb6d85b5044a99b706fd979f27f5 for more explanation of types !
"SaveFile" = wxBitmap save file.
"wxBitmap myBitmap;" = variable in your example.
"wxString myPath(wxGetCwd());" = varibale wxString equivalent : "wxstring myPath; myPath = wxGetCwd(); Returns the path of the app folder in myPath variable. wxString myPath is variable type wxString wxGetCwd() return path app folder. wxString myPath(wxGetCwd()); is path for app folder sets in myPath variable!
example complete:
wxString myPath(wxGetCwd());
wxBitmap myBitmap;
myBitmap.SaveFile(localAtual + wxT("//test.png"), wxBITMAP_TYPE_PNG);

Related

How to load CanvasSvgDocument from file?

In a C++/winrt project I have a large number of small svg resources to be loaded from file. Since it would be slow to reload them all from disk at each CreateResources event from the CanvasVirtualControl I have loaded them in advance and stored the data for each in an array. When CreateResources happens my intent is to load a CanvasSvgDocument for each of these by using the CanvasSvgDocument method LoadFromXml(System.string). However, If I create an svgDocument using the resourcecreator, I get an invalid argument crash when calling LoadFromXml(). The resourceCreator argument looks right (VS preview 6 now allows me to see local variables!) and the xml data string argument looks like the valid svg data, so my best guess about the crash is that the data string is the wrong format. The file data is UTF-8. If I convert that to a std::wstring as I must for the LoadFromXml argument can it still be understood as byte data?
For example, I create the std::wstring this way, given a pointer to unsigned char file data and its length in bytes:
m_data_string = std::wstring(data, data + dataLength);
When CreateResources is triggered that datastring is referenced this way:
m_svg = CanvasSvgDocument(resourceCreator);
m_svg.LoadFromXml(resourceCreator, m_data_string);
But LoadFromXml crashes with that invalid parameter error. I see that the length of the data string is correct, but of course that is the number of characters, not the actual size of the data. Could there be a conflict between the UTF-8 attribute in the svg and the fact that it is now recorded as 16-bit characters? If so, how would one load an xml document from such data?
[Update] with the suggestion that I use winrt::to_hstring. I read the unsigned char data into a std::string,
std::string cstring = std::string("");
cstring.assign(data, data + dataLength);
Then I convert that:
m_data_string = winrt::to_hstring(cstring);
And finally try to load an svg as before:
m_svg.LoadFromXml(resourceCreator, m_data_string);
And it crashes as before. I notice that in the debugger that converted string in neither case appeared to be gibberish - in both cases it read in the debugger as the expected svg data. But if this hstring is wide chars wouldn't that be a conflict with the attribute in the svg that identifies it as UTF-8?
[Update] I'm starting to wonder if anyone has ever used CanvasSvgDocument.Draw() to draw an svg loaded from a file. The files are now loading without crashing without any change to their internal encoding reference. But - they won't draw. These files - 239 of them - are UTF-8, svg 1.1, and they display nicely if opened in Edge or any browser. But if I load the file data to an hstring, create a CanvasSvgDocument and then use CanvasSvgDocument.LoadFromXml to load them, they do not draw when called by CanvasSvgDocument's draw method. Other drawing of shapes, etc. works fine during the drawing session. Here is what could be a hint: If I call GetXML() on one of these svgs after it is loaded, what is returned is just this:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg>
That is, the drawing information is not there. Or is this the full extent of what GetXml() is meant to return? That wouldn't seem useful. So perhaps CanvasSvgDocument.LoadFromXml(ResourceCreator, String) doesn't actually work yet?
So I'm back to asking again: is there a way to load a functional CanvasSvgDocument from file data?
My first answer here was wrong: the fault in my code above is that LoadFromXml() is a static method, and someone pointed out to me elsewhere, I was discarding the returned result. It should be theSvg = CanvasSvgDocument::LoadFromXml(string).
Having corrected that, I'm back to the problem of loading UTF-8 data in a method whose argument is a wide-character string. Changing the internal reference to UTF-16 doesn't help after all. Loading the svg with CanvasSvgDocument::LoadAsync(filestream) works, but if I want to load these without re-accessing the disk I will need to find a way to make RandomAccessFileStream from a buffer of bytes and then use LoadAsync. I think. Unless there is some other way to make LoadFromXmL() work - at present it fails with an invalid argument error.

How to disable Spacemacs logo from splash screen?

I want to remove the image because it unnecessarily takes space. I've tried fancy-splash-image nil but it didn't work.
What should I place in my .spacemacs (or wherever) and in which part.
There's a variable called dotspacemacs-startup-banner that you can set at your initialisation file in order to remove the banner.
Your initialisation file is either ~/.spacemacs or ~/.spacemacs.d/init.el. There you'll find a function called dotspacemacs/init which contains a list of variables and their values (with an explanation what each of them do), you just need to find dotspacemacs-startup-banner and replace its value to nil.
Here is the full documentation of the variable for the sake of completeness
dotspacemacs-startup-banner is a variable defined in
‘core-dotspacemacs.el’. Its value is ‘official’
Documentation:
Specify the startup banner. Default value is
‘official’, it displays the official spacemacs logo. An integer value
is the index of text banner, ‘random’ chooses a random text banner in
‘core/banners’ directory. A string value must be a path to a .PNG
file. If the value is nil then no banner is displayed.

wxFileDialog always returns an empty string ""

I am not 100% sure if this is the right place to ask but I have a problem with wxFileDialog. It always returns an empty string ""
wxFileDialog* openFileDialog = new wxFileDialog(
this,
_("Open"),
wxEmptyString,
wxEmptyString,
"Vocab files (*.vocab)|*.vocab",
wxFD_,
OPEN|wxFD_FILE_MUST_EXIST);
if (openFileDialog->ShowModal() == wxID_OK)
{
wxString path = openFileDialog->GetPath();
I haven't got the slightest clue as to why but I checked a few tutorials such as this one: http://wiki.wxwidgets.org/Writing_Your_First_Application-Common_Dialogs
and of course the manual but I only found that in the case that the user presses cancel (which I am not :) ) GetPath(); returns a "".
I am using gcc, code blocks, wxWidgets 2.9.5 and run windows 7
Thank you for your input.
There is nothing wrong in the code you show (not counting the unnecessary creation of the dialog on the heap, but this inefficient and inconvenient, not wrong). So either there is something wrong in your build of wxWidgets, or there is something catastrophic happening elsewhere in your program. To find out what it is, build and run the dialogs sample included in wxWidgets and use the file open dialog in it. If it works there, then at least your build of wxWidgets is sound.

How to manage messages in a xcode project?

I'm a newbie in objective c.
I want to know what's the most common way to handle messages(or string format) in a xcode project.I mean, to put all the message strings or formats in one file to manage it easily.
Could anyone give me some advice??
Thanks~
Have you looked at localization options? It is usually a good idea to prepare your app or program for internationalization. The way this works is to have a file Localizable.strings where you have the exact text defined for each "text macro". The strings files (you have a version for each language) are in a very simple format:
// in en.lproj
"Hello" = "Hello, World!";
// in de.lproj
"Hello" = "Hallo, Welt!"
Just make sure in your code you consistently use this format for literal strings that are displayed anywhere in your user interface:
label.text = NSLocalizedString(#"Hello", #"Optional comment");

Issues getting all data from an image file using Lua io.read('*a')

I'm trying to get all the data from image file (jpg/jpeg/gif/png/bmp etc.) use Lua's io.read() function, but I'm not having much luck as it only seems to read a small piece of the data.
As a side note all plain text files are being read just fine, so I'm assuming that the problem is with character encoding or some such thing.
Example:
local data
local fileHandle
fileHandle = io.open ( 'pic.jpg')
data = fileHandle:read('*a')
print(data)
If you're on Windows, open file as binary: io.open('pic.jpg', 'rb').
Also it is a good idea to wrap io.open() in assert() to catch errors (or do handle them otherwise, of course).