Reverse memcpy for NativeArray?
I want to convert these codes to NativeArray version.
using System.Linq;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
void foo(string filePath)
{
using(var bitmap = new Bitmap(filePath)
{
BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
int len = data.Height * data.Stride;
byte[] img_bytes = new byte[len];
Marshal.Copy(data.Scan0, img_bytes, 0, len);
var tex = new Texture2D(bitmap.Width, bitmap.Height, TextureFormat.RGB24, false, false);
tex.LoadRawTextureData(img_bytes.Reverse().ToArray());
bitmap.UnlockBits(data);
}
}
Currently I converted like this.
//....
var arr = new NativeArray<byte>(img_bytes.Reverse().ToArray(), Allocator.Temp);
tex.LoadRawTextureData(arr);
It does work already, but I'm wondering about possibility of optimizing.
I've tried UnsafeUtility.MemCpyStride with negative stride value, but it just drive to crashing app.
Any advise, idea or suggesion would be appreciated to me. I'm totally new on these yet.
sorry for trying spam$$anonymous$$g. I wasn't noticed it due to 504 time out error.
Your answer
Follow this Question
Related Questions
Enabling & Disabling Script via On Click 1 Answer
Can someone please help me find out what wrong with my code. 0 Answers
The laser problems 0 Answers
How can i make sure the script will work only on the attached object ? 1 Answer
How can I check if a object in the hierarchy have been destroyed using EditorWindow type script ? 1 Answer