導航:首頁 > 源碼編譯 > 私人圖片儲存系統源碼

私人圖片儲存系統源碼

發布時間:2024-03-18 01:45:13

㈠ VB 修改圖片的尺寸並保存,比如現有圖片256*128,我要修改成15*15的尺寸,要源碼

首先,聲明以下核心代碼部分完全照抄,由CSDN上laviewpbt提供,我在之前一篇VB常見問題里給出過鏈接。當時提到VB的效率問題,我舉
出圖片縮放的例子,用VB寫的圖片縮放,效率居然很高,以此證明演算法的重要性。laviewpbt又是受到了CSDN上zyl910,本名好像叫周岳靈的
激發,結果做出的程序效率更加驚人。有興趣的可以看看我這篇文章里給出的論壇鏈接。
所以,我這里用的解決方法就是從他們這里得來。不過這些高人們關注的是效率,程序裡面有很大篇幅是不同演算法比較,已經時間測試。而對於更加關心使用的人來說,代碼需要裁剪。我粗略的篩選了下,對模塊內容沒有改動,而只是從主程序里撥出我們需要的內容。
那麼,就開始吧。
首先,用到三個模塊和一個類模塊,這部分代碼我們不用重寫了。程序搭建時候添加進去。需要說明的是,如果你已經有一個在做的項目,那麼簡單的導入模塊可能是不行的。laviewpbt給我們做了一個很好的示範,他的API聲明都是在一個模塊裡面的,那麼你的項目最好也這樣,然後,把他的API聲明貼在後面,運行程序時候如果有重復,會自動找到,然後你就停掉他,注釋掉或者刪除。這幾個模塊的內容我最後貼出,這里到現在也不能上傳附件。
那麼,我們重點要介紹怎麼用。
Private DIBData As CImagePrivate DIBWork As CImage
首先要聲明兩個類變數。這個是我們自定義的類。在模塊里。
接著兩段代碼,一個載入圖片,一個改變圖片大小。
我們要打開圖片,初始化上面這兩個量,初始化過程寫在 form_load裡面
Set DIBData = New CImage
Set DIBWork = New CImage
scaNum = 1 '這個是比例
scaWidth = Me.Width '這個是窗體寬度的初始參照值
Picture1.Picture = LoadPicture(App.Path & "\手球場地小圖.jpg")
Dim DIBTemp As New CImage
If DIBTemp.LoadPictureFromFile(App.Path & "\手球場地小圖.jpg") = True Then
Set DIBData = DIBTemp
DIBWork.DisposeResource

Picture1.Width = DIBData.Width
Picture1.Height = DIBData.Height
DIBData.Render Picture1.Hdc
Picture1.Refresh
Else
MsgBox "錯誤的圖像文件", vbCritical
End If
Set DIBTemp = Nothing

當窗體大小變化的時候,我們再寫一段代碼改變圖片大小已經PictureBox大小任務就完成了。
需要說明的是,以下調用的代碼,對尺寸的計量單位是pixel,而VB窗體默認的計量單位是Tiwp,顯示器上一個pixel裡面可以有很多twip,如果你做出來的程序,圖像順暢顯示了,但是就是很小,那麼,恭喜你,你成功了,只是需要將尺寸轉換成vb裡面的tiwp,
乘以 Screen.TwipsPerPixelX
這段代碼如下:
Dim W As Long, H As Long
W = DIBData.Width * scaNum
H = DIBData.Height * scaNum
If W < 1 Then W = 1 If H < 1 Then H = 1
Dim DIBTemp As New CImage
Dim t As Currency
Me.MousePointer = vbHourglass
t = Utility.GetCurrentTime
Set DIBTemp = Resample(DIBData, W, H, 2) '這里固定選擇一個演算法,雙線性內插值
' t = GetCurrentTime - t
Me.MousePointer = vbDefault
' Me.Caption = " 處理時間:" & Format(t / 1000, "##,###,##0.000") & "秒"
Set DIBWork = DIBTemp
Set DIBTemp = Nothing
PicData.Width = DIBWork.Width * Screen.TwipsPerPixelX
PicData.Height = DIBWork.Height * Screen.TwipsPerPixelX
DIBWork.Render PicData.Hdc
' SolNum
PicData.Refresh
代碼被我注釋掉一部分,原代碼中有時間測試內容。
把這段代碼獨立成一個Sub,然後在form_reSize裡面調用,當然,調用之前首先要計算變化比例scaNum

下面開貼模塊代碼
模塊一、ImageResize模塊:
Option Explicit
Public Enum ResizeModeConst
SMC_Nearest = 0 '最鄰近插值
SMC_StretchBlt = 1 'StretchBlt
SMC_BiliNear = 2 '雙線性內插值
End Enum

Public
Function Resample(Img As CImage, NewWidth As Long, NewHeight As Long,
Optional Method As ResizeModeConst = SMC_BiliNear) As CImage
Dim X As Long, Y As Long
Dim XX As Long, YY As Long
Dim OldYY As Long
Dim Width As Long, Height As Long
Dim Sa As SAFEARRAY, SaN As SAFEARRAY
Dim ImageData() As Byte, NewImageData() As Byte
Dim Stride As Long, NewStride As Long
Dim Offset As Long

Dim Speed As Long, SpeedN As Long
Dim NewImg As New CImage
If NewImg.CreateNewImage(NewWidth, NewHeight) = True Then

With Sa
.Element = 1
.Dimension = 1
.Bounds.Elements = Img.Stride * Img.Height
.Pointer = Img.Pointer
End With
CopyMemory ByVal VarPtrArray(ImageData()), VarPtr(Sa), 4

With SaN
.Element = 1
.Dimension = 1
.Bounds.Elements = NewImg.Stride * NewImg.Height
.Pointer = NewImg.Pointer
End With
CopyMemory ByVal VarPtrArray(NewImageData()), VarPtr(SaN), 4

Width = Img.Width: Height = Img.Height
Stride = Img.Stride: NewStride = NewImg.Stride

ReDim LinearRow(NewWidth - 1) As Long

Select Case Method

Case ResizeModeConst.SMC_Nearest

OldYY = -1
For X = 0 To NewWidth - 1
LinearRow(X) = (X * Width \ NewWidth) * 3
Next
For Y = 0 To NewHeight - 1
SpeedN = Y * NewStride
YY = Y * Height \ NewHeight
Offset = YY * Stride
If YY = OldYY Then
CopyMemory NewImageData(SpeedN), NewImageData(SpeedN - NewStride), NewStride
Else
OldYY = YY
For X = 0 To NewWidth - 1
Speed = Offset + LinearRow(X)
NewImageData(SpeedN) = ImageData(Speed)
NewImageData(SpeedN + 1) = ImageData(Speed + 1)
NewImageData(SpeedN + 2) = ImageData(Speed + 2)
SpeedN = SpeedN + 3
Next
End If
Next

Case ResizeModeConst.SMC_StretchBlt
Img.Render NewImg.Hdc, 0, 0, NewImg.Width, NewImg.Height, 0, 0, Img.Width, Img.Height

Case ResizeModeConst.SMC_BiliNear
Dim PartXX As Long, PartYY As Long
Dim InvertXX As Long, InvertYY As Long
Dim NewX As Long, NewY As Long
Dim SpeedP As Long, ColOffset As Long
Dim Pos As Double
ReDim RowOffset(NewWidth - 1) As Long
ReDim RowPartXX(NewWidth - 1) As Long
For X = 0 To NewWidth - 1
Pos = X * (Width - 1) / NewWidth
RowOffset(X) = Int(Pos) * 3
RowPartXX(X) = (Pos - Int(Pos)) * 2048
Next

For Y = 0 To NewHeight - 1
SpeedN = Y * NewStride
Pos = Y * (Height - 1) / NewHeight
PartYY = (Pos - Int(Pos)) * 2048
InvertYY = 2048 - PartYY
ColOffset = Int(Pos) * Stride
For X = 0 To NewWidth - 1
PartXX = RowPartXX(X)
InvertXX = 2048 - PartXX
Speed = ColOffset + RowOffset(X)
SpeedP = Speed + Stride

NewImageData(SpeedN + 2) = ((ImageData(Speed + 2) * InvertXX +
ImageData(Speed + 5) * PartXX) * InvertYY + (ImageData(SpeedP + 2) *
InvertXX + ImageData(SpeedP + 5) * PartXX) * PartYY) \ 4194304

NewImageData(SpeedN + 1) = ((ImageData(Speed + 1) * InvertXX +
ImageData(Speed + 4) * PartXX) * InvertYY + (ImageData(SpeedP + 1) *
InvertXX + ImageData(SpeedP + 4) * PartXX) * PartYY) \ 4194304

NewImageData(SpeedN) = ((ImageData(Speed) * InvertXX + ImageData(Speed +
3) * PartXX) * InvertYY + (ImageData(SpeedP) * InvertXX +
ImageData(SpeedP + 3) * PartXX) * PartYY) \ 4194304
SpeedN = SpeedN + 3
Next
Next

End Select

CopyMemory ByVal VarPtrArray(ImageData()), 0&, 4
CopyMemory ByVal VarPtrArray(NewImageData()), 0&, 4
End If
Set Resample = NewImg
End Function

模塊2、可以忽略的和時間測試有關部分,內容不多,也貼出
Private SystemFrequency As Currency
Public Function GetCurrentTime() As Currency
If SystemFrequency = 0 Then '未初始化
If QueryPerformanceFrequency(SystemFrequency) = 0 Then
SystemFrequency = ERRORINDEX '無高精度計數器
End If
End If
If SystemFrequency <> ERRORINDEX Then
Dim CurCount As Currency
QueryPerformanceCounter CurCount
GetCurrentTime = CurCount * 1000@ / SystemFrequency
Else
GetCurrentTime = GetTickCount()
End If
End Function

模塊3、API聲明部分,需要你自己解決沖突問題。
Option Explicit
Public Const ERRORINDEX As Long = -1
Public Const DIB_RGB_COLORS As Long = 0
Public Const BI_RGB As Long = 0 '正常
Public Const STRETCH_ANDSCANS As Long = 1
Public Const STRETCH_DELETESCANS As Long = 3
Public Const STRETCH_HALFTONE As Long = 4
Public Const STRETCH_ORSCANS As Long = 2
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Type RGBQUAD
Blue As Byte
Green As Byte
Red As Byte
Alpha As Byte
End Type
Public Type LOGPALETTE
palVersion As Integer
palNumEntries As Integer
palPalEntry(255) As RGBQUAD
End Type
Public Type SAFEARRAYBOUND
Elements As Long
lLbound As Long
End Type
Public Type SAFEARRAY2D
Dimension As Integer
Features As Integer
Element As Long
Locks As Long
Pointer As Long
Bounds(1) As SAFEARRAYBOUND
End Type
Public Type SAFEARRAY
Dimension As Integer
Features As Integer
Element As Long
Locks As Long
Pointer As Long
Bounds As SAFEARRAYBOUND
End Type
Public Type BITMAPINFOHEADER
Size As Long
Width As Long
Height As Long
Planes As Integer
BitCount As Integer
Compression As Long
SizeImage As Long
XPelsPerMeter As Long
YPelsPerMeter As Long
ClrUsed As Long
ClrImportant As Long
End Type
Public Type BITMAPINFO
Header As BITMAPINFOHEADER
Palette(255) As RGBQUAD
End Type
Public Type Bitmap
Type As Long
Width As Long
Height As Long
WidthBytes As Long
Planes As Integer
BitsPixel As Integer
Bits As Long
End Type
'
'內存操作相關API
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpDst As Any, lpSrc As Any, ByVal ByteLength As Long)
Public Declare Sub ZeroMemory Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, ByVal numBytes As Long)
Public
Declare Sub FillMemory Lib "kernel32.dll" Alias "RtlFillMemory" (ByRef
Destination As Any, ByVal Length As Long, ByVal Fill As Byte)
'VB本體API
Public
Declare Function OleLoadPicture Lib "olepro32" (pStream As Any, ByVal
lSize As Long, ByVal fRunmode As Long, riid As Any, ppvObj As Any) As
Long
Public Declare Function SafeArrayGetDim Lib "oleaut32.dll" (ByRef saArray() As Any) As Long
Public Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (ByRef Ptr() As Any) As Long
'GDI系統API函數
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal Hdc As Long) As Long
Public
Declare Function CreateDIBSection Lib "gdi32.dll" (ByVal Hdc As Long,
ByRef pBitmapInfo As Any, ByVal un As Long, ByRef Pointer As Long, ByVal
Handle As Long, ByVal Dw As Long) As Long
Public Declare Function DeleteDC Lib "gdi32.dll" (ByVal Hdc As Long) As Long
Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal Hdc As Long) As Long
Public Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Public
Declare Function SetDIBColorTable Lib "gdi32" (ByVal Hdc As Long, ByVal
un1 As Long, ByVal un2 As Long, pcRGBQuad As RGBQUAD) As Long
Public
Declare Function GetDIBColorTable Lib "gdi32" (ByVal Hdc As Long, ByVal
un1 As Long, ByVal un2 As Long, pRGBQuad As RGBQUAD) As Long
Public Declare Function SelectObject Lib "gdi32.dll" (ByVal Hdc As Long, ByVal hObject As Long) As Long
Public
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As
Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long,
ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal
dwRop As Long) As Long
Public Declare Function SetStretchBltMode Lib "gdi32" (ByVal Hdc As Long, ByVal nStretchMode As Long) As Long
Public
Declare Function StretchBlt Lib "gdi32" (ByVal Hdc As Long, ByVal X As
Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long,
ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal
nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As
Long
Public Declare Function SetDIBitsToDevice Lib "gdi32" (ByVal Hdc
As Long, ByVal X As Long, ByVal Y As Long, ByVal dx As Long, ByVal dy
As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal Scan As Long,
ByVal NumScans As Long, Bits As Any, BitsInfo As BITMAPINFO, ByVal
wUsage As Long) As Long
Public Declare Function GetTickCount Lib "kernel32" () As Long
Public Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
Public Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
類模塊、CImage;文件名CImage.cls
Option Explicit
Private m_Width As Long '層的寬度
Private m_Height As Long '層的高度
Private m_Stride As Long '層數據每個掃描行的大小
Private m_Hdc As Long '層的內存DC
Private m_Pointer As Long '層數據在內存的首地址w
Private m_Handle As Long 'DIBSection的句柄
Private m_OldHandle As Long '原始設備環境的句柄
Public Property Get Width() As Long
Width = m_Width
End Property
Public Property Get Height() As Long
Height = m_Height
End Property
Public Property Get Stride() As Long
Stride = m_Stride
End Property
Public Property Get Hdc() As Long
Hdc = m_Hdc
End Property
Public Property Get Handle() As Long
Handle = m_Handle
End Property
Public Property Get Pointer() As Long
Pointer = m_Pointer
End Property
Private Sub Class_Terminate()
DisposeResource
End Sub
Public Function CreateNewImage(ByVal Width As Long, _ ByVal Height As Long) As Boolean
Dim ScreenDC As Long, BmpInfo As BITMAPINFOHEADER
If Width <= 0 Or Height <= 0 Then Exit Function
DisposeResource '刪除原始的內存資源
With BmpInfo
.BitCount = 24
.Height = -Height '為了和GDI對象的坐標系統(起點坐標在左上角),建立一個倒序的DIB
.Width = Width
.Planes = 1
.Size = 40
m_Stride = ((Width * 3 + 3) And &HFFFFFFFC)
.SizeImage = m_Stride * Height
End With
ScreenDC = GetDC(0) '得到屏幕DC
m_Hdc = CreateCompatibleDC(ScreenDC)
ReleaseDC 0, ScreenDC '釋放屏幕DC
m_Handle = CreateDIBSection(m_Hdc, BmpInfo, DIB_RGB_COLORS, m_Pointer, 0, 0)
If m_Handle <> 0 Then '希望系統能夠讓我們成功創建DIB吧
m_OldHandle = SelectObject(m_Hdc, m_Handle)
m_Width = Width: m_Height = Height
CreateNewImage = True
End If
End Function
Public Sub DisposeResource()
If m_Hdc <> 0 Then
SelectObject m_Hdc, m_OldHandle
DeleteDC m_Hdc
DeleteObject m_Handle
m_Width = 0: m_Height = 0 '重置其他的圖像相關屬性
m_Handle = 0: m_OldHandle = 0
m_Pointer = 0: m_Hdc = 0
End If
End Sub
Public Function Render(ByVal DestDC As Long, _
Optional ByVal DestX As Long, _
Optional ByVal DestY As Long, _
Optional ByVal DestWidth As Long, _
Optional ByVal DestHeight As Long, _
Optional ByVal SrcX As Long, _
Optional ByVal SrcY As Long, _
Optional ByVal SrcWidth As Long, _
Optional ByVal SrcHeight As Long) As Boolean
If m_Handle = 0 Then Exit Function

If DestWidth = 0 Then DestWidth = m_Width
If DestHeight = 0 Then DestHeight = m_Height
If SrcX < 0 Then SrcX = 0 ' 源X,Y不能為負,但目的X,Y可以
If SrcY < 0 Then SrcY = 0
If SrcWidth = 0 Then
SrcWidth = m_Width
ElseIf SrcWidth < 0 Then
DestWidth = -DestWidth
SrcWidth = -SrcWidth
End If
If SrcHeight = 0 Then
SrcHeight = m_Height
ElseIf SrcHeight < 0 Then
DestHeight = -DestHeight
SrcHeight = -SrcHeight
End If
SetStretchBltMode DestDC, STRETCH_HALFTONE
StretchBlt DestDC, DestX, DestY, DestWidth, DestHeight, m_Hdc, SrcX, SrcY, SrcWidth, SrcHeight, vbSrcCopy
End Function
Public Function LoadPictureFromFile(FileName As String) As Boolean
Dim Width As Long, Height As Long
Dim StdPic As StdPicture
On Error GoTo Errhandle:
Set StdPic = LoadPicture(FileName)
Width = ConvertHimetrixToPixels(StdPic.Width, True)
Height = ConvertHimetrixToPixels(StdPic.Height, False)
If CreateNewImage(Width, Height) = True Then

StdPic.Render m_Hdc + 0&, 0&, 0&, Width + 0&, Height +
0&, 0, StdPic.Height, StdPic.Width, -StdPic.Height, ByVal 0
'類似於BMP的逆序存儲,所以用-StdPic.Height
LoadPictureFromFile = True
End If
Errhandle:

End Function
Private Function ConvertHimetrixToPixels(HiMetrix As Long, Horizontally As Boolean) As Long
If Horizontally Then
ConvertHimetrixToPixels = HiMetrix * 1440 / 2540 / Screen.TwipsPerPixelX
Else
ConvertHimetrixToPixels = HiMetrix * 1440 / 2540 / Screen.TwipsPerPixelY
End If
End Function
Private Function ConvertPixelsToHimetrix(Pixels As Long, Horizontally As Boolean) As Long
If Horizontally Then
ConvertPixelsToHimetrix = Pixels * Screen.TwipsPerPixelX * 2540 / 1440
Else
ConvertPixelsToHimetrix = Pixels * Screen.TwipsPerPixelY * 2540 / 1440
End IfEnd Function

㈡ 求一個能上傳小說和圖片的網站源碼

這是我用的asp的,圖片存在UpImages文件下,圖片文件存在數庫里,別外你自添加數據連接吧;
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>寫日記</title>
<% if session("user")="" then
response.write"非法操作"
response.end
end if
%>
<link href="Css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
td { font-size: 12px; line-height: 18px; border-style: none; color: #333333}
body {
background-image: url(image/94d48012f93a637cf819b897.jpg);
}
.STYLE10 {font-size: 10px; font-family: "宋體"; }
.STYLE12 {font-size: 12px; font-family: "楷體_GB2312"; }
-->
</style></head>
<!--#include file="Conn.asp"-->
<body>
<table width="800" border="0" align="center" cellspacing="0">
<tr>
<th align="right" scope="col"> <span class="STYLE12">
<script language="javaScript" type="text/javascript">

var pp,mm,month;
mydate=new Date();
pp=mydate.getDay();
month=mydate.getMonth()+1;
switch(pp)
{case 0: mm="星期日";break;
case 1: mm="星期一";break;
case 2:mm="星期二";break;
case 3: mm="星期三";break;
case 4: mm="星期四" ;break;
case 5 : mm="星期五";break;
case 6 : mm="星期六";break;
}
document.write("今天是:"+mydate.getYear()+"年"+month+"月"+mydate.getDate()

+"日"+" "+mm+" ");
</script>
</span></th>
</tr>
<tr>
<th height="40" scope="col"><img src="image/top.gif" width="800" height="157" alt="書叢製作" /></th>
</tr>
<tr>
<td height="25" align="center" background="image/ph.gif">寫文章</td>
</tr>
</table>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#CCFFFF"><form action="write.asp?action=Addnew" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="138" align="right">文章標題:</td>
<td colspan="2"><label>
<input name="title" type="text" id="title" />
</label></td>
</tr>
<tr>
<td align="right"></td>
<td width="236"><label></label>
<label for="file"></label>
<input type="file" name="file" id="file" /></td>
<td width="426"> 心情狀態:
<select name="select">
<option value="一般" selected="selected">一般</option>
<option value="非常愉快">非常愉快</option>
<option value="愉快">愉快</option>
<option value="不好">不好</option>
<option value="失落">失落</option>
</select></td>
</tr>
<tr>
<td align="right">文章內容:</td>
<td colspan="2"><label>
<textarea name="content" cols="80" rows="20" id="content"></textarea>
</label></td>
</tr>
<tr>
<td align="right">操作:</td>
<td colspan="2"><label>
<input type="submit" name="Submit" value="提交" />
</label></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<table width="800" border="0" align="center" cellspacing="0">
<tr>
<th height="3" scope="col"><hr size="1" /></th>
</tr>
</table>
<table width="800" border="0" align="center" cellspacing="0">
<tr>
<th align="center" scope="col"><span class="STYLE10">Copyright 2009 ? www.pttjj.com.cn All Rights Reserved.<br />
版權所有: | 技術支持:<a href="mailto:[email protected]">書叢</a> | 渝ICP備000**0號 </span></th>
</tr>
</table>
<%
if request("action") = "Addnew" then
newline = chrB(13) & chrB(10) 'newline表示二進制的回車符
filesize = Request.TotalBytes 'filesize是表單數據大小
filedata = Request.BinaryRead(filesize) 'filedata是表單的二進制數據
divider = leftB(filedata,clng(instrb(filedata,newline))-1) 'divider是分割符
Set Rs = Server.CreateObject("ADODB.RecordSet")
Sql="Select * From word"
Rs.Open Sql,conn,3,3
Rs.addnew
k = 1
While instrb(k,filedata,divider) < instrb((instrb(k,filedata,divider)+lenb(divider)),filedata,divider)
start = instrb(k,filedata,divider) + lenb(divider) +2
endsize = instrb((instrb(k,filedata,divider) + lenb(divider)),filedata,divider) - start - 2
content = midb(filedata,start,endsize) '取文件說明部分
start_name = instrb(content,toByte("name="""))
end_name = instrb(start_name + 6,content,toByte(""""))
nametag = midb(content,start_name+6,end_name-start_name-6) '取文件說明部分中name=""中的內容,即表單元素的名稱
pos1_filename = instrb(end_name,content,toByte("filename="""))
'如果是文件框,則文件說明部分應有filename="",那麼pos1_filename不等於0
If pos1_filename = 0 Then '表單中不屬於文件上傳的數據處理
namevalue = toStr(midb(content,end_name+5,lenb(content)-end_name-4)) '取文件內容
' 將文件說明部分的name=""中的內容與表單元素的名稱進行比較,把相應的內容加入資料庫

If(InStr(toStr(nametag),"file") > 0)Then 'CenterID2'為表單控制項的name屬性值,以下同
Rs("image") = namevalue
session("CenterID") = namevalue '用於上傳文件保存時的文件名中
End If
If(InStr(toStr(nametag),"title") > 0)Then
Rs("title") = namevalue
if namevalue="" then
Response.Write "<Script>alert('請輸入標題!')</Script>"
response.end
end if
End If
If(InStr(toStr(nametag),"content") > 0)Then
Rs("content") = namevalue
if namevalue="" then
Response.Write "<Script>alert('請輸入內容!')</Script>"
response.end
end if
End If

If(InStr(toStr(nametag),"select") > 0)Then
Set Rs1 = Server.CreateObject("ADODB.RecordSet")
Sql="Select * From mun"
Rs1.Open Sql,conn,3,3
Rs1("mun")=namevalue
Rs1.update
Rs1.Close
Set Rs1=nothing
End If
Rs("wtime") = year(now)&"-"&month(now)&"-"&day(now)

'Response.Write (namevalue)
'Response.Write(" <br>")
else '處理文件上傳部分的數據
pos2_filename = instrb(pos1_filename+10,content,toByte(""""))
fullpath = midb(content,pos1_filename+10,pos2_filename-pos1_filename-10) '從文件說明部分中取出文件路徑
covername=GetFileName(toStr(fullpath))
If(fullpath <> "")Then '如果有上傳的文件,執行以下代碼
dim bStart ' 取二進制流文件部分開始位置
bStart = instrb(start,filedata,newline&newline)+3

dim bEnd ' 取二進制流文件部分結束位置
bEnd=inStrB(bStart+6,filedata,divider)-bStart-3

dim stm ' 定義一個 adodb.stream 源對象 stm, 用以拷貝二進制流文件部分至另一 adodb.stream fromStm
set stm=createObject("adodb.stream")
stm.type=1 ' 二進制模式
stm.mode=3 ' 指定打開模式為讀寫
stm.open
stm.write filedata '寫入二進制流內容

dim fromStm '定義 adodb.stream 對象 fromStm, 以保存文件
set fromStm=createOBject("adodb.stream")
with fromStm
.type=1
.mode=3
.open
stm.position = bStart ' 指定 stm 對象的起始位置, 以變數 bStart 的值為起始位置
stm.To fromStm, bEnd ' 拷貝 stm 二進制流至 fromStm 對象, 長度為 bEnd 變數的長度
.saveTofile server.MapPath (covername),2' 保存文件, 如果存在相同名稱, 則覆蓋
.close
end with
set fromStm = nothing

stm.close
set stm = nothing
Rs("image") =covername '將文件的相對路徑寫入資料庫中
end if
end if
k = instrb((instrb(k,filedata,divider)+lenb(divider)),filedata,divider)
Wend
Rs.update
Rs.close
set Rs = nothing
response.Redirect"mylife.asp"
end if

function toStr(Byt) '將二進制轉換為字元串
toStr=""
for i=1 to lenb(byt)
blow = midb(byt,i,1)
if ascb(blow)>127 then
toStr = toStr&chr(ascw(midb(byt,i+1,1)&blow)) '
i = i+1
else
toStr = toStr&chr(ascb(blow))
end if
Next
End function

Function toByte(Str) '將字元串轉換為二進制
dim i,iCode,c,iLow,iHigh
toByte=""
For i=1 To Len(Str)
c=mid(Str,i,1)
iCode =Asc(c)
If iCode <0 Then iCode = iCode + 65535
If iCode>255 Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
Else
toByte = toByte & chrB(AscB(c))
End If
Next
End function
Function GetFileName(imagespath)'將路徑轉換為時間,並使上傳的文件不重名
If imagespath <> "" Then
rname=right(toStr(fullpath),len(toStr(fullpath))-InStrRev(toStr(fullpath),".")+1)'獲得後綴名
GetFileName = "UpImages/" & year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&rname
Else
GetFileName =""
End If
End Function
%>

</body>
</html>

㈢ Cocos Creator怎麼使用安卓手機相冊中的圖片,最好有示例源碼

android 將drawable中的圖片保存到系統相冊中的原理比較簡單,獲取到的bitmap,然後通過的compress方法寫到一個fileoutputstream中. 再通知MediaScannerService有圖片文件加入就可以了.
保存圖片的核心代碼如下:
Bitmap bitmap= BitmapFactory.decodeResource(getResources(), R.drawable.icon);
MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, name, "");
或者
FileOutputStream fos = openFileOutput("image", Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
//發送系統通知消息
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
另一種方法是直接使用文件流讀寫:
InputStream is = mContext.getResources().openRawResource(PicID);
FileOutputStream fos = new FileOutputStream(LogoFilePath);
byte[] buffer = new byte[8192];
int count = 0;
while((count=is.read(buffer)) > 0)
{
fos.write(buffer, 0, count);
}
fos.close();
is.close();
這里要注意目錄許可權問題:在應用程序AndroidManifest.xml中的manifest節點中加入android:sharedUerId="android.uid.system"這個屬性。然後放在源碼環境中編譯,並通過adb install 的方式進行安裝。mk文件中的屬性改為LOCAL_CERTIFICATE :=platform。

閱讀全文

與私人圖片儲存系統源碼相關的資料

熱點內容
linux空值 瀏覽:137
剪力牆鋼筋用不用加密區 瀏覽:978
哪裡app可以上高中生物課 瀏覽:472
cad粗糙度快捷鍵命令大全 瀏覽:521
騰訊雲伺服器無法運行軟體 瀏覽:342
奔跑吧哪個app 瀏覽:97
哪個app聽音樂最好 瀏覽:281
考研英語2真題pdf 瀏覽:699
煙台編程積木教育環境好不好 瀏覽:214
python優秀代碼 瀏覽:620
androidtop命令 瀏覽:455
你平時怎麼排解壓力 瀏覽:68
表格中的文件夾怎樣設置 瀏覽:476
em78單片機 瀏覽:960
splitjava空格 瀏覽:248
電腦怎麼谷歌伺服器地址 瀏覽:515
nx自定義工具啟動宏命令 瀏覽:101
程序員怎麼解決無法訪問互聯網 瀏覽:303
java訪問本地文件 瀏覽:747
瓦斯琪伺服器怎麼用 瀏覽:22