GPWiki.org
GPWiki.org
It is currently Wed Jun 19, 2013 10:18 pm

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Tue Feb 03, 2009 4:50 am 
Level 1 Cleric

Joined: Sun Mar 11, 2007 12:00 am
Posts: 10
Can anyone take this tutorial a step further and show me how to save the StdPicture object as a .bmp file on the hard drive?
http://gpwiki.org/index.php/VB:Tutorials:WINAPI:Copy_DirectDrawSurface_To_StdPicture



I have been trying for over 4 hours and the closest I have gotten is:

Code:
Dim pic As New stdole.StdPicture
Set pic = CopySurfaceToPicture(ddsTileset.getSurface, srcRect)
SavePicture pic, strFilename


This gives me with an out of memory error on the SavePicture line. Obviously the StdPicture is not what this line is expecting, but I do not have any idea how to convert the StdPicture to the IPictureDisp object that the SavePicture function wants.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2009 8:12 pm 
Mumbo Jumbo
User avatar

Joined: Fri Aug 20, 2004 1:15 pm
Posts: 804
Location: Michigan, USA
savePicture can save stdPicture objects.

I would guess that pic is too big.

_________________
The path to hell is paved with clever code.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 2:01 am 
Level 1 Cleric

Joined: Sun Mar 11, 2007 12:00 am
Posts: 10
I don't see how it could be too big the picture is only 160x336 pixels.
Could something else be wrong, maybe in the tutorial?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 6:02 pm 
Mumbo Jumbo
User avatar

Joined: Fri Aug 20, 2004 1:15 pm
Posts: 804
Location: Michigan, USA
well i checked out the code, and i was able to load a surface with a bitmap, then use the function to copy the surface picture to an stdpicture, and then i was able to save it.

here is the hacked together code i used to create and save the surface. the CopySurfaceToPicture function is a direct copy/paste from the tutorial. (image1.bmp is a standard windows bitmap 128x64)

Code:
Dim pic As New stdole.StdPicture
Dim s As DxVBLib.DirectDrawSurface7
Dim R As DxVBLib.RECT
Dim dd As DirectDraw7
Dim dx As New DirectX7

Set dd = dx.DirectDrawCreate("")
Call dd.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsd.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
ddsd.lWidth = 128
ddsd.lHeight = 64
Set s = dd.CreateSurfaceFromFile("x:\image1.bmp", ddsd)

Set pic = CopySurfaceToPicture(s, R)
SavePicture pic, "x:\tempstdpic.bmp"


Edit: i even tried copying a primary surface to the pic and it saved a nice screen capture to disk.

_________________
The path to hell is paved with clever code.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 10:25 pm 
Level 1 Cleric

Joined: Sun Mar 11, 2007 12:00 am
Posts: 10
Moglor wrote:
well i checked out the code, and i was able to load a surface with a bitmap, then use the function to copy the surface picture to an stdpicture, and then i was able to save it.

here is the hacked together code i used to create and save the surface. the CopySurfaceToPicture function is a direct copy/paste from the tutorial. (image1.bmp is a standard windows bitmap 128x64)

Code:
Dim pic As New stdole.StdPicture
Dim s As DxVBLib.DirectDrawSurface7
Dim R As DxVBLib.RECT
Dim dd As DirectDraw7
Dim dx As New DirectX7

Set dd = dx.DirectDrawCreate("")
Call dd.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)
Dim ddsd As DDSURFACEDESC2
ddsd.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsd.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
ddsd.lWidth = 128
ddsd.lHeight = 64
Set s = dd.CreateSurfaceFromFile("x:\image1.bmp", ddsd)

Set pic = CopySurfaceToPicture(s, R)
SavePicture pic, "x:\tempstdpic.bmp"


Edit: i even tried copying a primary surface to the pic and it saved a nice screen capture to disk.



Thanks for your time.

I copied your code to try this in a new project used the exact same picture size 128x64 and exact same code, only changing the file path for the pictures to load and save. And I am STILL getting the error on the SavePicture line. So it has to be a problem with the library or some kind of bug wouldn't you think?

Error:
http://www.mortalsguild.com/pics/outofmemory.bmp

What a waste of time this has been... :confused

What OLE Automation file is referenced in your project?

Here is mine:
http://www.mortalsguild.com/pics/ole.bmp

Thanks again for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 11:32 pm 
Funky Monkey

Joined: Mon Aug 16, 2004 2:48 pm
Posts: 1604
Location: Minneapolis, MN USA
You should test if the "pic" object is set to anything after the copysurfacetopicture function is run.

Also, I don't see where "R" is being set to anything ... or is a "blank" rect treated as a special case to mean "whole surface"?

-Bryk

_________________
www.mwgames.com ... Dicey Curves, Space Mission, Jump Gate, Gem Raider, DareBase, Castle Danger, Keeps & Moats Chess


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 2:20 am 
Level 1 Cleric

Joined: Sun Mar 11, 2007 12:00 am
Posts: 10
The function seems to be working fine.
The Pic object has a dc as well as other information if I debug and look.
The problem seems to be with the SavePicture method.

And yes the rect is left blank or set to all 0's to indicate the whole surface.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 3:03 am 
Mumbo Jumbo
User avatar

Joined: Fri Aug 20, 2004 1:15 pm
Posts: 804
Location: Michigan, USA
whats the image you are using? maybe the image format is wrong for stdpicture

_________________
The path to hell is paved with clever code.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 3:41 am 
Level 1 Cleric

Joined: Sun Mar 11, 2007 12:00 am
Posts: 10
For the test project where I copied yoru code I made my own BMP in paint. Saved it as a 24 bit bmp file.

In my own project I am converting it directly from a directx surface via the function.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 6:03 am 
Level 1 Cleric

Joined: Sun Mar 11, 2007 12:00 am
Posts: 10
I did more playing around with this code works fine for me.

Code:
Picture1.Picture = LoadPicture("c:\test.bmp")
SavePicture Picture1.Picture, "c:\tempnewpic.bmp"


Yet, loading that same picture to a directx surface and converting it to a picture object and saving it results in the error still.

Anyone have any ideas why this would be?[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 1:50 pm 
Funky Monkey

Joined: Mon Aug 16, 2004 2:48 pm
Posts: 1604
Location: Minneapolis, MN USA
I haven't looked at the code for the copysurfacetopicture function, but I wonder if it makes some assumptions about your surface, such as your color depth format, which might be resulting in a picture object that SavePicture can't handle.

-Bryk

_________________
www.mwgames.com ... Dicey Curves, Space Mission, Jump Gate, Gem Raider, DareBase, Castle Danger, Keeps & Moats Chess


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 2:22 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2217
Location: England
Brykovian wrote:
I haven't looked at the code for the copysurfacetopicture function, but I wonder if it makes some assumptions about your surface, such as your color depth format, which might be resulting in a picture object that SavePicture can't handle.

-Bryk


Like if it's 32-bit, but savepicture can only handle 24-bit?


Top
 Profile  
 
 Post subject: kojioji
PostPosted: Mon Mar 16, 2009 7:23 am 
Sub ddScreenshot()
Dim hDC As Long
m.AutoRedraw = True
m.Cls
If Fullscreen Then
PS.BltToDC m.hDC, scr, scr
Else
GBF.BltToDC m.hDC, scr, scr
End If
SavePicture m.Image, App.Path + "\data\screens\" + GetVal("modname") + " " & Replace(Replace(Now, ":", "-"), "/", ".") & ".bmp"
m.AutoRedraw = False
End Sub

i made that myself :( obviously not the right way to do it, but works flawlessly on all systems tested on


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group