convert SharpDXDirect3D11 Texture2D?
#1
Hi,

I was able to make my forum account work just by simply creating another one hehe. Hopefully that doesn't mess up my account there on the ab4d official website. 

So I am using a DesktopDuplicator as seen here https://github.com/Deathspike/Hansha . Once I get access the Desktop Duplicator in a running program, it outputs:



Code:
   public class ScreenFrame
    {
        public Texture2D texture2D;
        public ScreenFrameRectangle Boundaries;
        public ScreenFrameRectangle[] ModifiedRegions;
        public ScreenFrameRegion[] MovedRegions;
        public byte[] NewPixels;
        public byte[] PreviousPixels;
    }

now with the following line of code next, I am able to copy the contents of the Newpixels to a Bitmap:

Code:
private static void CopyToImage(Bitmap image, ScreenFrame screenFrame)
{
  var imageBoundaries = new System.Drawing.Rectangle(0, 0, screenFrame.Boundaries.Right,
                        screenFrame.Boundaries.Bottom);
  var imageData = image.LockBits(imageBoundaries, ImageLockMode.WriteOnly, image.PixelFormat);
  Marshal.Copy(screenFrame.NewPixels, 0, imageData.Scan0, screenFrame.NewPixels.Length);
  image.UnlockBits(imageData);
}

Following that, I need to convert the Bitmap to a BitmapSource and then from BitmapSource to ImageBrush
and then imageBrush to DiffuseMaterial to apply it to the material of an object.


Code:
BitmapSource bitmapSource = CreateBitmapSource(_bitmap);
ImageBrush _imageBrush = new ImageBrush(bitmapSource);
diffuseMaterial = new DiffuseMaterial(_imageBrush);
floorBox.Material = diffuseMaterial;

It works.

But the function CreateBitmapSource here is overloading the performance like crazy. It really lags and bottlenecks the whole performance:

Code:
private static BitmapSource CreateBitmapSource(Bitmap bitmap)
{
 System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);

 BitmapData bitmapData = bitmap.LockBits(rect, ImageLockMode.ReadOnly, bitmap.PixelFormat);

 BitmapSource source = BitmapSource.Create(bitmap.Width, bitmap.Height,bitmap.HorizontalResolution,   bitmap.VerticalResolution, PixelFormats.Pbgra32, null,bitmapData.Scan0, bitmapData.Stride * bitmap.Height,  bitmapData.Stride);
 bitmap.UnlockBits(bitmapData);
 return source;
}

Does anybody have any clues on an alternative?

Thank you!
Steve

I will scour the AB4D samples to find clues about applying textures to an object's material.


EDIT 2018-06-23 - 22h00 - I have found an alternative. But it doesn't fix the lag issue and so I will divide the desktop screen and try to make threads work on them to lower the load. Here is the alternative that I found: 

Code:
BitmapImage _bitmapImage = ToBitmapImage(_bitmap);
ImageBrush brush = new ImageBrush(_bitmapImage);
diffuseMaterial = new DiffuseMaterial(brush);
floorBox.Material = diffuseMaterial;


from here: https://stackoverflow.com/questions/6484...vice-versa
  


Messages In This Thread
convert SharpDXDirect3D11 Texture2D? - by steve.chasse@gmail.com - 06-23-2018, 10:46 PM

Forum Jump:


Users browsing this thread:
1 Guest(s)