Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

1 Neutral

About hoahong

  • Rank

Personal Information

  • Interests

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. @Zakwayda Yes, the problem is in Premultiplied Alpha. I have to invert pixel value from Premultiplied Alpha value. Thank you so much for the help.
  2. The code to create GraphicContext: Factory5 resultFactory; Adapter4 resultAdapter; D3D11.Device5 resultDevice; D2D1.Device5 _d2d1device5; D2D1.DeviceContext5 _d2d1Devicecontext5; using (var factory2 = new SharpDX.DXGI.Factory2()) { resultFactory = factory2.QueryInterface<Factory5>(); using (Adapter adapter = resultFactory.GetAdapter1(0)) { resultAdapter = adapter.QueryInterface<Adapter4>(); using (var device = new D3D11.Device(resultAdapter, SharpDX.Direct3D11.DeviceCreationFlags.Debug | SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport | SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport, SharpDX.Direct3D.FeatureLevel.Level_11_0, SharpDX.Direct3D.FeatureLevel.Level_11_1, SharpDX.Direct3D.FeatureLevel.Level_12_0, SharpDX.Direct3D.FeatureLevel.Level_12_1/*requestedFeatureLevel*/) { DebugName = "Direct3D11 creation" }) { resultDevice = device.QueryInterface<D3D11.Device5>(); //Create 2D Device & Context var dxgiDevice1 = resultDevice.QueryInterface<SharpDX.DXGI.Device1>(); // Dont define f1 as SharpDX.Direct2D1.Factory1, just define f1 as var, this is a trick by system var f1 = new SharpDX.Direct2D1.Factory1(); var d2ddv = new SharpDX.Direct2D1.Device(f1, dxgiDevice1); _d2d1device5 = d2ddv.QueryInterface<SharpDX.Direct2D1.Device5>(); _d2d1Devicecontext5 = new DX.Direct2D1.DeviceContext5(_d2d1device5, DX.Direct2D1.DeviceContextOptions.EnableMultithreadedOptimizations) { TextAntialiasMode = DX.Direct2D1.TextAntialiasMode.Aliased }; } } } The code to create and draw bitmap in the fist post
  3. The revised code only change: PixelFormat = new D2D1.PixelFormat(Format.R8G8B8A8_UNorm, D2D1.AlphaMode.Premultiplied) To: PixelFormat = new D2D1.PixelFormat(Format.R8G8B8A8_UNorm, D2D1.AlphaMode.Ignore)
  4. Thanks @Zakwayda After you said in 2nd post, I changed Premultiplied at positionss in code (in creating images) test and got such result, i did not post that code here. The first bitmap was created with flag 'BitmapOptions.Target' so that i could draw on that bitmap by DeviceContext but i can access pixel value of the bitmap with such flag. That's why i created a second bitmap with flag 'BitmapOptions.CpuRead' to read pixel value. Do you have any hint for reading pixel of the first bitmap in my code? Thanks
  5. I changed to: D2D1.AlphaMode.Ignore But still the same value.
  6. Hi guys, I created a Bitmap1 and filled it with RawColor4(1f, 0.0f, 0.0f, 0.5f) by this code: D2D1.Bitmap1 img = new D2D1.Bitmap1(_graphics.D2D1Context5, new SharpDX.Size2(640, 480), new BitmapProperties1() { PixelFormat = new D2D1.PixelFormat(Format.R8G8B8A8_UNorm, D2D1.AlphaMode.Premultiplied), DpiX = 96, DpiY = 96, BitmapOptions = BitmapOptions.Target }); _graphics.D2D1Context5.Target = img; _graphics.D2D1Context5.BeginDraw(); _graphics.D2D1Context5.AntialiasMode = AntialiasMode.Aliased; //RawColor4 with Red=1f; G=0.0f; B=0.0f; Alpha = 0.5f; SolidColorBrush br = new SolidColorBrush(_graphics.D2D1Context5, new SharpDX.Mathematics.Interop.RawColor4(1f, 0.0f, 0.0f, 0.5f)); _graphics.D2D1Context5.FillRoundedRectangle(new RoundedRectangle() { RadiusX = 20, RadiusY = 20, Rect = new SharpDX.Mathematics.Interop.RawRectangleF(10, 10, 630, 470) }, br); br.Dispose(); _graphics.D2D1Context5.EndDraw(); Then i use this function to get Pixel value from img above: private static Color4 GetPixel( Bitmap1 created_with_BitmapOption_Target, int x, int y) { var img1 = new D2D1.Bitmap1(_graphics.D2D1Context5, new SharpDX.Size2(created_with_BitmapOption_Target.PixelSize.Width, created_with_BitmapOption_Target.PixelSize.Height), new BitmapProperties1() { PixelFormat = new D2D1.PixelFormat(Format.R8G8B8A8_UNorm, D2D1.AlphaMode.Premultiplied), DpiX = 96, DpiY = 96, BitmapOptions = BitmapOptions.CannotDraw | BitmapOptions.CpuRead }); img1.CopyFromBitmap(created_with_BitmapOption_Target); var map = img1.Map(MapOptions.Read); var size = created_with_BitmapOption_Target.PixelSize.Width * created_with_BitmapOption_Target.PixelSize.Height * 4; byte[] bytes = new byte[size]; Marshal.Copy(map.DataPointer, bytes, 0, size); img1.Unmap(); img1.Dispose(); var position = (y * created_with_BitmapOption_Target.PixelSize.Width + x) * 4; return new Color4(bytes[position], bytes[position + 1], bytes[position + 2], bytes[position + 3]); } Then i get pixel value : Color4 c4val = GetPixel(img,50, 50); I get c4value is: Alpha=127; Red=127; Green=0; Blue=0 This color is not the same the color i filled img (Red=1f; G=0.0f; B=0.0f; Alpha = 0.5f;) Can anybody help where i was wrong in code? Thank you so much in advance, HoaHong
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!