Tag: 位图

函数将hex字符串转换为BitArray C#

我创建了以下函数,它将按要求执行(将HEX字符串转换为BitArray)。 我不确定函数的效率,但我现在的主要问题是Convert.ToInt64函数是特定于endian的 。 当这被移植到备用芯片组时,我们将得到不同的结果(或例外)。 所以有人可以想到另一种方法来进行这种转换??? public BitArray convertHexToBitArray(string hexData) { string binary_values = “”; BitArray binary_array; if (hexData.Length <= "FFFFFFFFFFFFFFFF".Length) // Max Int64 { binary_values = Convert.ToString(Convert.ToInt64(hexData, 16), 2); binary_array = new BitArray(binary_values.Length); for (int i = 0; i < binary_array.Length; i++) { if (binary_values[i] == '0') { binary_array[i] = false; } else { binary_array[i] […]

WPF:使用ValueConverter为ImageSource创建BitmapImage的内存含义

我在使用图像时遇到问题,并提供了一个右键单击上下文菜单来删除图像。 最初我绑定了绝对文件路径: 其中ImageFileName类似于C:\myapp\images\001.png 。 我收到错误, The process cannot access the file ‘X’ because it is being used by another process 。 经过大量的研究,我发现了必要的代码更改。 我使用了Stackoverflow的答案: 删除另一个进程正在使用的文件 ,并将代码放入ValueConverter 。 XAML: 价值转换器: public class PathToImageConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { String fileName = value as String; if (fileName […]

将24bpp位图转换为1bpp

我试图转换一个小位图图像。 我想任何不是100%白色的像素都可以转换成黑色。 我试过了 Bitmap output = sourceImage.Clone(new Rectangle(0, 0, sourceImage.Width, sourceImage.Height), PixelFormat.Format1bppIndexed); 在1bpp输出中仍然有一些较亮的像素保持白色。 实现此转换的最快方法是什么? 我可以修改Clone()调用的强度阈值吗?

如何将1D字节数组转换为包含位图的2D字节数组?

我已经使用了LockBits和UnlockBits函数,并将Image的字节数组转换为1D数组。 (仅考虑黑白/二值化图像) 有没有办法将它带到2Darrays(图像高度和宽度的大小)? 所以我可以将数组转换为“.txt”文件并查看它? 我用来将图像转换为1D数组的代码如下: Public void function(Bitmap image){ { byte[] arr1D; byte[] arr2D; BitmapData data = image.LockBits(new Rectangle(0, 0, img_w, img_h), ImageLockMode.ReadOnly, image.PixelFormat); try { IntPtr ptr = data.Scan0; int bytes = Math.Abs(data.Stride) * image.Height; byte[] rgbValues = new byte[bytes]; arr1D = rgbValues; Marshal.Copy(ptr, rgbValues, 0, bytes); } finally { image.UnlockBits(data); } } 由于图像是二进制的,因此字节数组的值仅为255和0。 […]

WPF位图到图像转换仅显示黑色图像

我在以wpf-Imageforms显示图像(uEye-Cam)时遇到了一些问题。 显示的图像完全是黑色的。 以下是我用过的代码: //Get Cam Bitmap Image var cam = new uEye.Camera(); cam.Init(); cam.Memory.Allocate(); cam.Acquisition.Capture(uEye.Defines.DeviceParameter.DontWait); Int32 s32MemId; cam.Memory.GetActive(out s32MemId); cam.Memory.Lock(s32MemId); Bitmap bitmap; cam.Memory.ToBitmap(s32MemId, out bitmap); //WPF Image control System.Windows.Controls.Image img = new System.Windows.Controls.Image(); //convert System.Drawing.Image to WPF image System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bitmap); IntPtr hBitmap = bmp.GetHbitmap(); System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); image1.Source […]

在c#中将原始图像转换为位图

我的代码目前看起来像这样: if (fe == “CR2”) { Image img = null; byte[] ba = File.ReadAllBytes(open.FileName); using (Image raw = Image.FromStream(new MemoryStream(ba))) { img = raw; } Bitmap bm = new Bitmap(img); pictureBox1.Image = bm; statusl.Text = fe; } 当我打开RAW图像时程序停止,Visual Studio说: 参数无效:Image raw = Image.FromStream(new MemoryStream(ba)) 请帮忙! 如何在PictureBox中显示RAW文件?

c#中的位图(签名)比较

我们有一个有趣的项目,要求我们比较两个签名的两个黑白位图,并说明它们是否是同一个人签名。 由于这只是两个加载的位图而不是从平板电脑捕获的数据,因此该方法将与正常的签名识别略有不同。 我认为这需要以下步骤 将位图裁剪为仅签名 尝试计算某种旋转来对齐它们 resize以使裁剪/旋转位图相同 分析内部的签名(可能通过分解为网格) 有没有人对这个项目有任何想法? 如何最好地进行轮换,比较等? 看到类似的东西?

C#如何写位图数据。 是自下而上还是自上而下?

根据维基百科 : 像素arrays是32位DWORD的块,它逐像素地描述图像。 通常,像素相对于正常图像光栅扫描顺序“倒置”存储,从左下角开始,从左到右,然后从图像的底部到顶部逐行。 1当图像高度值为负时,也可以从上到下存储未压缩的Windows位图。 所以,当我使用这段代码时: b.Save(outputFilename, ImageFormat.Bmp); C#如何实际保存它? 我可以告诉C#以高度值为负值保存它并以自上而下的方式写入吗?

C#:在调用Bitmap.save()之后Dispose()一个Bitmap对象?

我有这个: Bitmap bmp = new Bitmap(image); //image processing bmp.Save(path + fileName); 我想知道我是否需要在此代码后调用bmp.Dispose() 。 提前致谢。

.Net使用Lockbits从位图获取RGB值

我使用下面的代码从图像中提取RGB值,有时这是有效的,但是在某些文件上(似乎Stride不能被位图的宽度整除)它返回混合值: Dim rect As New Rectangle(0, 0, bmp.Width, bmp.Height) Dim bmpData As System.Drawing.Imaging.BitmapData = bmp.LockBits(rect, Imaging.ImageLockMode.ReadOnly, Imaging.PixelFormat.Format24bppRgb) Dim ptr As IntPtr = bmpData.Scan0 Dim cols As New List(Of Color) Dim bytes As Integer = Math.Abs(bmpData.Stride) * bmp.Height Dim rgbValues(bytes – 1) As Byte System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes) ‘ Retrieve RGB values For i = modByte […]