473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DirectX and False Stretching Images

I am using some code that I somewhat cannibalized from a tutorial, and
whenever I try to put in an image not of specific seemingly random
sizes, it stretches them out alot.

The module that runs the code I am using is this: (note that the
tutorial had a 3D segment as well, which has been remarked)

-------------------------------------------------------

Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D

Module mdx9a
Public device As device
Public sprite As Sprite
Dim deviceSetting As New PresentParameters
Structure oggX
'contain mesh and material for an object
'Public mesh As Mesh
'Public numX As Integer
Public tex() As Texture
'Public mat() As Material
End Structure
'Public Const GradToRad = Math.PI / 180

Sub createDevice(ByVal width As Integer, ByVal heigth As Integer,
ByVal bpp As Integer, ByVal fhWnd As System.IntPtr, ByVal windowed As
Boolean)
'screen description
deviceSetting.BackBufferCount = 1 'backbuffer number
deviceSetting.AutoDepthStencilFormat = DepthFormat.D16
'Z/Stencil buffer formats
deviceSetting.EnableAutoDepthStencil = True 'active Z/Stencil
buffer
deviceSetting.DeviceWindowHandle = fhWnd 'handle del form
deviceSetting.SwapEffect = SwapEffect.Flip 'rendering type
If windowed Then
deviceSetting.Windowed = True 'setting for windowed mode
Else
deviceSetting.Windowed = False 'setting for fullscreen
deviceSetting.BackBufferWidth = width 'screen resolution
deviceSetting.BackBufferHeight = heigth 'screen resolution
If bpp = 16 Then
deviceSetting.BackBufferFormat = Format.R5G6B5
'backbuffer format at 16Bit
Else
deviceSetting.BackBufferFormat = Format.X8R8G8B8
'backbuffer format at 32Bit
End If

End If
'presentation type
deviceSetting.PresentationInterval = PresentInterval.Immediate
'create device
device = New device(0, DeviceType.Hardware, fhWnd,
CreateFlags.HardwareVertexProcessing, deviceSetting)

'create a sprite controller for device
sprite = New sprite(device)

End Sub

'must be executed when form is resized
Sub resetDevice()
'you must putting them to zero to permit directX to change
backbuffer size
deviceSetting.BackBufferHeight = 0
deviceSetting.BackBufferWidth = 0
device.Reset(deviceSetting)
End Sub

Sub defaultSetting()

' device.RenderState.ZBufferEnable = True 'Z buffer on
' device.RenderState.Lighting = False 'lights off
' device.RenderState.ShadeMode = ShadeMode.Gouraud 'gouraud
mode
device.Transform.World = Matrix.Identity
device.Transform.View = Matrix.LookAtLH(New Vector3(0, 0, -30),
New Vector3(0, 0, 0), New Vector3(0, 1, 0))
device.Transform.Projection =
Matrix.PerspectiveFovLH(CSng(Math.PI / 3), CSng(4 / 3), 1, 2000)

End Sub

'create texture from file
Function createTexture(ByVal filesrc As String, Optional ByVal
colorKey As Integer = 0) As Texture
Return TextureLoader.FromFile(device, filesrc, 0, 0, 0, 0,
Format.Unknown, Pool.Managed, Filter.Linear, Filter.Linear, colorKey)
End Function
End Module

--------------------------------------------------

I am then using code like this to display pictures to the screen.

This to Create:
Texture = createTexture("filename", Color.FromArgb(255, 255, 0,
255).ToArgb)

This to Draw:
sprite.Draw(Texture, New Rectangle(0, 0, 275, 2000), New Vector3(0, 0,
0), New Vector3(0, 0, 0), Color.White)
Note that everything works fine, except that some file sizes are
distorted. (the file size I need that doesnt work is 1021x2997)

*** Sent via Developersdex http://www.developersdex.com ***
Jun 30 '06 #1
1 2238
A. Gaubatz wrote:
I am using some code that I somewhat cannibalized from a tutorial, and
whenever I try to put in an image not of specific seemingly random
sizes, it stretches them out alot.
....
I am then using code like this to display pictures to the screen.

This to Create:
Texture = createTexture("filename", Color.FromArgb(255, 255, 0,
255).ToArgb)

This to Draw:
sprite.Draw(Texture, New Rectangle(0, 0, 275, 2000), New Vector3(0, 0,
0), New Vector3(0, 0, 0), Color.White)
Note that everything works fine, except that some file sizes are
distorted. (the file size I need that doesnt work is 1021x2997)
It appears that you are trying to squash a 1021px x 2997px image into a
275px x 2000px box. You could either
a) Crop the image
or
b) Resize the image into the available space while keeping the same aspect
ratio.

Andrew
Jul 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Zoury | last post by:
look up your timezome settings... you have future posted.
2
by: Dan | last post by:
Hi all, I'm totally new to DirectX but I'd need to learn some basics. I do not need all the bells & whistles, I just require a fast display of huge 2D images (typically JPEG photos or maps) in a...
3
by: Raed Sawalha | last post by:
I read in MSDN an examples for Image Stretching but something I can not understand is this line e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units); what is e in all example they...
6
by: Christopher Kurtis Koeber | last post by:
Dear All, I want to create a high-speed imaging application and I am currently sing the built-in GDI+ imaging controls, methods, etc. However, on Bob Powell's website, he said to check out DirectX...
14
by: Jessica Weiner | last post by:
I am writing an application in C# which need to plot graphs and simple shapes (polygons, circles, squares etc). Which library is better for this purpose and why? Thanks.
4
by: Arthur Dent | last post by:
Hello all... i have a really frsutrating problem here... This is only happening in IE (6 & 7b2), Mozilla and Netscape are both OK. I have a top-level table with a width of 760px, so it should be...
2
by: elephant | last post by:
I'm trying something in CSS, and I was wondering if anyone knows of a way to do it. The goal is to have one image with a width of 25px, and have the left 12 pixels be one side of an image of...
5
by: Vibhesh | last post by:
I am facing problem with TimeSpan structure when DirectX is used. Following is the sample code that causes the problem: ...
1
by: tictac | last post by:
I want to display 10 image with JPEG or BITMAP extension together and because of this 10 images cant fit in the screen of monitor ,I want to scroll through this images with mouse in up-down and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.