عرض مشاركة واحدة
  #1  
قديم 10-07-2017, 01:14 PM
W!ndows W!ndows غير متواجد حالياً
Administrator
 
تاريخ التسجيل: Sep 2017
المشاركات: 350
افتراضي تطبيق كامل منقول - قراءة وتعديل صورة Jpeg

كود:
' ---------------------------------------------------------------------------------- ' ' clsJPEGasm.cls ' Started on: May, 23th 2004 ' By : Light Templer ' Update lvl: 0 ' Last edit : 8/4/2004 ' ---------------------------------------------------------------------------------- ' ' ' Description: ' A selfcontained class based on my class clsJPEGparser to ' * READ in a JPEG file ' * Parse the segments ' * Get a list with start and size of segments ' * Isolate the comments ' * Add/modify/remove comments ' * Remove some segments on demand (Exif, Adobe (TM) PhotoShop ' header, all application specific headers, all comments) ' * Get some informations (like the TRUE size (width /height) ' of the image even there is a Adobe PhotoShop (TM) preview ' included ..., parseable without errors and so on) ' ' * WRITE out a new JPEG file ' ---------------------------------------------------------------------------------- ' ' ' CREDITS: ' ' Hans Reich He sponsored this project to submit it on PSC! ' ' Christian Tratz Many thx to Christian Tratz for sharing his JPEG informations ' on www.codeproject.com in his Visual-C project 'Extracting ' IPTC header information from JPEG images' ! ' ' Eric Hamilton for his JPEG structure docu from 1992. ' ' ' "The Web" Some more used JPEG informations I took from several web sites. ' ' ALLAPI team API information mostly taken from www.ALLAPI.NET ' Thx for their free fine app/lib 'API-Guide' and 'API-Viewer' ! ' ---------------------------------------------------------------------------------- ' ' COPYRIGHT / CONTACT ' ' All (C) by Light Templer. ' Please send any problems/improvements to ' ' schwepps_bitterlemon@gmx.de ' ---------------------------------------------------------------------------------- ' ' EXAMPLE: ' ' Dim oJPEGasm as clsJPEGasm ' ' Set oJPEGasm = new clsJPEGasm ' ' ' Read and paser a JPEG file ' oJPEGasm.ReadInJPEGFile("PathToYourSrcJPEGFile") ' ' ' 1 - Write back the segments into a new JPEG file when successfully ' ' parsed. Normaly file size doesn't change this way and you can be sure: ' ' JPEG structure is valid for this file. ' oJPEGasm.WriteOutJPEGFile("PathToYourDstJPEGFile") ' ' ' 2 - Change some stuff in this JPEG. ' oJPEGasm.RemoveExifHeader = True ' oJPEGasm.AddComment "This is a demo comment" ' Debug.Print oJPEGasm.FullReport ' There are many more properties ... ' ' ' Debug.Print oJPEGasm.xyz ... ' (Many other, try it!) ' ' oJPEGasm.RemovePhotoShopHeader = True ' There are more switches ... ' ' oJPEGasm.WriteOutJPEGfile("PathToNewJPEGFile") ' ' Set oJPEGasm = Nothing ' ' ---------------------------------------------------------------------------------- ' Option Explicit ' ************************************* ' * CONSTANTS * ' ************************************* Private Const MIN_SIZE_JPEG_FILE = 250 ' Used for error checking. AFAIK a JPEG file ' cannot be smaller than this. (Checked using ' QuickView with a one pixel sized gray image, ' change if you want ;) !) ' Markers in a JPEG file for segments with "standard" structure: Marker, Size , Data Private Const MARKER_SOI = "FFD8" ' Start-Of-Image Private Const MARKER_EOI = "FFD9" ' End-Of-Image Private Const MARKER_APP0 = "FFE0" ' Application marker 0 (there are APP0 to APP15 - FFE0 to FFEF) Private Const MARKER_EXIF = "FFE1" ' Exif header (mostly written by digital cameras, scanners, ...) Private Const MARKER_APP2 = "FFE2" ' Used by ??? Private Const MARKER_APP3 = "FFE3" ' Used by ??? Private Const MARKER_APP4 = "FFE4" ' Used by ??? Private Const MARKER_APP5 = "FFE5" ' Used by ??? Private Const MARKER_APP6 = "FFE6" ' Used by ??? Private Const MARKER_APP7 = "FFE7" ' Used by ??? Private Const MARKER_APP8 = "FFE8" ' Used by ??? Private Const MARKER_APP9 = "FFE9" ' Used by ??? Private Const MARKER_APP10 = "FFEA" ' Used by ??? Private Const MARKER_APP11 = "FFEB" ' Used by ??? Private Const MARKER_APP12 = "FFEC" ' Used by ??? Private Const MARKER_APP14 = "FFED" ' APP14 (Adobe PhotoShop (TM) picture informations) --- btw: Don't know ' why its called APP14; imho should be APP13 ... Private Const MARKER_APPEE = "FFEE" ' APP?? (Seen in JPEGs written by Adobe PhotoShop (TM)) Private Const MARKER_APP15 = "FFEF" ' APP15 Private Const MARKER_DQT = "FFDB" ' Quantization table Private Const MARKER_DHT = "FFC4" ' Huffman table Private Const MARKER_SOF0 = "FFC0" ' Start of frame Private Const MARKER_SOS = "FFDA" ' Start of scan Private Const MARKER_DRI = "FFDD" ' Define restart interval Private Const MARKER_COM = "FFFE" ' Comments ' === Type of coding (Baseline/Progressiv, ...) markers in a JPEG file. ' = Segments with "standard" structure: Marker, Size , Data Private Const MARKER_SOF1 = "FFC1" ' Extended sequential DCT, Huffman Private Const MARKER_SOF2 = "FFC2" ' Progressive DCT, Huffman Private Const MARKER_SOF3 = "FFC3" ' Spatial (sequential) lossless, Huffman Private Const MARKER_SOF5 = "FFC5" ' Differential Sequential DCT, Huffman Private Const MARKER_SOF6 = "FFC6" ' Differential progressive DCT, Huffman Private Const MARKER_SOF7 = "FFC7" ' Differential spatial, Huffman Private Const MARKER_SOF9 = "FFC9" ' Extended sequential DCT, Arithmetic Private Const MARKER_SOF10 = "FFCA" ' Progressive DCT, Arithmetic Private Const MARKER_SOF11 = "FFCB" ' Spatial (sequential) lossless, Arithmetic Private Const MARKER_SOF13 = "FFCD" ' Differential sequential DCT, Arithmetic Private Const MARKER_SOF14 = "FFCE" ' Differential progressive DCT, Arithmetic Private Const MARKER_SOF15 = "FFCF" ' Differential spatial, Arithmetic Private Const MARKER_JPG = "FFC8" Private Const MARKER_DAC = "FFCC" ' Define Arithmetic coding conditioning Private Const MARKER_DNL = "FFDC" ' Define number of Lines Private Const MARKER_DHP = "FFDE" ' Define Hierarchical progression Private Const MARKER_EXP = "FFDF" ' Expand reference components Private Const MARKER_JPG0 = "FFF0" ' Reserved for JPEG extensions ' ... to ... Private Const MARKER_JPG13 = "FFFD" ' Reserved for JPEG extensions ' = Markers in a JPEG file for segments without any further data, just the two marker bytes Private Const MARKER_TEM = "FF01" ' "Usually causes a decoding error, may be ignored" Private Const MARKER_RTS0 = "FFD0" ' RSTn are used for resync. You can find them within Private Const MARKER_RTS1 = "FFD1" ' a SOS segment only! Private Const MARKER_RTS2 = "FFD2" Private Const MARKER_RTS3 = "FFD3" Private Const MARKER_RTS4 = "FFD4" Private Const MARKER_RTS5 = "FFD5" Private Const MARKER_RTS6 = "FFD6" Private Const MARKER_RTS7 = "FFD7" ' ************************************* ' * API DEFINITIONS * ' ************************************* Private Const FILE_ATTRIBUTE_DIRECTORY = &H10 Private Const INVALID_HANDLE_VALUE As Long = -1 Private Const MAX_PATH As Long = 260 Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type Private Type WIN32_FIND_DATA dwFileAttributes As Long ftCreationTime As FILETIME ftLastAccessTime As FILETIME ftLastWriteTime As FILETIME nFileSizeHigh As Long nFileSizeLow As Long dwReserved0 As Long dwReserved1 As Long cFileName As String * MAX_PATH cAlternate As String * 14 End Type Private Declare Function API_FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _ (ByVal lpFileName As String, _ lpFindFileData As WIN32_FIND_DATA) As Long Private Declare Function API_FindClose Lib "kernel32" Alias "FindClose" _ (ByVal hFindFile As Long) As Long Private Declare Function API_CreateFile Lib "kernel32" Alias "CreateFileA" _ (ByVal lpFileName As String, _ ByVal dwDesiredAccess As Long, _ ByVal dwShareMode As Long, _ ByVal lpSecurityAttributes As Long, _ ByVal dwCreationDisposition As Long, _ ByVal dwFlagsAndAttributes As Long, _ ByVal hTemplateFile As Long) As Long Private Declare Function API_GetFileSize Lib "kernel32" Alias "GetFileSize" _ (ByVal hFile As Long, _ lpFileSizeHigh As Long) As Long Private Declare Function API_ReadFile Lib "kernel32" Alias "ReadFile" _ (ByVal hFile As Long, _ lpBuffer As Any, _ ByVal nNumberOfBytesToRead As Long, _ lpNumberOfBytesRead As Long, _ ByVal lpOverlapped As Any) As Long Private Declare Function API_WriteFile Lib "kernel32" Alias "WriteFile" _ (ByVal hFile As Long, _ lpBuffer As Any, _ ByVal nNumberOfBytesToWrite As Long, _ lpNumberOfBytesWritten As Long, _ ByVal lpOverlapped As Any) As Long Private Declare Function API_CloseHandle Lib "kernel32" Alias "CloseHandle" _ (ByVal hObject As Long) As Long ' ************************************* ' * PRIVATES * ' ************************************* Private arrByteJPEGfile() As Byte ' Here we hold the whole file in memory to parse it. ' Size should be no problem - JPEGs are small. Private Type tpSegmentList ' List with pointers, lenght and types of the JPEGs segments. ' Filled on parsing the file. sType As String ' Segment type, e.g. FFC4 for 'Huffman table' lStart As Long ' Index into arrByteJPEGfile() lLength As Long ' Size of segment in arrByteJPEGfile() End Type Private Type tpMvar ' UDT to hold all local informations in one easy to access var HasPreview As Boolean HasEXIFHeader As Boolean HasPhotoShopComments As Boolean ParsedWithoutProblems As Boolean SrcFilename As String Filesize As Long ' Source file's size DstFilename As String JPEGVersion As String HowManyComments As Long Comments() As String ' 1-based array with (1 to HowManyComments) elements FullReport As String Resolution As String XsizePreview As Long YsizePreview As Long XsizePicture As Long YsizePicture As Long ColorDepthInBit As Long ColorDepthAsText As String ErrorMsg As String RemoveExifHeader As Boolean RemovePhotoShopHeader As Boolean RemoveAllAppHeader As Boolean HowManySegments As Long arrSegmentList() As tpSegmentList ' A 1-based array witch represents the structure ' of the JPEG file saved in arrByteJPEGfile() End Type Private mvar As tpMvar ' Holds all local informations in a handy way. ' ' '
رد مع اقتباس