wxImage ConverTo wxBitmap how to ?
wxImage ConverTo wxBitmap how to ?
Sry,my English isn't very well.
I have problem:
I want convert a wxImage to wxBitmap
I tried
wxImage img;
wxBitmap bmp = (wxBitmap)img;
this wrote Seg Fault,I don't understand,early this was good,now isn't.
App is output this:
(process:23652): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:23652): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:23652): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:23652): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:23652): GLib-GObject-CRITICAL **: g_type_add_interface_static: assertion `G_TYPE_IS_INSTANTIATABLE (instance_type)' failed
(process:23652): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:23652): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:23652): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:23652): GLib-GObject-CRITICAL **: g_object_new: assertion `G_TYPE_IS_OBJECT (object_type)' failed
Backtrace is here:
#0 0xb74f9079 in gtk_window_new () from /usr/lib/libgtk-x11-2.0.so.0
#1 0xb7b17634 in wxGetRootWindow () from /usr/local/lib/libwx_gtk2_core-2.8.so.0
#2 0xb7b1aa71 in wxBitmap::CreateFromImageAsPixmap () from /usr/local/lib/libwx_gtk2_core-2.8.so.0
#3 0xb7b1b798 in wxBitmap::CreateFromImage () from /usr/local/lib/libwx_gtk2_core-2.8.so.0
#4 0x0804f8ed in LoadImages (this=0xbfce29e0, TemplateImg=@0xbfce2a88, ObservationImg=@0xbfce2a84) at /home/evil/wxWidgets-2.8.7/include/wx/gtk/bitmap.h:65
#5 0x0804e44c in Load::initFromDatFile (this=0xbfce2af0) at ../Load.cpp:244
#6 0x0804f103 in Load (this=0xbfce2af0, filename=@0xbfce2b2c) at ../Load.cpp:15
#7 0x0804fb1b in main (argc=Cannot access memory at address 0x0
) at ../Main.cpp:9
and I tried
wxBitmap bmp(img); <--this isn't good.
Documentation wrote,I don't use ConvertToBitmap.
I use wxWidgets 2.8.7 and 2.8.8
I haven't more idea.
Pleas help me.
Thanks Evil
I have problem:
I want convert a wxImage to wxBitmap
I tried
wxImage img;
wxBitmap bmp = (wxBitmap)img;
this wrote Seg Fault,I don't understand,early this was good,now isn't.
App is output this:
(process:23652): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:23652): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:23652): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:23652): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:23652): GLib-GObject-CRITICAL **: g_type_add_interface_static: assertion `G_TYPE_IS_INSTANTIATABLE (instance_type)' failed
(process:23652): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:23652): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:23652): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:23652): GLib-GObject-CRITICAL **: g_object_new: assertion `G_TYPE_IS_OBJECT (object_type)' failed
Backtrace is here:
#0 0xb74f9079 in gtk_window_new () from /usr/lib/libgtk-x11-2.0.so.0
#1 0xb7b17634 in wxGetRootWindow () from /usr/local/lib/libwx_gtk2_core-2.8.so.0
#2 0xb7b1aa71 in wxBitmap::CreateFromImageAsPixmap () from /usr/local/lib/libwx_gtk2_core-2.8.so.0
#3 0xb7b1b798 in wxBitmap::CreateFromImage () from /usr/local/lib/libwx_gtk2_core-2.8.so.0
#4 0x0804f8ed in LoadImages (this=0xbfce29e0, TemplateImg=@0xbfce2a88, ObservationImg=@0xbfce2a84) at /home/evil/wxWidgets-2.8.7/include/wx/gtk/bitmap.h:65
#5 0x0804e44c in Load::initFromDatFile (this=0xbfce2af0) at ../Load.cpp:244
#6 0x0804f103 in Load (this=0xbfce2af0, filename=@0xbfce2b2c) at ../Load.cpp:15
#7 0x0804fb1b in main (argc=Cannot access memory at address 0x0
) at ../Main.cpp:9
and I tried
wxBitmap bmp(img); <--this isn't good.
Documentation wrote,I don't use ConvertToBitmap.
I use wxWidgets 2.8.7 and 2.8.8
I haven't more idea.
Pleas help me.
Thanks Evil
-
- Super wx Problem Solver
- Posts: 497
- Joined: Mon Nov 06, 2006 9:58 pm
wxBitmap(const wxImage& img, int depth = -1)
Creates bitmap object from the image. This has to be done to actually display an image as you cannot draw an image directly on a window. The resulting bitmap will use the provided colour depth (or that of the current system if depth is -1) which entails that a colour reduction has to take place.
When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube created on program start-up to look up colors. This ensures a very fast conversion, but the image quality won't be perfect (and could be better for photo images using more sophisticated dithering algorithms).
On Windows, if there is a palette present (set with SetPalette), it will be used when creating the wxBitmap (most useful in 8-bit display mode). On other platforms, the palette is currently ignored.
Code: Select all
wxImage *yourwxImage = new wxImage(...);
wxBitmap *yourBMap = new wxBitmap(yourwxImage, -1);
Thx for your help,but I tried early this tooFlyingIsFun1217 wrote:wxBitmap(const wxImage& img, int depth = -1)
Creates bitmap object from the image. This has to be done to actually display an image as you cannot draw an image directly on a window. The resulting bitmap will use the provided colour depth (or that of the current system if depth is -1) which entails that a colour reduction has to take place.
When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube created on program start-up to look up colors. This ensures a very fast conversion, but the image quality won't be perfect (and could be better for photo images using more sophisticated dithering algorithms).
On Windows, if there is a palette present (set with SetPalette), it will be used when creating the wxBitmap (most useful in 8-bit display mode). On other platforms, the palette is currently ignored.FlyingIsFun1217Code: Select all
wxImage *yourwxImage = new wxImage(...); wxBitmap *yourBMap = new wxBitmap(yourwxImage, -1);
and now too.
But my app write output :
(process:26380): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:26380): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:26380): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:26380): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:26380): GLib-GObject-CRITICAL **: g_type_add_interface_static: assertion `G_TYPE_IS_INSTANTIATABLE (instance_type)' failed
(process:26380): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:26380): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:26380): GLib-GObject-CRITICAL **: gtype.c:2242: initialization assertion failed, use IA__g_type_init() prior to this function
(process:26380): GLib-GObject-CRITICAL **: g_object_new: assertion `G_TYPE_IS_OBJECT (object_type)' failed
I don't know why ...
I tried debug my app with eclipse ,but
I step by step in my app and unexpectedly it call gtk_window_new() and I don't know why and then crashed my app . I don't use GUI this version,this version is only cmd line version.
Anything idea? somebody ?
Thx Evil
U see the Attachment File ,it is Full BackTrace
- Attachments
-
- full_backtrace.txt
- Full BackTrace of my App
- (4.5 KiB) Downloaded 74 times
-
- Super wx Problem Solver
- Posts: 497
- Joined: Mon Nov 06, 2006 9:58 pm
Since wxImage and wxBitmap are custom types, you cannot typecast as you can with the standard library.
Every try typecasting a char to a wxString? It doesn't work well, does it?
Again, I would suggest trying the method I posted, I can guarantee it will work (the method, not my code).
FlyingIsFun1217
Every try typecasting a char to a wxString? It doesn't work well, does it?
Again, I would suggest trying the method I posted, I can guarantee it will work (the method, not my code).
FlyingIsFun1217
I tried your method,but it wrote was I copy here early ...FlyingIsFun1217 wrote:Since wxImage and wxBitmap are custom types, you cannot typecast as you can with the standard library.
Every try typecasting a char to a wxString? It doesn't work well, does it?
Again, I would suggest trying the method I posted, I can guarantee it will work (the method, not my code).
FlyingIsFun1217
I don't know why ..
I check all step ...doublemax wrote:wxBitmap bmp(img) should work.
use wxImage::IsOk() to check if your wxImage contains any valid data.
How do you create the wxImage object?
If you load it from an external file, check if the loading was successful.
U see this :
Load::Load(wxString filename) {
if (!filename.IsEmpty()) {
if (m_inputfile.Open(filename)) {
wxPrintf(_T("All right, '%s' file open succesful.\n "), m_inputfile.GetName());
//initFromDatFile();
} else {
wxPrintf(_T("ERROR: can't open '%s'\n"), m_inputfile.GetName());
}
}else{
wxPrintf(_T("ERROR: I need minimum one filename!"));
}
}
and sorry for form of code ,It looks badly here
so and :
ImplementOfAlg.m_TemplateImage = new wxImage();
if ( !(*ImplementOfAlg.m_TemplateImage).LoadFile(TemplateImg) ) {
wxLogError(_T("Couldn't load Template Image from '%s'."),
TemplateImg.c_str());
} else {
*ImplementOfAlg.m_TemplateImage =(*ImplementOfAlg.m_TemplateImage).ConvertToGreyscale();
ImplementOfAlg.m_pTemplateColours = (*ImplementOfAlg.m_TemplateImage).GetData();
ImplementOfAlg.m_pTemplateColours = ImplementOfAlg.Thresholding(ImplementOfAlg.m_pTemplateColours, *ImplementOfAlg.m_TemplateImage, 0);
(ImplementOfAlg.m_TemplateImageBitmap)=new wxBitmap(*ImplementOfAlg.m_TemplateImage);
}
I check All ,in all line ,and all case
anything idea ?
do you have an object derived from wxApp, or do you just start your program with main()?
In the latter case you need to initialize the wx library first. Just put this as the first line in main():
In the latter case you need to initialize the wx library first. Just put this as the first line in main():
Code: Select all
wxInitializer initializer;
Use the source, Luke!
I think ,I don't need wxApp.doublemax wrote:do you have an object derived from wxApp, or do you just start your program with main()?
In the latter case you need to initialize the wx library first. Just put this as the first line in main():Code: Select all
wxInitializer initializer;
I just start my program with main().
I tried what,u wrote,but don't change nothing ...
-
- Super wx Problem Solver
- Posts: 497
- Joined: Mon Nov 06, 2006 9:58 pm
Evil85 wrote: and sorry for form of code ,It looks badly here
then please use code tags
you do need to init wx somehow, see the docs and samples...Evil85 wrote:I think ,I don't need wxApp.doublemax wrote:do you have an object derived from wxApp, or do you just start your program with main()?
In the latter case you need to initialize the wx library first. Just put this as the first line in main():Code: Select all
wxInitializer initializer;
I just start my program with main().
I tried what,u wrote,but don't change nothing ...
Okay,but my code is very unfinished ..FlyingIsFun1217 wrote:Maybe post your source, I'm sure this would help quite a bit.
FlyingIsFun1217
I wrote early this app ,but it isn't good OO app,because my menthor say ,I write fast a app ,and I have time now,I rethink all ,and refactoring full code.Early code is running,but not good code style and not OO code ... and it use a libary,but between my app and lib communication was slow,because it was throught file.I make a .so from it lib,but I use it good without communication of file ,I must edit it lib and I make .so.
I see now,I can attachment file only three .
I make a package from my source ... a moment
- Attachments
-
- Program_use_datas.tar.gz
- my program use this files
- (5.55 KiB) Downloaded 114 times
-
- Package.tar.gz
- my Package
- (5.52 KiB) Downloaded 74 times
Last edited by Evil85 on Fri Aug 08, 2008 11:51 pm, edited 1 time in total.
Sry ALL ,I'm begginner here ... I register yesterday (08.08 )Auria wrote:Evil85 wrote: and sorry for form of code ,It looks badly here
then please use code tags
you do need to init wx somehow, see the docs and samples...Evil85 wrote:I think ,I don't need wxApp.doublemax wrote:do you have an object derived from wxApp, or do you just start your program with main()?
In the latter case you need to initialize the wx library first. Just put this as the first line in main():Code: Select all
wxInitializer initializer;
I just start my program with main().
I tried what,u wrote,but don't change nothing ...
Thx warning,I try in the future better write my ploblem
I found this now:
wxWidgets/Image sample /Image.cpp
if ( image.LoadFile( dir + _T("test.png") ) )
my_square = wxBitmap( image );
I tried ,but this isn't good too
somebody, anything ideas?Evil85 wrote:Sry ALL ,I'm begginner here ... I register yesterday (08.08 )Auria wrote:Evil85 wrote: and sorry for form of code ,It looks badly here
then please use code tags
you do need to init wx somehow, see the docs and samples...Evil85 wrote: I think ,I don't need wxApp.
I just start my program with main().
I tried what,u wrote,but don't change nothing ...
Thx warning,I try in the future better write my ploblem
I found this now:
wxWidgets/Image sample /Image.cpp
if ( image.LoadFile( dir + _T("test.png") ) )
my_square = wxBitmap( image );
I tried ,but this isn't good too
not really.
After googling a bit it seems that the 'IA__g_type_init()' error indicates that the GTK part is not initialized properly, but as i work on MSW only, i have no idea why this happens and/or how to fix it.
I don't know if it helps, but i suggest rewriting your code, get rid of main() and use a wxApp instance. Check the "minimal" sample, it shouldn't be much work to do that.
BTW: i assume you're using your program with a X server running. It probably won't work in text mode only.
After googling a bit it seems that the 'IA__g_type_init()' error indicates that the GTK part is not initialized properly, but as i work on MSW only, i have no idea why this happens and/or how to fix it.
I don't know if it helps, but i suggest rewriting your code, get rid of main() and use a wxApp instance. Check the "minimal" sample, it shouldn't be much work to do that.
BTW: i assume you're using your program with a X server running. It probably won't work in text mode only.
Use the source, Luke!