保存到DB后,图像有条形图 [英] Image has bars after saving to DB

查看:114
本文介绍了保存到DB后,图像有条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用emgu.CV libs从网络摄像头捕获图像。

保存到数据库后,图像上有检索条。



我尝试过:



这个代号:

I have captured image from webcam, using emgu.CV libs.
after saving to DB, the image has bars on retrieval.

What I have tried:

this isnmy code:

Bitmap bitmap = new Bitmap(CamImageBox.Image.Bitmap);
                Image img = (Image)bitmap;
                byte[] passportByte = ProcessImageData.CopyImageToByteArray(img);

  public static  Byte[] ImageToByte(Bitmap imageSource)
        {
            Byte[] buffer = null;
            MemoryStream stream = new MemoryStream();
            imageSource.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
            buffer = stream.ToArray();
            return buffer;
        }







检索我有。






Retrieving i have.

public static Bitmap GetImageFromByteArray(byte[] byteArray)
        {
            Bitmap bm = (Bitmap)_imageConverter.ConvertFrom(byteArray);

            if (bm != null && (bm.HorizontalResolution != (int)bm.HorizontalResolution ||
                               bm.VerticalResolution != (int)bm.VerticalResolution))
            {
                
                bm.SetResolution((int)(bm.HorizontalResolution + 0.5f),
                                 (int)(bm.VerticalResolution + 0.5f));
            }

            return bm;
        }





谢谢。



thanks.

推荐答案

从你的开始 _imageConverter.ConvertFrom 方法并查看它的作用以及返回的内容。

我的方式是:

Start with your _imageConverter.ConvertFrom method and see what it does, and what it returns.
The way I do it is:
byte[] data = (byte[])reader["Picture"];
using (MemoryStream stream = new MemoryStream(bytes))
    {
    myImage = new Bitmap(stream);
    }

您使用的图像到字节数组代码与我的相同。

在将分辨率设置为之前查看图像好吧 - 注释代码以确保它不会导致问题。

如果这不能解决问题,那么请查看保存到数据库的输入图像并确保条形码不是在你将它转换为字节数组之前就已经开始了。

The "Image to byte array" code you use is the same as mine.
Look at the image before you set the resolution as well - comment that code out to ensure it isn't causing the problem.
If that doesn't fix it, then look at the input image that you save to the DB and make sure the bars aren't on that before you convert it to a byte array.


我知道了,

i必须使位图的大小变得简单

到托管它的图像控件的大小。

感谢您的贡献。
I got it,
i had to soecify the size of the bitmap
to the size of the image control hosting it.
Thanks for your contribution.


这篇关于保存到DB后,图像有条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆