Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I will agree with Andrew Russel that a much better alternative would be to simply save to PNG, but if you simply HAVE to save to jpg, then there is a much better way than go trhough WriteableBitmap. </p> <p>What you can do is create an empty Bitmap object and transfer the texture data over so you will do a Texture2D to Bitmap convertion. Simply copy from below:</p> <pre><code> public static Bitmap ToBitmap(this Microsoft.Xna.Framework.Graphics.Texture2D rd, int Width, int Height) { var Bmp = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); byte[] data = ToBytes(rd); var bmpData = Bmp.LockBits(new Rectangle(0, 0, rd.Width, rd.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); System.Runtime.InteropServices.Marshal.Copy(data, 0, bmpData.Scan0, data.Length); Bmp.UnlockBits(bmpData); return Bmp; } public static byte[] ToBytes(this Microsoft.Xna.Framework.Graphics.Texture2D rd) { byte[] data = new byte[4 * rd.Height * rd.Width]; rd.GetData&lt;byte&gt;(data); SwapBytes(data); return data; } private static void SwapBytes(byte[] data) { System.Threading.Tasks.ParallelOptions po = new System.Threading.Tasks.ParallelOptions(); po.MaxDegreeOfParallelism = -1; System.Threading.Tasks.Parallel.For(0, data.Length / 4, po, t =&gt; { int bi = t * 4; byte temp = data[bi]; data[bi] = data[bi + 2]; data[bi + 2] = temp; }); } </code></pre> <p>Note that the above is pretty efficient, but with certain drawbacks. A similar code to the above can be used to very quickly achieve a Bitmap to Texture2D convertion, but without premultiplying alpha.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload