Q2:如果图片文件很大,使用哪种方法更高效?
如果图片文件很大,建议使用
HttpPostedFileBase
方法,因为它直接从上传文件流中读取数据,而不需要将整个文件加载到内存中,这样可以减少内存消耗,提高处理效率。
vb.net如何将图片转二进制
容易,用api,查一查SetBitmapBits新建工程,增加一个 command button , 一个 picture box , 将图片加载到 picture box.将代码粘贴到 Form1Private Type BITMAPbmType As LongbmWidth As LongbmHeight As LongbmWidthBytes As LongbmPlanes As IntegerbmBitsPixel As IntegerbmBits As LongEnd TypePrivate Declare Function GetObject Lib gdi32 Alias GetObjectA (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As LongPrivate Declare Function GetBitmapBits Lib gdi32 (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As LongPrivate Declare Function SetBitmapBits Lib gdi32 (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As LongDim PicBits() As Byte, PicInfo As BITMAP, Cnt As LongPrivate Sub Command1_Click()Get information (such as height and width) about the pictureboxGetObject , Len(PicInfo), PicInforeallocate storage spaceReDim PicBits(1 To * * 3) As ByteCopy the bitmapbits to the arrayGetBitmapBits , UBound(PicBits), PicBits(1)Invert the bitsFor Cnt = 1 To UBound(PicBits)PicBits(Cnt) = 255 - PicBits(Cnt)Next CntSet the bits back to the pictureSetBitmapBits , UBound(PicBits), PicBits(1) Sub
在c#中,为什么要将图片转换为字节流(或者二进制流)才能输出?这里的“输出”指的是到哪儿?谢谢!
一定要知道输出和显示是两个不一样的概念。 显示只是输出的一种形式,即把图片信息输出到显示设备上。 但输出还有很多种其他的形式,比如将数据输出并保存到文件中、将数据输出到网络设备上进行传输...而且这些输出一般是指从内存中输出到其他的地方。 至于为什么要转换成二进制流,这就是计算机组成原理或者微机原理上的知识了,一句话两句话也解释不清楚。 反正计算机逻辑上是只认识二进制数据的,即1和0,物理上就是高低电平。 像你在编程中用到的数据类型int、long等等,实际上操作系统或者更底层的设备最终都会把它转换成32位的二进制数据。
asp.net问题ashx文件有什么用
? 引自网络... ----------- 2.0 Person Web Site:将图片以二进制的从数据库读取 在 Person Web Site Starter Kits中,图片的是以二进制的形式存放在数据库里,微软提供的读取该图片的方式是通过来实现的. 首先你所看到的对图片的引用都是类似如下 的形式,也就是你所看到的每一个图片都由动态生成,所以在你保存你所看到的图片时,它的命名都是. 使用而不是来引用图片并不是一定的,换句话说,你可以将该文件改为并没有本质的区别,不过根据微软的文档,使用*作为扩展名的文档比*的文档性能高,因为它减少了控件树的生成. ---------- 这是代码: <%@ WebHandler Language=C# %> using System; using ; using ; using ; using ; using ; using ; public class MyHandle : IHttpHandler { public void ProcessRequest (HttpContext context) { //从数据库中取 MemoryStream ms = (1); DataTable dt = (1); Byte[] image = (Byte[])[0][Photo]; MemoryStream ms = new MemoryStream(image, 0, ); if (ms != null) { //取得图像MemoryStream大小 int bufferSize = (int); //建立 buffer byte[] buffer = new byte[bufferSize]; //调用,自MemoryStream 读取至buffer,并返回count int countSize = (buffer, 0, bufferSize); //返回图像buffer (buffer, 0, countSize); } } public bool IsReusable { get { return false; } } }














发表评论