Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ SaveImage() [2/2]

void Terraria.Graphics.Capture.CaptureCamera.SaveImage ( Texture2D texture,
int width,
int height,
ImageFormat imageFormat,
string foldername,
string filename )
inlineprivate

Definition at line 283 of file CaptureCamera.cs.

284 {
285 string text = Main.SavePath + Path.DirectorySeparatorChar + "Captures" + Path.DirectorySeparatorChar + foldername;
286 string text2 = Path.Combine(text, filename);
287 if (!Utils.TryCreatingDirectory(text))
288 {
289 return;
290 }
291 if (!Platform.IsWindows)
292 {
293 int elementCount = texture.Width * texture.Height * 4;
294 texture.GetData(_outputData, 0, elementCount);
295 int num = 0;
296 int num2 = 0;
297 for (int i = 0; i < height; i++)
298 {
299 for (int j = 0; j < width; j++)
300 {
302 _outputData[num2 + 1] = _outputData[num + 1];
303 _outputData[num2 + 2] = _outputData[num + 2];
304 _outputData[num2 + 3] = _outputData[num + 3];
305 num += 4;
306 num2 += 4;
307 }
308 num += texture.Width - width << 2;
309 }
311 PlatformUtilities.SavePng(stream, width, height, width, height, _outputData);
312 return;
313 }
314 using Bitmap bitmap = new Bitmap(width, height);
315 System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
316 int elementCount2 = texture.Width * texture.Height * 4;
317 texture.GetData(_outputData, 0, elementCount2);
318 int num3 = 0;
319 int num4 = 0;
320 for (int k = 0; k < height; k++)
321 {
322 for (int l = 0; l < width; l++)
323 {
324 byte b = _outputData[num3 + 2];
326 _outputData[num4] = b;
327 _outputData[num4 + 1] = _outputData[num3 + 1];
328 _outputData[num4 + 3] = _outputData[num3 + 3];
329 num3 += 4;
330 num4 += 4;
331 }
332 num3 += texture.Width - width << 2;
333 }
334 BitmapData bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb);
335 IntPtr scan = bitmapData.Scan0;
336 Marshal.Copy(_outputData, 0, scan, width * height * 4);
337 bitmap.UnlockBits(bitmapData);
338 bitmap.Save(text2, imageFormat);
339 }
static bool IsWindows
Definition Platform.cs:19
static FileStream Create(string path)
Definition File.cs:73
static string Combine(string path1, string path2)
Definition Path.cs:304
static void Copy(int[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:800
static void SavePng(Stream stream, int width, int height, int imgWidth, int imgHeight, byte[] data)

References Terraria.Graphics.Capture.CaptureCamera._outputData, System.IO.Path.Combine(), System.Runtime.InteropServices.Marshal.Copy(), System.IO.File.Create(), ReLogic.OS.Platform.IsWindows, Terraria.Utilities.PlatformUtilities.SavePng(), System.stream, System.text, and Terraria.Utils.TryCreatingDirectory().