• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

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

用户头像
it1352
帮助4

问题说明

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:UsersPublicPicturesSample PicturesKoala.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:UsersPublicPicturesSample PicturesKoala.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;
        }

    }
}

我正在使用上面的代码将 jpg 文件转换为位图.它有效,但我需要知道如何流式传输 jpg 图像并将其转换为位图,然后显示位图图像而不存储它.我正在使用 c# 和 vb.net

I am using the above code for converting jpg file into bitmap. It works but I need to know how to stream the jpg image and convert it into bitmap then display the bitmap image with out storing it. I am using c# and vb.net

正确答案

#1

试试这个转换为 Bitmap :

Try this to convert to Bitmap :

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;
}

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tangicaga
系列文章
更多 icon
同类精品
更多 icon
继续加载