相关疑难解决方法(0)

如何将位图转换为byte []?

基本上我使用listviews插入事件插入图像,尝试从fileupload控件调整图像大小,然后使用LINQ将其保存在SQL数据库中.

我找到了一些代码来在fileupload控件中创建内容的新位图,但这是将它存储在服务器上的一个文件中,从这个来源,但我需要将位图保存回SQL数据库,我认为我需要转换回byte []格式.

那么如何将位图转换为byte []格式?

如果我以错误的方式解决这个问题,我将不胜感激,你可以纠正我.

这是我的代码:

            // Find the fileUpload control
            string filename = uplImage.FileName;

            // Create a bitmap in memory of the content of the fileUpload control
            Bitmap originalBMP = new Bitmap(uplImage.FileContent);

            // Calculate the new image dimensions
            int origWidth = originalBMP.Width;
            int origHeight = originalBMP.Height;
            int sngRatio = origWidth / origHeight;
            int newWidth = 100;
            int newHeight = sngRatio * newWidth;

            // Create a new bitmap which will hold the previous resized bitmap
            Bitmap newBMP …
Run Code Online (Sandbox Code Playgroud)

c# linq byte image-uploading asp.net-3.5

15
推荐指数
3
解决办法
3万
查看次数

标签 统计

asp.net-3.5 ×1

byte ×1

c# ×1

image-uploading ×1

linq ×1