Page 1 of 1

draw image to a windows handle?

Posted: 2008-04-08T02:50:43-07:00
by Bob2
Hello,

I use imageMagick dlls in c programming under windows, and I'd like to know how I could draw an image (or a part of) into a windows window, or into a canvas Handle.. ?

Thank you very much in advance

Best regards
Bob

Re: draw image to a windows handle?

Posted: 2008-04-09T06:56:27-07:00
by Bob2
It's impossible with imageMagick??

Actually, I would like to create a windows application that could display imageMagick images into a window. That's why I would need direct drawing functions, or copyrect functions, so as to take fastly a rectangle from my image in memory, and copy it into my screen buffer..

How could I do?

Thank you very much in advance.

Best regards
Bob

Re: draw image to a windows handle?

Posted: 2008-04-09T09:00:51-07:00
by el_supremo
ImageMagick has a ImageToHBITMAP function which returns a bitmap handle from an Image pointer.
You will need:

Code: Select all

#include <magick/nt-feature.h>
and then:

Code: Select all

hbmp = ImageToHBITMAP((Image *)image);
You can then use this handle to display the image.
Pete

Re: draw image to a windows handle?

Posted: 2008-04-10T00:11:08-07:00
by Bob2
Hi Pete,

thanks a lot for your reply! That function is interesting, but the problem is that if I'm using an image bigger than the available RAM memory (which is exactly what I wanted to use imageMagick for), as soon as I will convert my ImageMagick into a bitmap, it will crash.. So that's not a possible way to display it.

Any other clue?

Thanks a lot in advance.
Bob

Re: draw image to a windows handle?

Posted: 2008-04-10T09:03:59-07:00
by el_supremo
I know very little about how to display images with windows.
I would guess that one way would be (if you're using MagickWand) to use MagickGetImageRegion to extract a new wand with the region of interest, convert that wand to HBITMAP and then display it. But it's probably going to be slow.
If you can write image data directly to the window you could try using a pixel iterator (e.g. NewPixelRegionIterator) to extract the region you want.

Pete

Re: draw image to a windows handle?

Posted: 2008-04-11T00:37:16-07:00
by Bob2
Hi Pete !
thanks again.

OK, both ideas don't seem to me very efficient, but if there isn't any other way to display imageMagick images, I will have to do that..
If I understand well, ImageMagick is not really suitable to handle images as a main image container in an application.

Thank you by the way for your answer.
Bob

Re: draw image to a windows handle?

Posted: 2010-07-25T19:23:36-07:00
by anotherprogrammer123
Hi, in case it helps, to display images while debugging, I have:
1. Compress them losslessly to a temporary .tif file
2. Open this file in Windows Paint using system("mspaint ~temp.tif")
3. Delete the file from the hard drive

This has worked nicely for me. Note that the program is paused until you close windows paint!