Sql server 将jpg数据从数据库保存到jpg文件

Sql server 将jpg数据从数据库保存到jpg文件,sql-server,jpeg,Sql Server,Jpeg,我想在一个包含jpeg图像的字段中获取数据,并将其保存到一个实际文件中,我可以使用绘制编辑器打开该文件。我知道我可以用c语言创建一个应用程序来实现这一点,但我想知道是否有一种简单快捷的方法可以从sql查询中实现这一点 它不需要同时处理所有记录。我只需要能够选择一条记录并将该记录的图像保存到一个文件中。您可以使用C中的MemoryStream对象,如下所示 MemoryStream memstmSignature = new MemoryStream(InkToBytes(ds.Tables[1]

我想在一个包含jpeg图像的字段中获取数据,并将其保存到一个实际文件中,我可以使用绘制编辑器打开该文件。我知道我可以用c语言创建一个应用程序来实现这一点,但我想知道是否有一种简单快捷的方法可以从sql查询中实现这一点


它不需要同时处理所有记录。我只需要能够选择一条记录并将该记录的图像保存到一个文件中。

您可以使用C中的MemoryStream对象,如下所示

MemoryStream memstmSignature = new MemoryStream(InkToBytes(ds.Tables[1].Rows[0]["SIGNATURE"].ToString(), "image/gif", 0, 0));
Image imaSig = Image.FromStream(memstmSignature);
imaSig.RotateFlip(RotateFlipType.Rotate180FlipX);
imaSig.Save(Path.Combine(this.temporaryFilePath, this.signatureFileName));
memstmSignature.Close();
助手功能如下 私有静态字节[]InktoBytes字符串inkStrokes,字符串编码器类型,浮点x,浮点y { ArrayList笔划=新的ArrayList

        // max size for bit map
        int maxX = 0;
        int maxY = 0;

        // intialize the strokes array with text string
        int strokesCount;
        if (inkStrokes.Length > 0)
        {
            if (inkStrokes.EndsWith(";"))
                inkStrokes = inkStrokes.Remove((inkStrokes.Length - 1), 1);

            char[] strokeSeperator = { ';' };
            string[] strokeArray = inkStrokes.Split(strokeSeperator);
            strokesCount = strokeArray.Length;

            for (int i = 0; i < strokesCount; i++)
            {
                Stroke stroke = new Stroke(50);
                stroke.Text = strokeArray[i];
                strokes.Add(stroke);

                Point[] points = stroke.ToPointArray();
                int len = points.Length;
                foreach (Point point in points)
                {
                    maxX = (point.X > maxX ? point.X : maxX);
                    maxY = (point.Y > maxY ? point.Y : maxY);
                }
            }
        }

        // setup the gdi objects
        Bitmap bitMap = new Bitmap(maxX + 20, maxY + 20); // leave some buffer room
        Graphics graphics = Graphics.FromImage(bitMap);
        Rectangle clientRect = new Rectangle(0, 0, bitMap.Width, bitMap.Height);
        Pen pen = new Pen(Color.Black);
        pen.Width = 2; // matches the client capture

        // draw the bit map
        if (x > 0 && y > 0)
            graphics.DrawImage(bitMap, x, y);
        else
            graphics.DrawImage(bitMap, 0, 0);
        graphics.FillRectangle(Brushes.White, clientRect);
        graphics.DrawRectangle(pen, clientRect);
        strokesCount = strokes.Count;
        for (int j = 0; j < strokesCount; j++)
        {
            Stroke stroke = (Stroke)strokes[j];
            if (stroke != null)
            {
                Point[] points = stroke.ToPointArray();
                int len = points.Length;
                if (len > 1)
                {
                    Point prevPoint = points[0];
                    for (int i = 1; i < len; i++)
                    {
                        graphics.DrawLine(pen, prevPoint.X, prevPoint.Y, points[i].X, points[i].Y);
                        prevPoint = points[i];
                    }
                }
            }
        }

        // create the bytes from the bitmap to be returned
        MemoryStream memStream = new MemoryStream(1000);
        ImageCodecInfo imageCodedInfo = GetEncoderInfo(encoderType);
        bitMap.Save(memStream, imageCodedInfo, null);
        byte[] bytes = memStream.GetBuffer();
        memStream.Close();
        return bytes;
    }

    private static ImageCodecInfo GetEncoderInfo(String mimeType)
    {
        int j;
        ImageCodecInfo[] encoders;
        encoders = ImageCodecInfo.GetImageEncoders();
        for (j = 0; j < encoders.Length; ++j)
        {
            if (encoders[j].MimeType == mimeType)
                return encoders[j];
        }
        return null;
    }
希望这有帮助。
注意:我还没有研究优化上述代码

你从哪里获得Stroke类?看起来不是来自Microsoft.Ink的,也不是来自System.Windows.Ink的。上面没有我可以看到的文本属性,也没有接受整数的构造函数。这看起来很有希望,但我似乎无法理解至少有一部分。