Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用C#将jpg文件转换为位图?_C#_Bitmap - Fatal编程技术网

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

如何使用C#将jpg文件转换为位图?,c#,bitmap,C#,Bitmap,我使用上面的代码将jpg文件转换为位图。它的作品,但我需要知道如何流的jpg图像和转换成位图,然后显示位图图像不存储它。我正在使用c#和vb.net尝试将此转换为位图: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using Sys

我使用上面的代码将jpg文件转换为位图。它的作品,但我需要知道如何流的jpg图像和转换成位图,然后显示位图图像不存储它。我正在使用c#和vb.net

尝试将此转换为位图:

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.
            // ... Then, adjust its height and width properties.
           // pictureBox1.Image = image;
            //pictureBox1.Height = image.Height;
            //pictureBox1.Width = image.Width;

            string strFileName = @"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg";

            Bitmap bitmap = new Bitmap(strFileName);
            //bitmap.Save("testing.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
           pictureBox1.Image = bitmap;
           pictureBox1.Height = bitmap.Height;
           pictureBox1.Width = bitmap.Width;
        }

    }
}
可能更容易:

public Bitmap ConvertToBitmap(string fileName)
{
    Bitmap bitmap;
    using(Stream bmpStream = System.IO.File.Open(fileName, System.IO.FileMode.Open ))
    {
         Image image = Image.FromStream(bmpStream);

         bitmap = new Bitmap(image);

    }
    return bitmap;
}

位图bmp=新位图(新内存流(blob));这很好。但我需要使用网格视图在wpf应用程序中执行此过程。在网格中没有位图,只有位图图像可用。如何执行此操作很好,我对wpf没有太多经验,但请查看此链接,如果您需要的话。
var bitmap = new Bitmap(Image.FromFile(path));