Jump to content
Sign in to follow this  

Extract individual Tiff from Multipage Tiff files

Recommended Posts

I regularly receive a multipage Tiff file, and I need to store the individual uncompressed Tiff images in a database. I currently perform this with a combination of Autoit and VFP, but I'd like to eliminate VFP from the process.

I found >this thread, which shows how to access the individual frames within the Tiff file. However, I'm unsure how to best use this so that I end up with a string containing the uncompressed Tiff image that can then be written to the database. I would like to accomplish this without writing the image to a temp file on disk.

Can anyone assist me with this or get me pointed in the right direction?

Thanks, Dan

Share this post

Link to post
Share on other sites

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."


Signature last update: 2018-10-31

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • By UEZ
      Here a little script to load a TGA image file and create a GDI+ bitmap. Currently supported TGA formats are  8-Bit, 16-Bit, 24-Bit and 32-Bit but yet no support for RLA compressed images.
      As it is written completely in AutoIt, it might take some time to convert larger images. ☕
      ;Coded by UEZ #AutoIt3Wrapper_UseX64=n #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPIFiles.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GDIPlus_TGAImageLoadFromFile ; Description ...: Loads an uncompressed TGA image file (1/8/16/24/32-bit) and converts it to a GDI+ bitmap format. ; Syntax ........: _GDIPlus_TGAImageLoadFromFile($sFile[, $bPrintInfo = False.]) ; Parameters ....: $sFile - TGA file name to load from disk. ; $bPrintInfo - [optional] Prints some information about the TGA image to console. Default is False. ; Return values .: Success: GDI+ bitmap handle ; Failure: error 1 - file cannot be opened ; error 2 - TGA image is not in one of these formats: 1/8/16/24/32-bit ; error 3 - unsupported TGA image type ; error 4 - 8-bit TGA image must be unequal 1 ; error 5 - return bitmap cannot be created ; Version .......: v0.60 build 2019-09-21 beta ; Author ........: UEZ ; Modified ......: ; Remarks .......: No RLE compressed TGA image support yet! ; Related .......: _GDIPlus_BitmapCreateFromScan0, _GDIPlus_ImageRotateFlip, DllStructCreate, _WinAPI_CreateFile, _WinAPI_SetFilePointer ; Link ..........: https://www.loc.gov/preservation/digital/formats/fdd/fdd000180.shtml ; Example .......: Yes ; =============================================================================================================================== Func _GDIPlus_TGAImageLoadFromFile($sFile, $bPrintInfo = False) Local Const $tagTGAHeader = "align 1;byte idLength;byte colormapType;byte imageType;word firstEntryIndex;word colormapLength;byte colormapEntrySize;word xOrigin;word yOrigin;word width;word height;byte pixelDepth;byte imageDescriptor" Local Const $tTGAHeader = DllStructCreate($tagTGAHeader) Local Const $hFile = _WinAPI_CreateFile($sFile, 2, 2) If Not $hFile Then Return SetError(1, 0, 0) Local $dwBytesRead _WinAPI_ReadFile($hFile, $tTGAHeader, DllStructGetSize($tTGAHeader), $dwBytesRead) If $tTGAHeader.idLength > 0 Then _WinAPI_SetFilePointer($hFile, $tTGAHeader.idLength, $FILE_CURRENT) If Not BitOR($tTGAHeader.pixelDepth = 32, $tTGAHeader.pixelDepth = 24, $tTGAHeader.pixelDepth = 16, $tTGAHeader.pixelDepth = 8, $tTGAHeader.pixelDepth = 1) Then _WinAPI_CloseHandle($hFile) Return SetError(2, 0, 0) EndIf If Not BitOR($tTGAHeader.imageType = 0x01, $tTGAHeader.imageType = 0x02, $tTGAHeader.imageType = 0x03) Then _WinAPI_CloseHandle($hFile) Return SetError(3, 0, 0) EndIf Local Const $iW = $tTGAHeader.width, $iH = $tTGAHeader.height, $bytesPerPixel = $tTGAHeader.pixelDepth / 8, $pitch = $tTGAHeader.colormapLength * $tTGAHeader.colormapEntrySize / 8 Local Const $dwBufferSize = $iW * $iH * $bytesPerPixel Local $tBuffer = DllStructCreate("byte color[" & $dwBufferSize + $pitch & "]") _WinAPI_ReadFile($hFile, $tBuffer, $dwBufferSize + $pitch, $dwBytesRead) _WinAPI_CloseHandle($hFile) If $bytesPerPixel = 1 And $tTGAHeader.colormapType <> 1 Then Return SetError(4, 0, 0) If $bPrintInfo Then ConsoleWrite("idLength: " & $tTGAHeader.idLength & @CRLF) ConsoleWrite("colormapType: " & $tTGAHeader.colormapType & @CRLF) ConsoleWrite("imageType: " & $tTGAHeader.imageType & @CRLF) ConsoleWrite("firstEntryIndex: " & $tTGAHeader.firstEntryIndex & @CRLF) ConsoleWrite("colormapLength: " & $tTGAHeader.colormapLength & @CRLF) ConsoleWrite("colormapEntrySize: " & $tTGAHeader.colormapEntrySize & @CRLF) ConsoleWrite("xOrigin: " & $tTGAHeader.xOrigin & @CRLF) ConsoleWrite("yOrigin: " & $tTGAHeader.yOrigin & @CRLF) ConsoleWrite("width: " & $tTGAHeader.width & @CRLF) ConsoleWrite("height: " & $tTGAHeader.height & @CRLF) ConsoleWrite("pixelDepth: " & $tTGAHeader.pixelDepth & @CRLF) ConsoleWrite("imageDescriptor: " & $tTGAHeader.imageDescriptor & @CRLF) EndIf Local Static $tPixel ;must be static otherwise bitmap data might get corrupted. Local $stride, $iPixelFormat Switch $tTGAHeader.pixelDepth Case 1 ;1-bit $iPixelFormat = $GDIP_PXF01INDEXED $stride = BitAND(($iW * 1) + 1, BitNOT(1)) $tPixel = DllStructCreate("byte color[" & $iW * $iH * 1 & "];") Case 8, 24 $iPixelFormat = $GDIP_PXF24RGB $stride = BitAND(($iW * 3) + 3, BitNOT(3)) $tPixel = DllStructCreate("byte color[" & $iW * $iH * 3 & "];") Case 16 $iPixelFormat = $GDIP_PXF16RGB555 $stride = BitAND(($iW * 2) + 2, BitNOT(2)) $tPixel = DllStructCreate("byte color[" & $iW * $iH * 2 & "];") Case 32 $iPixelFormat = $GDIP_PXF32ARGB $stride = $iW * 4 $tPixel = DllStructCreate("byte color[" & $iW * $iH * 4 & "];") EndSwitch Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH, $iPixelFormat, $stride, $tPixel) If @error Or Not $hBitmap Then Return SetError(5, 0, 0) Local $x, $x1, $y, $iOffset, $iOffset2, $r, $g, $b, $a, $t1, $t2 Switch $tTGAHeader.pixelDepth Case 1 ;1-bit $t1 = $iW / 8 For $y = 0 To ($iH - 1) $iOffset = $y * $iW $iOffset2 = $y * $t1 For $x = 0 To ($iW - 1) $tPixel.color($iOffset + $x + 1) = $tBuffer.color($iOffset2 + $x + 1) Next Next Case 8 ;8-bit If $tTGAHeader.colormapType = 1 Then Local $tMapColorTbl = DllStructCreate("byte bgr[" & $pitch & "]", DllStructGetPtr($tBuffer, "color") + $tTGAHeader.firstEntryIndex) For $y = 0 To ($iH - 1) $iOffset = $y * $iW $iOffset2 = $iOffset * 3 For $x = 0 To ($iW - 1) $t1 = $iOffset2 + $x * 3 $t2 = $tBuffer.color($iOffset + $x + $pitch + 1) * 3 $tPixel.color($t1 + 1) = $tMapColorTbl.bgr($t2 + 1) $tPixel.color($t1 + 2) = $tMapColorTbl.bgr($t2 + 2) $tPixel.color($t1 + 3) = $tMapColorTbl.bgr($t2 + 3) Next Next EndIf Case 16, 24, 32 ;16/24/32-bit, as the bitmap format is the same we can use memcpy to copy the pixel data directly to the memory Local $hDLL = DllOpen("msvcrt.dll") For $y = 0 To $iH - 1 $t1 = $y * $stride DllCall($hDLL, "ptr:cdecl", "memcpy", "ptr", DllStructGetPtr($tPixel) + $t1, "ptr", DllStructGetPtr($tBuffer) + $t1, "uint", $stride) Next DllClose($hDLL) EndSwitch ;TGA image is stored bottom up in file. Need to flip it. If BitAND($tTGAHeader.imageDescriptor, 0x30) <> 0x20 Then _GDIPlus_ImageRotateFlip($hBitmap, $GDIP_Rotate180FlipX) $tBuffer = 0 Return $hBitmap EndFunc ;==>_GDIPlus_TGAImageLoadFromFile Global $sFile = FileOpenDialog("Select a TGA file", "", "TGA image(*.tga)") If @error Then Exit _GDIPlus_Startup() Global $hImage = _GDIPlus_TGAImageLoadFromFile($sFile) If @error Then ConsoleWrite(@error & @CRLF) _GDIPlus_Shutdown() Exit EndIf _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Converted.png") Global $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) Global $hGui = GUICreate("TGA Image Loader by UEZ", $iW, $iH) GUISetState() Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iW, $iH) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GDIPlus_BitmapDispose($hImage) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() Exit Case $GUI_EVENT_RESTORE _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iW, $iH) EndSwitch WEnd  
      If you find a TGA image which is in scope of this script but doesn't convert it properly, please report it here.
    • By misioooo
      I am writing some GUI and i need to use images as buttons, but with text on them (text is from INI file).
      Part with button looks like this:
      $ankieta1 = GUICtrlCreateButton($txtAnk1, 100,350,765,164) GUICtrlSetFont(-1, 22, 800, -1, "Arial") ;GUICtrlSetColor(-1,0xffffff) $hImageBtn_1 = _GUIImageList_Create(765, 164) _GUIImageList_AddBitmap($hImageBtn_1, "c:\path\to\ankieta_clean.bmp") _GUICtrlButton_SetImageList($ankieta1, $hImageBtn_1, 4) GUICtrlSetOnEvent(-1, "On_Ankieta1") The problem - if i uncomment GUICtrlSetColor, color of text changes, but button is just plain gray (no image). How i can change text color not touching image on a button here?
    • By Xandy
      Special thanks: AdmiralAlkex, Melba23, MrCrearoR, Dragon Warrior 3, SDL
      MapIt is a tile world editor.  MapIt was built around the concept of reversing Dragon Warrior map images.  MapIt can take image input and produce a tile and world array.  
      Changing and replacing tile / world data is easy.  B/c tile world editor.

      CTRL+R in image above to signal replace tile action and I use "G" to Get the tile under mouse.
      A full list of hotkeys can be assigned in the: Help Menu\Hotkeys
      MapParser is a C++ project that scans images for unique tiles. 
      MapIt can be downloaded without MapParser. MapParser can be toggled off in the Scan_Image dialog. Without MapParser, MapIt will use the Scan_Tiles() function written in AutoIt ; which is 100 * slower Idk. If MapParser.exe will not run for you:      Installing Visual C++ Redistributable for Visual Studio 2015 should fix it: https://www.microsoft.com/en-us/download/details.aspx?id=48145   
      You can start with example world and tiles.
      Example world was made following these steps:
      Started with a tile map image of DragonWarrior3 town of: Reeve From MapIt World Menu \ New \ Scan_Image dialog, I set the area to exclude the key legend to the far right of image. After scanning the map image to world and tile array.  I removed a few of the map artifacts.  More work could be done on this world; removing unwanted tiles, but it is fine for now. I saved my world to disk.  This creates folder: Worldname: Containing folder of Tiles and a Worldname.txt. Using The Gimp, I edited some tiles to have a transparent color: Stairs, Trees, Desk Tables, Chest-of-drawers, Chairs, Signs, Doors, Beds. I changed the world layers to 2: World Menu \ Properties. F9 Finds all selected tile on current layer and changes to a new selected tile on new layer. I used F9 to change all Trees on layer: 0 to Trees on layer: 1. Then I used F9 to change all Trees on layer: 0 to Grass on layer: 0  
      In this video you can see how I used the Tile Menu \ Replace From Disk option to remap tile images to my custom tiles.  Conveniently my tiles already have a transparent pixel.
      See video for how that was done:
      To use the example world:
      First unzip the world save file: http://songersoft.com/programming/mapit/worlds/Reeve_Swapped.zip From the World Menu: choose \Load Navigate to the Reeve_Swapped.txt located in the extracted zip. Or you can scan any image.
      The map images I used are here: http://www.realmofdarkness.net/dq/games/nes/dw3/maps/world
      For download, videos, and example of created world file data; please visit the MapIt webpage: http://songersoft.com/programming/mapit/mapit_about.phtml
    • By dejhost
      Happy New Year everyone!
      I would like to extract the color values of certain pixels in an image.  This is how I picture the workflow: 
      User opens an image of his choice. Image is shown on the screen. User draws a line into the image. This happens by marking the startpixel and the endpixel of the line The line is drawn, so the user can check visually if he is happy with the line.  The following pixel based properties belonging to the line are stored in Excel: X-Coordinate Y-Coordinate Color Value Additional operations: Extracting for max- and min. color values; Statistical operations.   Browsing through the helpfile of AutoIt I find plenty of functions for treating images (e.g. GDIPlus), but I am completely unsure if Autoit will get me there. Should I read the entire image into an array? Should I rather attempt to script an external image software (e.g. IrfanView, Gimp)?
      I would be very thankful if someone could give some recommendations and maybe list a couple of the most important commands to use.
      Thank you very much.
    • By Miliardsto
      hello Im wondering if it is possible to process image in autoit like this
      1. firstly there is colorfull wallpaper
      2. Fill all colors (exception rose color) - with white
      3. Fill rose color with black color
      I see Gdi functions have things to manipulate images
  • Create New...