- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试为我的简历创建一个程序但是我在将位图照片(灰度照片)转换为十六进制或更好地称之为代码时遇到了问题颜色谁能帮帮我?
我尝试用 base64string 转换它,但没有成功。
openFileDialog1=new OpenFileDialog();
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Open Image";
dlg.Filter = "bmp files (*.bmp)|*.bmp";
if (dlg.ShowDialog() == DialogResult.OK)
{
Rectangle bounds = Screen.GetBounds(Point.Empty);
Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
// Convert the image to byte[]
System.IO.MemoryStream stream = new System.IO.MemoryStream();
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] imageBytes = stream.ToArray();
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
// Write the bytes (as a Base64 string) to the textbox
textBox1.Text = base64String.ToString();
我本以为会看到一堆数字,例如 A9C 或 255,但我什么也没看到。
最佳答案
它与您的代码中的 .bmp 文件一起使用,并给出 AARRGGBB 像素代码。
using System;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Title = "Open Image";
dlg.Filter = "bmp files (*.bmp)|*.bmp";
if (dlg.ShowDialog() == DialogResult.OK)
{
var colorCodes = this.GetColorCodes(dlg.FileName);
var str = string.Join(Environment.NewLine,
colorCodes.Select<int[], string>(line => string.Join(" ", line.Select<int, string>(code => string.Format("{0:X8}", code))))); // string.Format("{0:X6}", code & 0x00FFFFFF) if you want RRGGBB format
textBox1.Text = str; // requires textBox1.Multiline = true, better have monospaced font
}
}
}
private int[][] GetColorCodes(string path)
{
var bitmap = new Bitmap(path);
return Enumerable.Range(0, bitmap.Height)
.Select<int, int[]>(y => Enumerable.Range(0, bitmap.Width)
.Select<int, int>(x => bitmap.GetPixel(x, y).ToArgb())
.ToArray())
.ToArray();
}
}
}
关于c# - 如何将位图照片转换为十六进制颜色代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55656218/
我有一个消息 static int[] message = { 0x01, 0x10, 0x00, 0x01, // port addres 01 - 08
如何将十进制转换为以下格式的十六进制(至少两位,零填充,不带 0x 前缀)? 输入:255 输出:ff 输入:2 输出:02 我尝试了 hex(int)[2:] 但它似乎显示了第一个示例而不是第二个示
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: Large numbers in Pascal (Delphi) 我正在尝试将 66 位值转换为十进制。 我注意到d
给定一个十进制数字列表,如何将每个数字转换为其等效的十六进制值,反之亦然? 例如: (convert2hex 255 64 64); ->(FF 40 40) (convert2dec FF 40 4
var color = Math.floor(Math.random() * 16777215).toString(16); var hex = Number.parseInt(col
我一直被教导 0-9 代表 0 到 9 的值,A、B、C、D、E、F 代表 10-15。 我看到这种格式 0x00000000,它不适合十六进制模式。有没有导游或导师可以解释一下? 我在谷歌上搜索了十
我目前正尝试像十六进制编辑器一样将文件读取为十六进制值。为了解释这个问题,让我们假设我有一个test.txt,里面有一个简单的“Hello world”。我正在尝试使用接近以下代码的程序以十六进制形式
我正在尝试获取元素背景颜色 $(document).ready(function(){ $.each('.log-widget',function(){ console.log($(t
0x40130020的十六进制值是 2.296883 的浮点值, 使用本网站 http://gregstoll.dyndns.org/~gregstoll/floattohex/ .这如何实现到 Lu
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,vis
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
谁能解释一下我们如何计算十六进制浮点常量的值。我在看书,发现0x0.3p10代表值192。 最佳答案 指数仍以十进制表示,但底数为二,尾数为十六进制。 所以 0.3P10 是 (3 × 16−1) ×
我正在尝试创建一个标签云,需要帮助来创建一个函数来计算应用于每个标签链接所需的颜色。 我有 3 个变量: 单个标签重要性(从 0.1 到 1) 最大(最重要)的标签颜色(十六进制代码,例如“fff00
大家好,我想发送尽可能短的字符串/值。如果我有以下内容 1)l23k43i221j44h55uui6n433bb4 2)124987359824369785493584379 3)kla^askdja
我知道你会写... background-color: #ff0000; ...如果你想要红色的东西。 你可以写... background-color: rgba(255, 0, 0, 0.5);
我有一些传递地理位置坐标的二进制数据流 - 纬度和经度。我需要找到它们编码的方法。 4adac812 = 74°26.2851' = 74.438085 2b6059f9 = 43°0.2763'
我想从 my_table 中选择 family,其中 family LIKE '%HEX(9D)' 家庭十六进制格式以 9D 十六进制结尾 我将excel文件转换为sqlite数据库但是 我的一些数据
我有一组二进制配置文件,每个文件有三个版本——每个文件的原始版本和两个不同修改的版本。我需要能够同时看到两个版本和原始版本之间的差异。 我需要的是一个二进制文件的三向差异工具。通过相当费力的谷歌搜索,
我正在尝试将(可变长度)十六进制字符串转换为带符号整数(我需要正值或负值)。 [Int16] [int 32]和[int64] 似乎可以在2,4+字节长的十六进制字符串上正常工作,但我在使用3个字节的
如何将十六进制的 unicode 写入 Facebook“您在想什么”框? 我尝试过写: \u00B9 "\u00B9" ¹ "¹" 到目前为止没有任何效果 (让我补充一下,我是在 M
我是一名优秀的程序员,十分优秀!