Quantcast

FXCanvas -> Image

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

FXCanvas -> Image

Surya Kiran Gullapalli
Hi,
I'm having some drawing drawn on a canvas (FXCanvas). I'd like to
convert it to a image file say png. how can this be done.
thanks in advance,
Surya











-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FXCanvas -> Image

Jeroen van der Zijp
On Saturday 14 February 2004 03:43 am, Surya Kiran Gullapalli wrote:
> Hi,
> I'm having some drawing drawn on a canvas (FXCanvas). I'd like to
> convert it to a image file say png. how can this be done.

Assuming something is visible in FXCanvas, you need to use an FXImage:


    if(FXCALLOC(&data,FXColor,canvas->getWidth()*canvas->getHeight())){
      FXImage image(getApp(),data,IMAGE_KEEP,canvas->getWidth(),canvas->getHeight());
      image.create();
      {
        FXDCWindow dc(image);
        dc.setFunction(BLT_SRC);
        dc.drawArea(canvas,0,0,canvas->getWidth(),canvas->getHeight());
      }
      image.restore();

      // Now we got the pixels in the client-side buffer of FXImage
      ...
      do something with them
      ...

      // Ditch the pixels
      FXFREE(&data);
      }


Hope this helps,


                Jeroen



--
+----------------------------------------------------------------------------+
| Copyright (C) 23:50 12/11/2003 Jeroen van der Zijp.   All Rights Reserved. |
+----------------------------------------------------------------------------+



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FXCanvas -> Image

Surya Kiran Gullapalli
This did help me to some  extent,
but, when any window overlaps my canvas, the final image i'm getting is an incomplete image, in the sense, that the final image has blank area which the overlapping window occupies.

I'm opening a window, so that the user can enter a filename to save, and after the user enters the name, i'm closing the dialogbox (getApp->stopModal (this, TRUE)) and then writing the image. but some how the dialog box does not close till the writing is over.

how can i solve this.

Thanks in advance,
Surya

jeroen wrote:
On Saturday 14 February 2004 03:43 am, Surya Kiran Gullapalli wrote:
  
Hi,
I'm having some drawing drawn on a canvas (FXCanvas). I'd like to
convert it to a image file say png. how can this be done.
    

Assuming something is visible in FXCanvas, you need to use an FXImage:


    if(FXCALLOC(&data,FXColor,canvas->getWidth()*canvas->getHeight())){
      FXImage image(getApp(),data,IMAGE_KEEP,canvas->getWidth(),canvas->getHeight());
      image.create();
      {
	FXDCWindow dc(image);
	dc.setFunction(BLT_SRC);
	dc.drawArea(canvas,0,0,canvas->getWidth(),canvas->getHeight());
      }
      image.restore();

      // Now we got the pixels in the client-side buffer of FXImage
      ...
      do something with them
      ...

      // Ditch the pixels
      FXFREE(&data);
      }


Hope this helps,


		Jeroen



  

--
~/.signature.html
Anyone can do any amount of work provided it isn't the work he is supposed to be doing at the moment.
 -- Robert Benchley

Surya Kiran Gullapalli,         Ph. (OFF) (020) 4142624
Engineer - Development,         Ph. (RES) (020) 5620 2326
Fluent India Pvt. Ltd.,
Pune, India













Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FXCanvas -> Image

Jeroen van der Zijp
On Saturday 14 February 2004 08:06 am, Surya Kiran Gullapalli wrote:
> This did help me to some  extent,
> but, when any window overlaps my canvas, the final image i'm getting is
> an incomplete image, in the sense, that the final image has blank area
> which the overlapping window occupies.

Yes, you can only read back the pixels which are actually stored
in the frame buffer.

Perhaps you need to draw your picture in the image instead of the
window, and then BLIT the image to the window.  This way, you always
have a ready-made drawing in the image, and it will be easier to
redraw in most cases (you only need to redraw the image if you
need to display different information).  When you simply service
an exposure (paint message), you can just BLIT from the image.

Barring that, try and write your drawing function as a function
which takes a FXDC& parameter.  Then you can draw into either
the window or image as the need arises.

> I'm opening a window, so that the user can enter a filename to save, and
> after the user enters the name, i'm closing the dialogbox
> (getApp->stopModal (this, TRUE)) and then writing the image. but some
> how the dialog box does not close till the writing is over.

My recommendation is to grab the image first, then fire up the dialog.

Look at what ShutterBug does....

        - Jeroen


--
+----------------------------------------------------------------------------+
| Copyright (C) 23:50 12/11/2003 Jeroen van der Zijp.   All Rights Reserved. |
+----------------------------------------------------------------------------+



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click


Loading...