Page 1 of 2

CopyImage problem

Posted: Thu Dec 20, 2007 4:03 am
by MikeB
If I use CopyImage(1, 2) with an image size greater than about 1824 * 1368 it doesn't work. I am trying to copy an image which is 3648 * 2736 (my camera size) and getting nowhere.

Does it require setting a buffer size bigger or something? Or is it just impossible?

Posted: Thu Dec 20, 2007 4:13 am
by netmaestro
How much memory have you got?

Posted: Thu Dec 20, 2007 4:32 am
by citystate
it's a stupid question, but - have you tried CopyImage(2, 1)?

Posted: Thu Dec 20, 2007 6:34 am
by superadnim
up to 8000x8000 you shouldn't have trouble.

To discard coder's fault, try and use variables instead of enumerations for your objects (in this case, image handles).

Example:

Code: Select all

EnableExplicit
DisableDebugger

Define.l myFirstImage, mySecondImage

myFirstImage 		= CreateImage(#PB_Any, 2000,2000)

If StartDrawing( ImageOutput(myFirstImage) )
	
	Box(100,100,1800,1800, #White)
	
	StopDrawing()
EndIf

mySecondImage = CopyImage(myFirstImage, #PB_Any)

If mySecondImage
	
	Define.s szName
	szName	= "C:\temp"+Str(Random(9999))+".bmp"
	SaveImage(mySecondImage, szName)
	
	FreeImage(myFirstImage)
	FreeImage(mySecondImage)
	
	RunProgram(szName)
	Delay(3000)
	DeleteFile(szName)
	
Else
	MessageRequester("Attention", "Something went wrong...")
	
EndIf
End
Works just fine here.
Notice, I assume theres a default application set for the mime type "bmp", also, I'm using a random name because I often have stuff like "temp.bmp" in my C root (for testing cases I almost always use the root...) so, to avoid replacing any of your files I just used a random name. (I could of setup a window and displayed the image, but it's too big)

Replace CreateImage by LoadImage and comment out the drawing lines, should work first hand, if not, let us know.

Posted: Thu Dec 20, 2007 11:08 am
by MikeB
I have 8 Gb of memory so I don't think that is the problem!

If I load an image of 3648 * 2736 as image 1 and then try to CopyImage(1, 2) and show the image I get "Image object not initialised". If I insert ResizeImage (1, ImageWidth(1)*0.5, ImageHeight(1)*0.5) then it works perfectly!

Replace the *0.5 with *0.6 and again it does not work, which is why I said the image could not be greater than 1824 * 1368 or half the original size.

What I am trying to do is change the size by using *0.95 every time I press the "S" key to slowly decrease the size of the image which is displayed under a draggable borderless window with a transparent rectangular region in the middle to show how it could be cropped when printing.

This slightly complex procedure works every time if the image is 1824 * 1368 or less or if I insert a bit that uses ResizeImage (1, ImageWidth(1)*0.5, ImageHeight(1)*0.5) if the image is greater than 1824 * 1368 and the *0.95 if it is that or less. In most cases that is OK as my standard print size for the album is a 1/4 sheet of A4 and so it will be reduced to much less than half. But if I want to take a small piece out of the middle then I would like to be able to work down from the full to half without the jump.

The fact that my program works with images of 1824 * 1368 or smaller tells me that it is not a bug in my program, but a problem that PB is not copying images bigger than this.

Also I tried the superadnim code and the same happened, CopyImage worked for smaller images but fell over with the bigger ones. :(

Posted: Thu Dec 20, 2007 12:31 pm
by srod
Try the api CopyImage_() to see if this one works? This will only work with image handles (as opposed to image#) but you should be able to knock up a quick test to see if things are working.

Posted: Thu Dec 20, 2007 1:07 pm
by PB
Quickest way to sort out the problem is to post some code which causes the
error, along with a link to a pic of that size that has been zipped.

Posted: Thu Dec 20, 2007 4:00 pm
by netmaestro
I have 2 gb ram and I can create and copy a 14000 * 14000 32bit image, so there's probably something to find in your code.

@srod, I believe PB's CopyImage command calls that api, so it's unlikely to yield a different result.

Things like this usually boil down to large images not getting freed when they should.

Posted: Thu Dec 20, 2007 9:55 pm
by superadnim
What mr PB says is the logical next step, please share media and code (could be the same code I posted if that's also not working for you).

It would be nice to know what system you are working with and also, if possible, your GDI dll hash in case of windows (I know this sounds odd, but I have the impression something might be wrong with your libraries).

Good luck.

Posted: Fri Dec 21, 2007 12:20 am
by MikeB
Don't know if it makes a difference but I am running Vista Home Premium 32 bit. Grapics card Sapphire X1960 Pro with 512 Mb.
Code below is the easy way of showing what happens.

Code: Select all

If CreateImage(1, 3648, 2736) ; change to 1824 * 1368 and it works
	StartDrawing(ImageOutput(1))
	For k = 1 To 1000
		Box(Random(3500), Random(2600), 100, 100, RGB(Random(255), Random(255), Random(255)))
	Next
	StopDrawing()
	SaveImage(1, "C:\Temp\Image1.bmp") ; no problem
	If CopyImage(1, 2) = #False
		Debug "Failed"  ; fails every time
	Else
		Debug "Success"
		SaveImage(2, "C:\Temp\Image2.bmp")  ; never happens
	EndIf
Else
	Debug "Can't create image"  ; never happens as image gets created
EndIf
As you see I can create an image to save loading one, but still can't copy it.

P.S. GDI dll hash ?

Posted: Fri Dec 21, 2007 12:35 am
by superadnim
Yep a hash (fingerprint, md5 or crc32) to compare with my list of versions. It's just a whim though.

Works just fine...

Code: Select all

ih = CreateImage(#PB_Any, 3648, 2736)

If ih
	If StartDrawing(ImageOutput(ih))
		For k = 1 To 1000
		  Box(Random(3500), Random(2600), 100, 100, RGB(Random(255), Random(255), Random(255)))
		Next
		StopDrawing()
		
		SaveImage(ih, "C:\Temp\Image1.bmp")
		
		img = CopyImage(ih, #PB_Any)
		If Not img
		  Debug "Failed"
		Else
		  Debug "Success"
		  SaveImage(img, "C:\Temp\Image2.bmp")
		EndIf
   EndIf
   
Else
   Debug "Can't create image"
EndIf 

Posted: Fri Dec 21, 2007 12:37 am
by Dare
It's not a hardware thing, is it?

Perhaps you could run a ram diagnostic tool of some sort (no idea what these may be) and see if your memory is all okay.

Posted: Fri Dec 21, 2007 12:44 am
by superadnim
Dare, his last code fails here (didn't even care to check why though) but mine doesn't, at least here it works just fine.

for mem-diagnosis you could get a DOS tool, but none of them are bulletproof. anyway I doubt it's a hardware issue... too soon to jump into conclusions of that sort.

perhaps copyimage when used with enumaration doesn't return anything?, I haven't checked... I never use enum though, it's too abstract for me.

Posted: Fri Dec 21, 2007 1:46 am
by MikeB
I've been experimenting and have found a way that works.

Code: Select all

If CreateImage(1, 3648, 2736) And CreateImage(2, 3648, 2736)
	StartDrawing(ImageOutput(1))
	For k = 1 To 1000
		Box(Random(3500), Random(2600), 100, 100, RGB(Random(255), Random(255), Random(255)))
	Next
	StopDrawing()
	SaveImage(1, "C:\Temp\Image1.bmp")
	StartDrawing(ImageOutput(2))
	DrawImage(ImageID(1), 0, 0)
	Circle(200, 200, 150, RGB(255, 255, 0)) ; just to prove they are different
	StopDrawing()
	SaveImage(2, "C:\Temp\Image2.bmp")
Else
	Debug "Can't create images"
EndIf
Which I would say proves that it is not a memory or system issue.
Come to think of it, I only found this happening after downloading PB 4.10, I am not saying that it worked before as I only added this bit after the download and so I can't say. The upgrade came up with all sorts of problems and so I did a full install, therefore all the libraries should have been replaced with the new ones.

I have worked round the problem in my picture viewer program by resizing image 1 and doing away with image 2, then reloading if I want to go back to the original. BUT it is something that I would like to track down just in case it comes up again. :?

Posted: Fri Dec 21, 2007 11:56 am
by Trond

Code: Select all

If CreateImage(1, 3648, 2736) ; change to 1824 * 1368 and it works 
   StartDrawing(ImageOutput(1)) 
   For k = 1 To 1000 
      Box(Random(3500), Random(2600), 100, 100, RGB(Random(255), Random(255), Random(255))) 
   Next 
   StopDrawing() 
   SaveImage(1, "C:\Temp\Image1.bmp") ; no problem 
   If CopyImage(1, 2) = #False 
      Debug "Failed"  ; fails every time 
   Else 
      Debug "Success" 
      SaveImage(2, "C:\Temp\Image2.bmp")  ; never happens 
   EndIf 
Else 
   Debug "Can't create image"  ; never happens as image gets created 
EndIf
1. Success happens here, you've got a bad aura!
2. You're checking if the result of CopyImage() is #False, but the help file says this command only returns a sensible value the second parameter is #PB_Any.