KuljeetSingh.com

Mar 17, 2013

Saving Multiple Images in One Multipage / Multiframe Tiff File (VB.NET)

The most convinient way of managing multiple images is saving image in Multipage TIFF or MultiPage PDF Files. Here I am sharing method, how we can save multiple images in single MultiPage or MultiFrame TIFF File.
Tiff is just like a Multiframe Bitmaps. We can save different images in each frame. Bitmap is created with one first Image and then added to different frames. To save it as Tiff we attach the Tiff encoder with Bitmap file

Steps:
1. Open the OpenFileDialog Box and Select the images and save the path in any container for. e.g listboxListBox1.Items.Add(OpenFileDialog1.FileName)
2. Store all the images in ArrayList object Dim panelarr As New ArrayList
For Each strpath As String In ListBox1.Items
panelarr.Add(New Bitmap(strpath))
Next


3. Create the BitMap File with first image Dim bmp As Image = panelarr.Item(0)
Dim MasterBitmap As Bitmap = CType(bmp, Bitmap)

4. Get the Encoder Information, Encoding Parameters of TIFF and save the bitmap

5. MasterBitmap.SaveAdd used to add images to different frames.

Complete Procedure
Public Sub saveMultipage(ByVal location As String)
Try
If File.Exists(location) Then File.Delete(location)
'Save all the images in ArrayList
Dim panelarr As New ArrayList
For Each strpath As String In ListBox1.Items
panelarr.Add(New Bitmap(strpath))
Next
Dim bmp As Image = panelarr.Item(0)
Dim MasterBitmap As Bitmap = CType(bmp, Bitmap)
'Select the image encoder
Dim enc As Encoder = Encoder.SaveFlag
Dim info As ImageCodecInfo = Nothing
Dim ice As ImageCodecInfo
For Each ice In ImageCodecInfo.GetImageEncoders()
If ice.MimeType = "image/tiff" Then
info = ice
End If
Next ice
Dim ep As New EncoderParameters(1)
ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.MultiFrame))
'Save the master bitmap
MasterBitmap.Save(location, info, ep)
ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.FrameDimensionPage))
'add all images from index 1 to n
Dim i As Integer
For i = 1 To (panelarr.Count) - 1
MasterBitmap.SaveAdd(CType(panelarr(i), Bitmap), ep)
Next i
ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.Flush))
'close out the file.
MasterBitmap.SaveAdd(ep)
Return True
Catch ee As System.Exception
Throw New Exception(ee.Message & " Error in saving as multipage ")
End Try
End Sub

Download Sample Code Here

 
?

Blogs | About Me | My Projects | Contact Me
【丰胸】虽然,这些药物对于乳房而言粉嫩公主,能够起到一定的丰胸效果,可朋友们这些药物的后遗症,也会在我们服完后慢慢显现出来丰胸产品,譬如:机体中的雌激素水平被打破了,就容易导致我们的月经变得不正常丰胸食物,从而使得我们的腰跟着变得圆嘟嘟,而严重的话还可能会导致我们的子宫出血,肝脏受损丰胸效果,所以说若是采用药物来进行丰胸,大家还是小心谨慎些为好。