Blitting Image to windows device context


#1

It works!
Juce stylee ActiveX components! Wooo!

Jules (or anyone), is there a better way to do it than this?..

	for ( int x = 0; x < _image->getWidth(); ++x )
		for ( int y = 0; y < _image->getHeight(); ++y )
			SetPixel( di.hdcDraw, x + rc.left , y + rc.top, (COLORREF)*(_image->getPixelPointer( x, y )) );

I’m thinking hack juce to get hold of raw buffer then memcpy?

k


#2

good grief, it’ll take hours to do it a pixel at a time.

The Juce image class can actually wrap a HBITMAP, so you can blit it directly - check out the code in juce_win32_windowing.cpp that does the repainting, because that just creates an image, draws into it, then blits it to the window.


#3

[quote=“jules”]good grief, it’ll take hours to do it a pixel at a time.

The Juce image class can actually wrap a HBITMAP, so you can blit it directly - check out the code in juce_win32_windowing.cpp that does the repainting, because that just creates an image, draws into it, then blits it to the window.[/quote]

Yes yes. Just chucked that in before looking for something zippier.

Anyway, can’t get it working. are we talking createSystemNativeImage()? (or whatever its called) Tried that with a hack to get hold of the WindowsBitmapWrapper. Nope. Tried setting up BITMAPINFO (or whatever it is) manually and using getPixelPointer(0,0) to get the buffer but I’m just getting solid black where me graphics should be!

Don’t know if I’m going about it wrong or fucked up a setting.

I can see why you wrote a JDK-alike crossplatform library Jules.


#4

Hmm - it’s a bit fiddly.

Create the image with Image::createSystemNativeImage()

Make a copy of the definition of the WindowsBitmapWrapper struct from win32_windowing.cpp in your code

Cast the image’s getBitmapHandlePointer() to a WindowsBitmapWrapper, and use the HBITMAP inside.


#5

[quote=“jules”]Hmm - it’s a bit fiddly.

Create the image with Image::createSystemNativeImage()

Make a copy of the definition of the WindowsBitmapWrapper struct from win32_windowing.cpp in your code

Cast the image’s getBitmapHandlePointer() to a WindowsBitmapWrapper, and use the HBITMAP inside.[/quote]

That’s EXACTLY what I did. Must have fucked up somewhere. I’ll have another look…


#6

maybe in your code there’s a different struct member alignment for the WindowBitmapWrapper?

Try hacking a new method into juce_win32_windowing.cpp code that does the blit, and call that from your code.


#7

Woaw! Gotta raise a green flag!
struct alighnment?
what?
never heard.
will try your hack and look into WTF struct alignment

c


#8

I mean structure packing - “#pragma pack” and all that jazz.


#9