EMF problem?

Everything else that doesn't fall into one of the other PB categories.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

EMF problem?

Post by srod »

Hi,

I've had this sort of thing before with Enhanced MetaFiles, but solved the previous problem. This one is proving very puzzling indeed!!!

Basically, create a small EMF containing an image and some text. No problem. 'Play' this EMF into a larger EMF and generally - no problem.

However, the following code plays the smaller memory based EMF into a larger disc based one 3 times (one under the other). The first two copies appear fine. In the third one, however, the image disappears leaving just the text!!! This one has me stumped!

Code: Select all

LoadImage(1, "header.bmp")  ;Use your own image.

hdc = CreateEnhMetaFile_(0, 0, 0, 0)
If hdc
  ;Create a small memory based EMF with a copy of the image and some text.
    hBrush = GetStockObject_(#WHITE_BRUSH)
    SetRect_(rc.RECT, 0, 0, 1000, 1000)
    oldBrush = SelectObject_(hdc, hBush)
    Rectangle_(hdc, 0, 0, 1000, 1000)
    hdcImage = CreateCompatibleDC_(hdc)
    oldImage = SelectObject_(hdcImage, ImageID(1))
      StretchBlt_(hdc, 0, 0, 1000, 400, hdcImage, 0, 0, ImageWidth(1), ImageHeight(1), #SRCCOPY)
      TextOut_(hdc, 0,500,@"HELLO!",6)
    SelectObject_(hdcImage, oldImage)
    SelectObject_(hdc, oldBrush)
    DeleteDC_(hdcImage)
    hEMF = CloseEnhMetaFile_(hdc)

  ;Render to a larger filebased emf.
    If hEMF
      hdc = CreateEnhMetaFile_(0, @"test.emf", 0, 0)
      hBrush = GetStockObject_(#GRAY_BRUSH)
      SetRect_(rc.RECT, 0, 0, 1000, 3000)
      FillRect_(hdc, rc, hBrush)
      SetRect_(rc.RECT, 0, 0, 1000, 500)
      PlayEnhMetaFile_(hdc, hEMF, @rc) 
      SetRect_(rc.RECT, 0, 500, 1000, 1000)
      PlayEnhMetaFile_(hdc, hEMF, @rc) 
      SetRect_(rc.RECT, 0, 1000, 1000, 1500)  ;Only the text appears here!!!!!! Where is the image?
      PlayEnhMetaFile_(hdc, hEMF, @rc) 
      hEMFPage = CloseEnhMetaFile_(hdc)
      DeleteEnhMetaFile_(hEMFPage) 
    EndIf
    DeleteEnhMetaFile_(hEMF) 
EndIf
To run the code, provide your own bitmap, run the program and have a look at the resulting disc file "test.emf" and you should see what I mean!!! If we play the smaller EMF into the larger and position it beyond a certain limit (vertically) then the bitmap image does not appear to get copied!

I've tried resetting view-point origins etc. but to no avail!

Any ideas what is going on here?

Thanks.
I may look like a mule, but I'm not a complete ass.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

If I understood correctly then in the third block the image is not drawn, right?

I just tested the code with another image from the PB folder.

This is what I got: http://www.codedreality.de/tl_files/temp/emftest.jpg

Should it look something like that or is it still wrong?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Yes it should look exactly like that!!!

I've just used the same image as yourself from the PB folder and I still get the problem!!!

Could you please check out the emf produced on my machine and tell me if it looks the same on your machine as the image you produced?

www.purecoder.net/test.emf

Thanks.
I may look like a mule, but I'm not a complete ass.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Nope, the image from the third block is still missing. Weird! :?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

Yet another Vista EMF bug srod?
Windows 7 & PureBasic 4.4
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I've tried on vista and xp on this machine with the same result.

Time to try another computer entirely...
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Right, same problem on my other machine (xp sp3).

@Fluid or Milan or anyone : This problem seems to surface if I play the memory emf 'far enough' down (vertically) the larger file. Perhaps we need to extend the range in order for the problem to surface on your machine.

Would you mind running the following which should place 10 copies of the emf one under the other etc. Are any of these copies missing the image?

Code: Select all

LoadImage(1, #PB_Compiler_Home+"Examples\Sources\Data\Background.bmp")

hdc = CreateEnhMetaFile_(0, 0, 0, 0) 
If hdc 
  ;Create a small memory based EMF with a copy of the image and some text. 
    hBrush = GetStockObject_(#WHITE_BRUSH) 
    SetRect_(rc.RECT, 0, 0, 1000, 1000) 
    oldBrush = SelectObject_(hdc, hBush) 
    Rectangle_(hdc, 0, 0, 1000, 1000) 
    hdcImage = CreateCompatibleDC_(hdc) 
    oldImage = SelectObject_(hdcImage, ImageID(1)) 
      StretchBlt_(hdc, 0, 0, 1000, 400, hdcImage, 0, 0, ImageWidth(1), ImageHeight(1), #SRCCOPY) 
      TextOut_(hdc, 0,500,@"HELLO!",6) 
    SelectObject_(hdcImage, oldImage) 
    SelectObject_(hdc, oldBrush) 
    DeleteDC_(hdcImage) 
    hEMF = CloseEnhMetaFile_(hdc) 

  ;Render to a larger filebased emf. 
    If hEMF 
      hdc = CreateEnhMetaFile_(0, @"test.emf", 0, 0) 
      hBrush = GetStockObject_(#GRAY_BRUSH) 
      SetRect_(rc.RECT, 0, 0, 1000, 10000) 
      FillRect_(hdc, rc, hBrush) 
      For i = 0 To 9
        SetRect_(rc.RECT, 0, i*500, 1000, (i+1)*500) 
        PlayEnhMetaFile_(hdc, hEMF, @rc) 
      Next
      hEMFPage = CloseEnhMetaFile_(hdc) 
      DeleteEnhMetaFile_(hEMFPage) 
    EndIf 
    DeleteEnhMetaFile_(hEMF) 
EndIf 
Thanks.
I may look like a mule, but I'm not a complete ass.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

First 3 are shown, the rest are blank. :o
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Fluid Byte wrote:First 3 are shown, the rest are blank. :o
Thanks. :)

This means that either there is something about EMF's which I do not understand, or there is a bug here in Windows itself.
I may look like a mule, but I'm not a complete ass.
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

Same here - 3 are displayed correctly and the last 7 ones are missing :o
Okay, this rules out a machine dependant problem, either it's the code or a bug indeed...
Windows 7 & PureBasic 4.4
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I came across it in some very complex code of mine and was surprised to find that I could replicate the problem so easily.

I am just trawling through as much info on EMF's as I can find right now to see if there is anything I am missing? If not then I will just have to find some workaround. I will be interested to enumerate all the records within the large EMF to see if I can find just eactly what is amis?
I may look like a mule, but I'm not a complete ass.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Windows 95: PlayEnhMetaFile is subject to the limitations of the Windows 95 GDI. For example, Windows 95 supports only 16-bit signed coordinates. For records that contain 32-bit values, Windows 95 fails to play the record if the values are not in the range -32,768 to 32,767.
Maybe they forgot to fix that for Vista?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

We have no problem with text and other gdi elements Trond - it's just bitmaps and this only occurs when playing an EMF containing such images into another EMF. It's all very strange.
I may look like a mule, but I'm not a complete ass.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

This was regarding PlayEnhMetaFile(). You don't use that for bitmaps and text, right?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Sure I do. The memory based EMF in the code above has images and text added to it which is no problem. As I say it's when playing this emf into another emf that problems arise with the images for some reason.
I may look like a mule, but I'm not a complete ass.
Post Reply