0
我想将包含jpeg图像的字段中的数据保存到实际的文件中,我可以使用绘制编辑器打开该文件。我知道我可以创建一个应用程序来做到这一点在c#中,但我想知道是否有一个简单的方法来从SQL查询做到这一点?将jpg数据从数据库保存到jpg文件
它不需要一次处理所有记录。我只需要能够选择单个记录并将该记录的图像保存到文件中。
我想将包含jpeg图像的字段中的数据保存到实际的文件中,我可以使用绘制编辑器打开该文件。我知道我可以创建一个应用程序来做到这一点在c#中,但我想知道是否有一个简单的方法来从SQL查询做到这一点?将jpg数据从数据库保存到jpg文件
它不需要一次处理所有记录。我只需要能够选择单个记录并将该记录的图像保存到文件中。
可以使用的MemoryStream对象在C#作为以下的 私有静态字节[] InkToBytes
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();
帮助器函数(串inkStrokes,串encoderType,浮子的x,浮子Y) { 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的人。 – BVernon
或者来自System.Windows.Ink的那个。没有我可以看到的Text属性或带有整数的构造函数。这看起来很有前途,但我似乎无法想出这一部分。 – BVernon