draw image to a windows handle?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
Bob2

draw image to a windows handle?

Post 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
Bob2

Re: draw image to a windows handle?

Post 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
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: draw image to a windows handle?

Post 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
Bob2

Re: draw image to a windows handle?

Post 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
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: draw image to a windows handle?

Post 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
Bob2

Re: draw image to a windows handle?

Post 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
anotherprogrammer123
Posts: 36
Joined: 2010-02-21T18:02:40-07:00
Authentication code: 8675308

Re: draw image to a windows handle?

Post 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!
Post Reply