本文介绍了如何将文件传输图像像素大小....转换为用户所需的fomrat大小。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个归档,这是签名在这些,我使用文件上传控制...我上传图像..用户给出一些签名图像..基于... ....什么是大小和什么是像素图片的格式...我想将该签名图像设置为180X35像素大小...但这里的图像宽度和高度是.....获取属性..但我使用的是Bitmap ...但它显示只有浅灰色没有显示任何图像...........以下代码如下....可以重播我...你如何在.aspx.cs文件中设置图像的像素大小 byte [] fileData; if(ImgImages.UploadedFiles.Count> 0) { UploadedFile文件= ImgImages.UploadedFiles [0]; RadBinaryImage RadBi = new RadBinaryImage(); 系统。 Drawing.Image myImage = System.Drawing.Image.FromStream(file.InputStream); 位图b =新位图(myImage); System.Drawing.Im aging.BitmapData bi = new System.Drawing.Imaging.BitmapData(); Bitmap biImageConvert = new Bitmap(180,35,bi.Stride,myImage.PixelFormat,bi.Scan0); byte [] f1 = imageToByteArray(biImageConvert); oCheck.Signature = f1; } public byte [] imageToByteArray(System.Drawing.Bitmap imageIn) { MemoryStream ms = new MemoryStream(); imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif); 返回ms.ToArray(); } 上面代码中的位图错误...为什么我得到灰色图像而不是原始图像...转换后输入图像。I Have One filed that is signature in these ,I am used File upload control... i am upload the image ..user give some signature image..based on that ....what is size and what is pixel format of picture ...I am want to set that signature image to "180X35" pixel size ...but here image width and height is .....get property ..but i am used Bitmap ...but It show Only" Light Gray" not show any image...........the following code is below....can replay me...you how to set pixel size of image in .aspx.cs file byte[] fileData; if (ImgImages.UploadedFiles.Count > 0) { UploadedFile file = ImgImages.UploadedFiles[0]; RadBinaryImage RadBi = new RadBinaryImage(); System.Drawing.Image myImage = System.Drawing.Image.FromStream(file.InputStream); Bitmap b = new Bitmap(myImage); System.Drawing.Imaging.BitmapData bi=new System.Drawing.Imaging.BitmapData(); Bitmap biImageConvert = new Bitmap(180, 35,bi.Stride , myImage.PixelFormat,bi.Scan0); byte [] f1=imageToByteArray(biImageConvert); oCheck.Signature = f1;} public byte[] imageToByteArray(System.Drawing.Bitmap imageIn) { MemoryStream ms = new MemoryStream(); imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); return ms.ToArray(); }where wrong with bitmap in above code...why i am getting gray color image not original one...type image after converstion.推荐答案 System.Drawing.Image myImage = System.Drawing.Image.FromStream(file.InputStream); Bitmap b = new位图(myImage); 这是浪费时间。上次我查看框架代码时,您的图像已经是位图并且可以进行转换。无论哪种方式,为什么不创建位图开始?并且,您不需要执行所有这些操作,您可以创建一个带有位图的构造函数的位图,以及您想要图像的新大小。System.Drawing.Image myImage = System.Drawing.Image.FromStream(file.InputStream);Bitmap b = new Bitmap(myImage);This is a waste of time. Last time I looked at the framework code, your image is already a bitmap and can be cast. Either way, why not just create the Bitmap to start with ? And, you don't need to do all this, you can create a bitmap with a constructor that takes a bitmap, and the new size you want the image to be. if(ImgImages .UploadedFiles.Count> 0) { UploadedFile file = ImgImages.UploadedFiles [0]; fileData = new byte [file。 InputStream.Length]; System.Drawing.Image myImage = System.Drawing.Image.FromStream(file.InputStream); //计算缩略图大小。 大小thumbnailSize = GetThumbnailSize(myImage); //获取缩略图。 System.Drawing.Image thumbnail = myImage.GetThumbnailImage(thumbnailSize.Width,thumbnailSize .Height,null,IntPtr.Zero); fileData = imageToByteArray(thumbnail); oCheck.Signature = fileData; } 静态大小GetThumbnailSize(System.Drawing.Image original) { //任何尺寸的最大尺寸。 const int MaxWidth = 180; const int Maxheight = 35; //宽度和高度。 int originalWidth = original.Width; int originalHeight = original.Height; //计算最佳基于较大尺寸缩放整个图像的因子。 双重因子; 双倍因子1; if(originalWidth> originalHeight) { factor =(double)MaxWidth / originalWidth; factor1 =(double)Maxheight / originalHeight; } 其他 { factor =(double)MaxWidth / originalWidth; factor1 =( double)Maxheight / originalHeight; } //返回缩图尺寸。 //返回新尺寸((int)(originalWidth * factor),(int)(originalHeight * factor)); 返回new size((int)(originalWidth * factor),(int)(originalHeight * factor1)) ; } public byte [] imageToByteArray(System.Drawing.Image imageIn) { MemoryStream ms = new MemoryStream(); imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif); / *这里我们看到格式类型就像你一样可以保存任何格式.png或.Jpeg或.bmp* / 返回ms.ToArray(); } if (ImgImages.UploadedFiles.Count > 0){UploadedFile file = ImgImages.UploadedFiles[0]; fileData = new byte[file.InputStream.Length]; System.Drawing.Image myImage = System.Drawing.Image.FromStream(file.InputStream); // Compute thumbnail size. Size thumbnailSize = GetThumbnailSize(myImage); // Get thumbnail. System.Drawing.Image thumbnail = myImage.GetThumbnailImage(thumbnailSize.Width, thumbnailSize.Height, null, IntPtr.Zero); fileData = imageToByteArray(thumbnail);oCheck.Signature = fileData;}static Size GetThumbnailSize(System.Drawing.Image original) { // Maximum size of any dimension. const int MaxWidth = 180; const int Maxheight = 35; // Width and height. int originalWidth = original.Width; int originalHeight = original.Height; // Compute best factor to scale entire image based on larger dimension. double factor; double factor1; if (originalWidth > originalHeight) { factor = (double) MaxWidth / originalWidth; factor1 = (double)Maxheight / originalHeight; } else { factor = (double)MaxWidth / originalWidth; factor1 = (double)Maxheight / originalHeight; } // Return thumbnail size. //return new Size((int)(originalWidth * factor), (int)(originalHeight * factor)); return new Size((int)(originalWidth*factor),(int) (originalHeight*factor1)); } public byte[] imageToByteArray(System.Drawing.Image imageIn) { MemoryStream ms = new MemoryStream(); imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);/* here we are seen format type like that you can save any format ".png or .Jpeg or .bmp" */ return ms.ToArray(); } 这篇关于如何将文件传输图像像素大小....转换为用户所需的fomrat大小。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 17:52