473,721 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Direc tX
Imports Microsoft.Direc tX.Direct3D

Module mdx9a
Public device As device
Public sprite As Sprite
Dim deviceSetting As New PresentParamete rs
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(By Val width As Integer, ByVal heigth As Integer,
ByVal bpp As Integer, ByVal fhWnd As System.IntPtr, ByVal windowed As
Boolean)
'screen description
deviceSetting.B ackBufferCount = 1 'backbuffer number
deviceSetting.A utoDepthStencil Format = DepthFormat.D16
'Z/Stencil buffer formats
deviceSetting.E nableAutoDepthS tencil = True 'active Z/Stencil
buffer
deviceSetting.D eviceWindowHand le = fhWnd 'handle del form
deviceSetting.S wapEffect = SwapEffect.Flip 'rendering type
If windowed Then
deviceSetting.W indowed = True 'setting for windowed mode
Else
deviceSetting.W indowed = False 'setting for fullscreen
deviceSetting.B ackBufferWidth = width 'screen resolution
deviceSetting.B ackBufferHeight = heigth 'screen resolution
If bpp = 16 Then
deviceSetting.B ackBufferFormat = Format.R5G6B5
'backbuffer format at 16Bit
Else
deviceSetting.B ackBufferFormat = Format.X8R8G8B8
'backbuffer format at 32Bit
End If

End If
'presentation type
deviceSetting.P resentationInte rval = PresentInterval .Immediate
'create device
device = New device(0, DeviceType.Hard ware, fhWnd,
CreateFlags.Har dwareVertexProc essing, 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.B ackBufferHeight = 0
deviceSetting.B ackBufferWidth = 0
device.Reset(de viceSetting)
End Sub

Sub defaultSetting( )

' device.RenderSt ate.ZBufferEnab le = True 'Z buffer on
' device.RenderSt ate.Lighting = False 'lights off
' device.RenderSt ate.ShadeMode = ShadeMode.Goura ud 'gouraud
mode
device.Transfor m.World = Matrix.Identity
device.Transfor m.View = Matrix.LookAtLH (New Vector3(0, 0, -30),
New Vector3(0, 0, 0), New Vector3(0, 1, 0))
device.Transfor m.Projection =
Matrix.Perspect iveFovLH(CSng(M ath.PI / 3), CSng(4 / 3), 1, 2000)

End Sub

'create texture from file
Function createTexture(B yVal filesrc As String, Optional ByVal
colorKey As Integer = 0) As Texture
Return TextureLoader.F romFile(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(Tex ture, 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 2265
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(Tex ture, 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
2184
by: Zoury | last post by:
look up your timezome settings... you have future posted.
2
1273
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 c-sharp windows forms application; further, I should display "layered" semitransparent images onto the base image with some filtering, and optionally draw on the fly some text labels onto some externally defined positions in the images. Could anyone...
3
2928
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 did not show what is e ????? any help
6
6933
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 to do this. But I am not well versed in C++ or C#, I am relatively new to those languages, I have more experience and therefore am more comfortable in Visual Basic. Can I use DirectX in Visual Basic.Net or will I have to learn C# or C++. I want...
14
2654
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
1784
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 760 minimum and stretching wider as needed to fit content (such as bound datagrids). In the top TR/TD, i have a header table which is width of 100%, and has three TD's. Each contains one image file, with the middle TD being set to width 100%. So...
2
3727
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 indeterminate width, the right 12 pixels be the right side of the image, and the center pixel to stretch the entire distance in between. I know how to do this using three separate images, but is it possible to do it by just somehow stretching the 1...
5
2004
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: *************************************************************************************************************** { ........................... PrintTimeSpanProblem(); device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); PrintTimeSpanProblem();
1
1582
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 left-right direction.(In C# and directX)? I find a program with C# and directX (2D) that display images with TIF extension,but I want display JPG or BMP
0
8834
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8727
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9365
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9212
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9127
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5973
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4483
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4748
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2127
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.