2007-06-14

VFPPaint - Flexible Drawing and Paint utility with GdiPlus X





sometimes users need to make some basic modifications in images that are part of the application, and it is not comfortable for them too have to look for files, choose places to save, etc... in the vast majority of cases, ms-paint does the job, but i always needed it to be customized... and i couldn't.


after being challenged by frank cazabon in a foxite thread, i finally took the courage to create my own "paint" application, using gdi+.


vfppaint works much like mspaint, and creates a canvas that permits you to draw whatever you want with the mouse.


it's just one single 50k scx file that does all the job, in partnership with the gdiplusx library.





important
requires vfp9 and gdiplusx to run. 
the latest stable version of gdiplusx is dated 11th may 2007 - alpha 0.8a. please make sure that you have the latest version, because vfppaint uses some functions that were added recently.
http://www.codeplex.com/vfpx/wiki/view.aspx?title=gdiplusx&referringtitle=home



when you run vfppaint.scx it will ask you to select the folder where gdiplusx library is located.



features:


- draw points, rectangles lines and ellipses with the mouse.


- text drawing, choose any font, size and style, and it will appear at the place that you click on the image. (drag and drop to choose the best place)


- choose any color, from the palette or directly from the loaded image or canvas and select the pen width that you want to draw.


- select the shape or type of drawing in the graphical option buttons, and then go to the canvas (image object) and click the left mouse button.


- drag and drop is available for rectangles, lines and ellipses.


- basic undo features


- rotate and flip images


- resizing images


- printing and saving images


 


basic commands:

















































































load image to canvas
save image in desired image format
print image
undo last changes
pick color from palette
pick color from canvas
clear entire canvas with selected color
rotate left
rotate right
flip image horizontally
flip image vertically
draw points
draw rectangle
draw ellipse
draw line
fill rectangle
fill ellipse
draw string
resize image
select font, size and type


 


all images are generated without disk access, using the new pictureval property of the image control. for this specific case, i didn't use the imagecanvas that ships with gdiplusx because i needed some extra customization. after the latest release of gdiplusx, getting the pictureval property of an image has became very simplified, with the new methods added to the image class - getpictureval and getpicturevalfromhbitmap.


as sometimes we need to work with an image that is bigger than our screen,  the drawing canvas was put in a "in toplevelform" that has scrollbars.


another cool feature is the "undo" possibilities. vfppaint stores the previous bitmap in a cache. this can be improved too, maybe you need to "undo" in higher level. for this, very few code is needed.


when drawing on the canvas, try dragging and dropping the objects. for this, the "undo" feature was highly used, because the shape is drawn, and when the user moves the mouse, it restores the original image from the buffer and draws again in the new position.



 


when a big sized image is loaded, first it asks if the canvas needs to be resized.



scrollbars appear in the image to help dealing with it. in a first moment, i thought of using the very nice ctl32 scrollable container from carlos aloatti and malcolm greene, but i gave up because i needed the pictureval property, that is present only in the default image control. so, there are currently 2 forms in the screenshot below. one is a "in toplevel" form that contains just one image object, and resides in the main vfppaint form. the other form is a "toplevel form". the image object from the "child form" changes its size automatically, depending on the image dimensions. when this object is resized, the child form automatically resizes itself, and shows and adjusts the scrollbars if needed.



 


resizing sample:



 


vfppaint also accepts that you pass an image file as a parameter. this way, you'll be able to open the form loading automatically the desired image to edit. run the form like this:


do form vfppaint with "eyes.gif"


in case you pass a gif image as a parameter, it will be automatically converted to 24bpp. that's because gifs are indexed images. a classic example of indexed images are monochrome. pure monochrome images use only 1 bit per pixel. so, in just one byte you can store information of 8 pixels ! in the case of gifs, they are usually 8 bits per pixel, so in one bit we can have a value that ranges from 0 to 255 - that's exactly the quantity of colors supported by gifs ! unfortunately, the redistributable version of gdi+ has a limitation when working with images created in indexed pixel formats, such as 1bppindexed (0x00030101), 4bppindexed (0x00030402) and 8bppindexed (0x00030803). if you try to draw on this kind of images you'll always receive an error message when you'll create the graphics object, that permits to you to draw on the image. more detailed info about this can be found in this post: drawing on gifs or indexed pixel format images with gdi+  http://weblogs.foxite.com/vfpimaging/archive/2006/03/18/1302.aspx . that's why gifs are converted to a 24bpp format before initializing the painting possibilities.



this still has a lot that can be improved, like adding special effects, such as brightness, contrast, hue adjustments, cutting and pasting image portions, saving and retrieving images or pieces of image in the clipboard, etc.


but the main thing is that this totally customizable. the more important in this form is the technique that was used, and you'll see that there's not too much code there.


this still needs to be more tested. feel free to call me if you find any problems or have suggestions. maybe some of your needs can be of interest to be added to vfppaint, and i'll be happy to improve it.


any feedback is very welcome!


 






download


http://weblogs.foxite.com/files/vfpimaging/vfppaint/vfppaint.zip


17 comments:

  1. Simple brilliant, man you really deserve to become a MVP


    Thanks a lot

    ReplyDelete
  2. Sensational,  

    congratulations Caesar!  

    With your techniques always improving and collaborating with us.  

    I am your fan.  

    Thanks

    ReplyDelete
  3. WOW! You have really outdone yourself with this one. Great Job!!!

    ReplyDelete
  4. "In a first moment, I thought of using the very nice CTL32 scrollable container from Carlos Aloatti and Malcolm Greene, but I gave up because I needed the PictureVal property, that is present only in the default image control."

    Cesar:

    You can drop a default image control inside the ctl32_scontainer, check the sample forms included with the project.

    Any doubts do not hesitate to contact me. Carlos
    Carlos,
    I must confess that I didn't investigate the necessary your Ctl32 classes.
    The possibility of dropping an image control directly to the container will solve an important problem that VFPPaint has, that it needs to be in a TopLevel form and cannot be modal. Thanks very much for your support, and all the precious stuff that you provided in your Ctl32 classes.
    Would it be possible to redistribute these classes with VFPPaint?
    Muchas Gracias !
    Saludos
    Cesar

    ReplyDelete
  5. My friends,
    Thanks very much for visiting this blog, testing and providing really valious suggestions.
    Thanks also for your kind words and support.

    ReplyDelete
  6. Cesar:

    You can include any of the ctl32 files in anything you please, they are free to use for any purpose.

    Also, the ctl32_scontainer has a nice zoom-in / zoom-out feature for child image controls already built in, the only thing missing is the code the keep the zoomed image centered where the mouse cursor is placed, maybe you can fill that gap.

    The zoom step values I copied from a paint program, from 1% to 3200 % IIRC.
    Zooming is achieved using CTRL+MouseWheel and the ctlZoom property holds the value of the present zoom level, so you can even display it in the caption or somewhere. (How about adding a ctl32_statusbar while you are at it?)

    You can restore zoom to 100% by calling the ctlRestoreSize method or double clicking in the image.

    Also check the samples on how to refresh the scrollbars size if you resize the image control, you can even add the image control dinamically.

    Just be shure to download the latest version of the class here:

    http://www.ctl32.com.ar/files/ctl32_2006xxxx.zip

    I will be updating all of the ctl32 classes in at most 15-20 days, new classes are coming too.

    If you need any help, contact me at my email address calloatti at gmail.com

    Thinking about this, you/we could make this app a VFPx projects showcase app! Count me in if you decide to do so, I will find the time to pitch in somehow.

    Carlos
    Hi Carlos,
    Thanks very much for the clear explanations and ideas. I hope to deal with the scrollable container this weekend.
    >>Thinking about this, you/we could make this app a VFPx projects showcase app! Count me in if you decide to do so, I will find the time to pitch in somehow.
    That would be great ! Just let me get more familiarized with the scrollable container, and add some new stuff regarding images (cut/paste, to/from clipboard, drawing curves...).
    For sure this can grow and become a great postcard for VFPX. As soon as I finish these modifications, I hope to get in direct contact with you.
    Regards
    Cesar

    ReplyDelete
  7. Muy Interesante

    gracias por la colaboracion

    ReplyDelete
  8. Cesar, I linked to your file from our Download page (http://www.foxite.com/downloads/default.aspx?id=168). If you ever post updates of VFPPAINT, please post it to the same location and filename so the download link from the main site continues to work. Thanks.
    Thanks Eric,
    I hope to send some updates to VFPPaint, using some other CTL32 controls from Carlos Aloatti. Emerson Reed is also interested in adding some features here. So, this has the possibility to grow and to become a very interesting project!
    Regards
    Cesar

    ReplyDelete
  9. Este articulo esta traducido al español en www.PortalFox.com


    "VFPPaint - Utilitario flexible de Pintura y Dibujo con GdiPlusX"

    http://www.portalfox.com/article.php?sid=2456

    ReplyDelete
  10. wow...you is "The Smart Fox" !

    ReplyDelete
  11. Hi...Very very usefull .... Thanks for give us .... a great tool.

    I made some changes
    1- Add New Button: Create new empty canvas
    2- Add Cut to New button: this buton allows you to create a new image based on selected region. It Cut, create new canvas , paste cuted region and resize de canvas. this is useful when you are cutting portions of images to make new images with it.
    3- Added posiblity of  make n(50 by default) undo. A property was added indicating the desired max undo changes.

    Again. Very thnaks to you.
    Hola Juan Pablo,
    Thanks for the kind words.
    These are good suggestions, I hope to incorporate them in the next version, or maybe you could just send me your modified version?

    ReplyDelete
  12. Hello Cesar.


    Because iam writing a prg for Coin Inventory, i need the possibilty that your vfpaint can create a "panoramic" picture ....This means creating one combinate picture from two coins images(Obverse side +Reverse Side) side by Side.

    also i need the ability to partial zoom a region of the resulting picture and than the ability to store the zoomed region to a separate blob feld.


    Is this possible?

    thanks for your excellent tool.

    ReplyDelete
  13. Hi Mr Caesar thanks a lot to share with us your brilliant software. To be honest I have never done any imaging software before, but  because of you now I can finish 1 project related with imaging by using your software& a bit modification. Thankssss a lot you are very brilliant & helpful. Btw is it possible to add a mirroring function to your software? I just see there is a flip function, but however I need to retain the original image. So what I want is I want to see both the original image and the image after I flip. I did the mirroring by using get pixel and set pixel, but it takes very long time ? do you have another idea? Is there any way to check the pixel except using the get pixel?


    Thankss a lottt,



    Sharon

    ReplyDelete
  14. It's great utility, many thanks. I have a question - is there a method/possibility to save the painted curve points?

    ReplyDelete
  15. Hello Sir, Its great to have a painting tool as I needed urgetly, but Sir I want some extended funtionality in it, i.e. I want to import three to four images in the painting area and resize it after importing it, moreover I want to enter text in the area out of images.  Let me explain it, on the left side here will be three-four images aligned to the left side of the canvas area and on te right side I want to write some text to explain aboit the images and also ity sould be save as it is being done in this tool.  It will be a geat help it you can please, please!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!111.

    Sanjay Bhasin
    Hi Sanjay,
    This tool is completely open source, and was intended to serve as a sample, showing you all the new possibilities that GDi+X brings to us. Feel free to change any code that you need.
    Cesar

    ReplyDelete
  16. Hello Sir, Its great to have such a painting tool in my VFP application as a lot of things are already solved using this tool.  One thing I am unable to modify in it which is, whenever I save the image in this tool as JPG file its resolution is very low i.e. when we open the saved image in Paint of Windows it comes out to be of 96X96 resolution and I want it to be atleast 150X150, please help me solve this, it will be a great help and I will be very very thankfull to you sir.
    Hi !
    Thanks for the kind words.
    Well to change the JPEG quality, you have to adapt some code in VFPPAINT. Please study the contents of this old post, and make the needed changes in the sources. http://weblogs.foxite.com/vfpimaging/archive/2007/02/22/3352.aspx
    Hope that helps !
    Good luck

    ReplyDelete