Tag: 位图

Bitmap.LockBits是否将位图“固定”到内存中?

我最近使用锁定的位图,并且一直“试图访问无效内存”错误。 这主要是因为位图已在内存中移动。 有些人使用GCHandle.Alloc()在CLR中分配内存并固定它。 Bitmap.LockBits()也这样做吗? 我不明白“锁定”内存和“固定”内存之间的区别。 你能解释术语和差异吗?

如何使用C#将jpg文件转换为位图?

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace convert { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load_1(object sender, EventArgs e) { // Image image = Image.FromFile(@”C:\Users\Public\Pictures\Sample Pictures\Koala.jpg”); // Set the PictureBox image property to this image. […]

用PNG图像中的白色替换透明背景

我有一个PNG图像从Android中的DrawingView发送到WCF服务。 图像以32位发送,并具有透明背景。 我想用白色替换透明色(缺少更好的单词)背景。 到目前为止我的代码看起来像这样: // Converting image to Bitmap object Bitmap i = new Bitmap(new MemoryStream(Convert.FromBase64String(image))); // The image that is send from the tablet is 1280×692 // So we need to crop it Rectangle cropRect = new Rectangle(640, 0, 640, 692); //HERE Bitmap target = i.Clone(cropRect, i.PixelFormat); target.Save(string.Format(“c:\\images\\{0}.png”, randomFileName()), System.Drawing.Imaging.ImageFormat.Png); 以上工作正常,但图像具有透明背景。 我注意到在Paint.NET中你可以简单地将PNG格式设置为8位,并将背景设置为白色。 但是,当我尝试使用时: System.Drawing.Imaging.PixelFormat.Format8bppIndexed […]

将位图保存为32bpp不会保持透明度

using (var bmp = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb)) using (var g = Graphics.FromImage(bmp)) { g.Clear(Color.Transparent); g.DrawImage(image, 0, 0); bmp.Save(“image.bmp”, ImageFormat.Bmp); } 问题应该是明确的:为什么保存到BMP 会将透明度变为黑色 ,而保存到PNG 会保留它 ? 只是为了澄清: 图像采用Format8bppIndexed格式,其调色板确实包含透明色(例如,它正确地绘制在窗体/图片框上) 编辑:我的错, Bitmap.Save()实际上以Format32bppRgb格式保存BMP,即使位图格式是Format32bppArgb 。

如何防止richTextBox在其中粘贴图像?

我用c#编程。 我上面有一个richTextBox。 在运行时,我通过编码将一些Bitmap图像插入到richTextbox中。 但我想阻止用户拖动插入的图像或粘贴其他一些图像在richTextBox中。 我该如何实现呢? 提前致谢!

将32位位图保存为C#中的1位.bmp文件

在C#中将32位位图转换并保存为1位(黑/白).bmp文件的最简单方法是什么?

将位图保存到文件 – Xamarin,Monodroid

我正在尝试将位图图像保存到手机内的目录(图库)中。 该应用程序正在Xamarin中开发,因此代码是C#。 我似乎无法弄清楚如何创建目录,并保存位图。 有什么建议? public void createBitmap(View view){ view.DrawingCacheEnabled = true; view.BuildDrawingCache (true); Bitmap m_Bitmap = view.GetDrawingCache(true); String storagePath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; Java.IO.File storageDirectory = new Java.IO.File(storagePath); //storageDirectory.mkdirs (); //save the bitmap //MemoryStream stream = new MemoryStream (); //m_Bitmap.Compress (Bitmap.CompressFormat.Png, 100, stream); //stream.Close(); try{ String filePath = storageDirectory.ToString() + “APPNAME.png”; FileOutputStream fos = new FileOutputStream (filePath); […]

如何在.net中将pdf转换为位图图像?

寻找将pdf文件的指定页面转换为位图图像的解决方案。

将位图设置为MP3的封面

我一直试图将位图设置为MP3的封面艺术,但我似乎无法让它工作。 它没有抛出任何错误,但是当我播放MP3时,位图没有显示。 这就是我目前所拥有的: TagLib.File f = TagLib.File.Create(“song.mp3”); Image currentImage = getAlbumArt(result.passedAlbumID); Picture pic = new Picture(); pic.Type = PictureType.FrontCover; pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; pic.Description = “Cover”; MemoryStream ms = new MemoryStream(); currentImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); ms.Position = 0; pic.Data = ByteVector.FromStream(ms); f.Tag.Pictures = new IPicture[1] { pic }; pictureBox1.Image = currentImage; //testing the image is correct f.Save(); ms.Close();

将图像转换为c#中的图标

我有一个项目将图像格式文件转换为图标文件。 但是,在转换图像后,图像的颜色会发生变化。 这是我的代码 Bitmap theBitmap = new Bitmap(theImage, new Size(width, height)); IntPtr Hicon = theBitmap.GetHicon();// Get an Hicon for myBitmap. Icon newIcon = Icon.FromHandle(Hicon);// Create a new icon from the handle. FileStream fs = new FileStream(@”c:\Icon\” + filename + “.ico”, FileMode.OpenOrCreate);//Write Icon to File Stream 谁知道怎么解决这个问题?