lockbits

Edge Detection with Lockbits C#

a 夏天 提交于 2021-01-29 03:48:50
问题 I made a program that implements an edge detection algorithm, but it takes a long time to process. I've read about using lockbits, and unsafe state instead of getpixel and setpixel, but I still don't understand how to use it. This is my example code: private Bitmap SobelEdgeDetect(Bitmap original) { Bitmap b = original; Bitmap bb = original; int width = b.Width; int height = b.Height; int[,] gx = new int[,] { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } }; int[,] gy = new int[,] { { 1, 2, 1 }, {

Fast Bitmap modifying using BitmapData and pointers in C#

岁酱吖の 提交于 2020-03-04 12:35:13
问题 I am capturing data from some camera (array of RAW data). Then I'm mapping this data to RGB values according to color palette. I need to map it as fast as possible, so I use BitmapDdata and edit pixels in unsafe piece of code using pointers. public void dataAcquired(int[] data) { Bitmap bmp = new Bitmap(width, height); BitmapData data = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); for (int i = 0; i < data.Length; i++) { int x = i % bmp

LockBits seems to result in wrong stride when copying byte array to bitmap

谁说胖子不能爱 提交于 2019-12-25 18:45:41
问题 I'm trying to copy a simple byte array to an 8bit indexed bitmap. Using the exact same code as shown in countless answered questions on many forums, I still get the wrong result. The data I'm trying to write to image files is 360 bytes, setup as an 18x20 byte linear array. That is, the first 18 bytes (0-17) belong on the top row of the image, the next 18 bytes (18-35) belong on the 2nd row, etc. I have confirmed that this data is correct, as I can manually parse it in Excel (and even

C# Bitmap LockBits/UnlockBits in multi-thread

冷暖自知 提交于 2019-12-25 04:19:30
问题 I am working on a CCTV project which employs ONVIF. I use a Winform sample, which is provided by "ONVIF Device Manager" project, to obtain video frames from a camera. (You can find it here). I found that the sample put a CopyMemory() block code inside UI thread by using dispatcher.BeginInvoke(). I would slow down main UI thread because this block is repeated to display images in a PictureBox. void InitPlayback(VideoBuffer videoBuffer, bool isInitial) { //.... var renderingTask = Task.Factory

C# - Remove Bitmap padding

浪子不回头ぞ 提交于 2019-12-19 11:16:07
问题 I was wondering if there's a way in order to remove the padding generated by the 24 bit Bitmap for each scan line. What I mean is like this : Original [Pure Cyan 24 Bit BMP] : FF FF 00 FF FF 00 FF FF **00 00** FF FF 00 FF FF 00 FF FF 00 Desired output [Removed Padding] : FF FF 00 FF FF 00 FF FF **00** FF FF 00 FF FF 00 FF FF 00 Here's my code for getting the pixel data. Bitmap tmp_bitmap = BitmapFromFile; Rectangle rect = new Rectangle(0, 0, tmp_bitmap.Width, tmp_bitmap.Height); System

Mifare Ultralight C Lock

☆樱花仙子☆ 提交于 2019-12-18 18:28:12
问题 I'm attempting to lock a Mifare Ultralight C tag. I want to set NDEF pages 0x04 to 0x27 to read-only. I think this can be achieved via Ndef.makeReadonly() . Additionally, I would like to set pages 0x29 to 0x2F to be password protected (for read and write) so they can only be accessed after authentication was successful. I'm struggling to understand which bytes need to set in lock bytes (page 0x28, bytes 0, 1) and if sectors 0x2A and 0x2B need to be set as well. 回答1: I'm attempting to set NDEF

Does Bitmap.LockBits “pin” a bitmap into memory?

亡梦爱人 提交于 2019-12-18 08:26:47
问题 I'm using locked bitmaps a lot recently, and I keep getting "attempted to access invalid memory" errors. This is mostly because the bitmap has been moved in memory. Some people using GCHandle.Alloc() to allocate memory in the CLR and pin it. Does Bitmap.LockBits() do the same? I don't understand the difference between "locking" memory and "pinning" memory. Can you also explain the terminology and the differences if any? 回答1: GCHandle.Alloc is a more generic method, that allows you to allocate

Mifare Ultralight: lock specific pages

时光怂恿深爱的人放手 提交于 2019-12-13 11:48:39
问题 I got reference from this link (Mifare Ultralight C Lock) to make all pages on a Mifare Ultralight tag read-only. I can write a message on a Mifare Ultralight tag successfully on Android. Now I want to lock pages 4 to 7 (or any specific page). The above link only shows how to lock all pages. How I can lock specific pages? This code locks all pages: mifare.transceive(new byte[] { (byte)0xA2, /* CMD = WRITE */ (byte)0x02, /* PAGE = 2 */ (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF /* DATA =