相关疑难解决方法(0)

将图像转换为位图会将背景变为黑色

我需要将图像转换为位图.

最初,gif以字节形式读入,然后转换为Image.

但是,当我尝试将图像转换为位图时,我的图片框中显示的图形在以前是白色时具有黑色背景.

这是代码:

    var image = (System.Drawing.Image)value;
        // Winforms Image we want to get the WPF Image from...
        var bitmap = new System.Windows.Media.Imaging.BitmapImage();
        bitmap.BeginInit();
        MemoryStream memoryStream = new MemoryStream();
        // Save to a memory stream...
        image.Save(memoryStream, ImageFormat.Bmp);
        // Rewind the stream...
        memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
        bitmap.StreamSource = memoryStream;
        bitmap.EndInit();
        return bitmap;
Run Code Online (Sandbox Code Playgroud)

有人可以解释为什么背景会变黑以及我如何阻止它这样做.

谢谢

c# image bitmap

9
推荐指数
1
解决办法
2万
查看次数

保存位图时背景变黑 - C#

我目前正在尝试保存位图图像,但背景正在变为黑色.

我可以"另存为"图像完美无缺.我也可以"保存"图像.这更难,因为我不得不覆盖现有的图像.

但是,当我"保存"我的图像时,背景变黑了.我不知道是什么导致了它.

这是我的代码:

Bitmap tempImage = new Bitmap(DrawArea);

DrawArea.Dispose();

if (extension == ".jpeg")
    tempImage.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
else
    tempImage.Save(fileName, System.Drawing.Imaging.ImageFormat.Bmp);

DrawArea = new Bitmap(tempImage);
pictureBox1.Image = DrawArea;

tempImage.Dispose();
Run Code Online (Sandbox Code Playgroud)

c# bitmap image-processing

8
推荐指数
1
解决办法
2万
查看次数

将透明png颜色转换为单色

我正在使用Bitmap C#并想知道如何将颜色png图像转换为仅一种颜色.我希望图像中的所有可见颜色都变白.透明的部分应保持透明.我将以灰色背景显示这些.

c# transparency bitmap

6
推荐指数
2
解决办法
6620
查看次数

将所有图像转换为jpg

我需要将文件夹和子文件夹中的所有图像转换为jpg.我需要用命令文件批处理这个过程.GUI工具针对我来说我需要脚本.

我尝试使用来自ImageMagick的mogrify.exe,还有convert.exe功能,但是afaik它们都能够转换图像.

我写了下一个脚本:

$rootdir = "E:\Apps\???????\temp1\graphics"
$files = dir -r -i *.png $rootdir
foreach ($file in $files) {.\mogrify.exe -format png *jpg $file}
Run Code Online (Sandbox Code Playgroud)

但它不起作用,当我尝试运行它时,我遇到了错误:

mogrify.exe: unable to open file `*jpg' @ error/png.c/ReadPNGImage/3633.
mogrify.exe: Improper image header `E:\Apps\???????\temp1\graphics\telluric\day\
Athens\2011-07-03-17.png' @ error/png.c/ReadPNGImage/3641.
mogrify.exe: unable to open image `*jpg': Invalid argument @ error/blob.c/OpenBl
ob/2588.
Run Code Online (Sandbox Code Playgroud)

我也找到下一个代码:

[Reflection.Assembly]::LoadWithPartialName('System.Drawing')

$img=[Drawing.Image]::FromFile("$(cd)\Max.jpg")
$img.Save("$(cd)\max.gif", 'Gif')
$img.Dispose()
Run Code Online (Sandbox Code Playgroud)

如何让它与dirs树一起工作并将png和tiff转换为jpg?

powershell imagemagick

6
推荐指数
1
解决办法
1万
查看次数

powershell将透明png转换为jpg

我正在尝试将一堆透明 png 批量转换为 jpg,下面的鹅卵石 powershell 可以工作,但每当我转换时,所有图像都会显示为黑色。我在这里尝试了答案 将透明 PNG 转换为具有非黑色背景颜色的 JPG 但我得到“使用”关键字不受支持(在模块中也找不到它)

$files = Get-ChildItem "C:\Pictures\test" -Filter *.png -file -Recurse | 
foreach-object {

    $Source = $_.FullName
    $test = [System.IO.Path]::GetDirectoryName($source)
    $base= $_.BaseName+".jpg"
    $basedir = $test+"\"+$base
    Write-Host $basedir
    Add-Type -AssemblyName system.drawing
    $imageFormat = "System.Drawing.Imaging.ImageFormat" -as [type]
    $image = [drawing.image]::FromFile($Source)
    $image.Save($basedir, $imageFormat::jpeg)
}  
Run Code Online (Sandbox Code Playgroud)

据我了解,您需要创建一个具有白色背景的新位图图形,并在其上绘制此图像,但我一生都不知道如何添加它。

powershell

4
推荐指数
1
解决办法
4755
查看次数