Jump to content
  • Advertisement
Sign in to follow this  
oracle1

[XNA] Scaling Texture makes it transparent

This topic is 2987 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, my problem is like in the topic, my code:
spriteBatch.Draw(buffer, new Vector2(x * iwidth, y * iheight), null, Color.White, 0, new Vector2(iwidth, iheight), 0.8f, SpriteEffects.None, 0);

when scale factor is smaller then texture just disappears. I load 8bit Indexed PNG and then create a bitmap from it. here is my code:
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(System.Drawing.Image.FromFile(files));
              
                    Texture2D customTexture = new Texture2D(graphics.GraphicsDevice, bitmap.Width, bitmap.Height, 0, TextureUsage.None, SurfaceFormat.Color);

                    System.Drawing.Imaging.BitmapData data =
                        bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);
                    byte[] bytes = new byte[data.Height * data.Stride];
                    Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);
                    customTexture.SetData(bytes);
                    bitmap.UnlockBits(data);
                    buffer.Add(customTexture);

When i load them normally like this:
buffer.Add(Texture2D.FromFile(graphics.GraphicsDevice,files));

Textures scale normally but much slower, please help :) ? [Edited by - oracle1 on April 14, 2010 9:40:19 AM]

Share this post


Link to post
Share on other sites
Advertisement
The scale factor scales shape of sprite or scales texture?
If it was scaling vector of pixel color it would scale 4th component, alfa vale.
So alfavalues get close to 0 and you dont render them.
....
ouch. You render actualy those textures?

System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(System.Drawing.Image.FromFile(files));

-you load a bitmap by passing to constructor new object of a Image that gets loaded from a file right on.

Texture2D customTexture = new Texture2D(graphics.GraphicsDevice, bitmap.Width, bitmap.Height, 0, TextureUsage.None, SurfaceFormat.Color);

-You allocate dx texture, ok

System.Drawing.Imaging.BitmapData data =
bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);


byte[] bytes = new byte[data.Height * data.Stride];
Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);

-Then you copy from this surface to byte[] array!

customTexture.SetData(bytes);

// trara, finaly we load the dx texture surfacet by this byte[] array.

bitmap.UnlockBits(data);

buffer.Add(customTexture);

Share this post


Link to post
Share on other sites
I am sure you can read map bytes from Image class right away as byte[] array.
And load theese to dx surface right on without locking dynamic surfaces or so

Share this post


Link to post
Share on other sites
Also you have a DirectX utility function that loads from file of any format to dx texture object, and you use this dx texture object right on.

I do not use utility functions, but I need them for this particular function:)

Share this post


Link to post
Share on other sites
> I am sure you can read map bytes from Image class right away as byte[] array.

Yes i can but setdata returns an error:
The size of the data passed in is too large or too small for this resource.

adn i cant convert textures because my app is image viewer

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!