我无法将组合图像从一个图片框保存到数据库 [英] I cant save combined images from one picturebox to database
本文介绍了我无法将组合图像从一个图片框保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不能将组合图像从一个PictureBox保存到数据库
单击btnSave时
错误:'System.NullReferenceException'将pictureBoxNemoone.Image转换为位图时
请帮我保存到数据库
谢谢
我尝试过:
private void btnImgNemoone_Click( object sender,EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = JPG Files(* .jpg)| * .jpg;
ofd.Multiselect = true ;
ofd.Title = ?????? ???? ?跨度>;
ofd.ShowDialog();
string fullPath = ofd.FileName;
string directory1;
directory1 = fullPath.Substring( 0 ,fullPath.LastIndexOf(' \\'跨度>));
DirectoryInfo目录= 新 DirectoryInfo(fullPath.Substring( 0 ,fullPath.LastIndexOf(' \\')));
List< system.drawing.bitmap> images = new 列表< system.drawing.bitmap>();
System.Drawing.Bitmap finalImage = null ;
尝试
{
int width = < span class =code-digit> 0 ;
int height = 0 ;
foreach ( string image in ofd.FileNames)
{
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);
width + = bitmap.Width;
height = bitmap.Height > 身高? bitmap.Height:height;
images.Add(bitmap);
}
finalImage = new System.Drawing.Bitmap(width,height);
使用(System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
{
g.Clear(System.Drawing.Color.Black);
int offset = 0 ;
foreach (System.Drawing.Bitmap image in images)
{
g.DrawImage(image,
new System.Drawing.Rectangle(offset, 0 ,image.Width,image.Height));
offset + = image.Width;
}
}
pictureBoxNemoone.Image = finalImage;
}
catch (例外)
{}
}
private void btnSave_Click( object sender,EventArgs e)
{
byte [] ImgNemooneN;
ImgNemooneN = null ;
Bitmap BNemoone =(Bitmap)pictureBoxNemoone.Image;
System.IO.MemoryStream MSNemoone = new System.IO.MemoryStream();
BNemoone.Save(MSNemoone,BNemoone.RawFormat);
ImgNemooneN = MSNemoone.GetBuffer();
}
解决方案
我找到转换编码
private void btnSave_Click( object sender,EventArgs e)
{
byte [] ImgNemooneN;
ImgNemooneN = null ;
MemoryStream ms = new MemoryStream();
pictureBoxNemoone.Image.Save(ms,ImageFormat.Jpeg);
ImgNemooneN = new byte [ms.Length];
ms.Position = 0 ;
ms。阅读(ImgNemooneN, 0 ,ImgNemooneN.Length);
}
I Cant Save Combined Images From One PictureBox To Database
When click btnSave
Error:'System.NullReferenceException' When Convert pictureBoxNemoone.Image To Bitmap
Please Help Me To Save To Database
Thanks
What I have tried:
private void btnImgNemoone_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "JPG Files (*.jpg)|*.jpg";
ofd.Multiselect = true;
ofd.Title = "?????? ??? ?????";
ofd.ShowDialog();
string fullPath = ofd.FileName;
string directory1;
directory1 = fullPath.Substring(0, fullPath.LastIndexOf('\\'));
DirectoryInfo directory = new DirectoryInfo(fullPath.Substring(0, fullPath.LastIndexOf('\\')));
List<system.drawing.bitmap> images = new List<system.drawing.bitmap>();
System.Drawing.Bitmap finalImage = null;
try
{
int width = 0;
int height = 0;
foreach (string image in ofd.FileNames)
{
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);
width += bitmap.Width;
height = bitmap.Height > height ? bitmap.Height : height;
images.Add(bitmap);
}
finalImage = new System.Drawing.Bitmap(width, height);
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
{
g.Clear(System.Drawing.Color.Black);
int offset = 0;
foreach (System.Drawing.Bitmap image in images)
{
g.DrawImage(image,
new System.Drawing.Rectangle(offset, 0, image.Width, image.Height));
offset += image.Width;
}
}
pictureBoxNemoone.Image = finalImage;
}
catch (Exception)
{}
}
private void btnSave_Click(object sender, EventArgs e)
{
byte[] ImgNemooneN;
ImgNemooneN = null;
Bitmap BNemoone = (Bitmap)pictureBoxNemoone.Image;
System.IO.MemoryStream MSNemoone = new System.IO.MemoryStream();
BNemoone.Save(MSNemoone, BNemoone.RawFormat);
ImgNemooneN = MSNemoone.GetBuffer();
}
解决方案
I'm Find Coding For Convert
private void btnSave_Click(object sender, EventArgs e) { byte[] ImgNemooneN; ImgNemooneN = null; MemoryStream ms = new MemoryStream(); pictureBoxNemoone.Image.Save(ms, ImageFormat.Jpeg); ImgNemooneN = new byte[ms.Length]; ms.Position = 0; ms.Read(ImgNemooneN, 0, ImgNemooneN.Length);
}
这篇关于我无法将组合图像从一个图片框保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文