Merge multiple images into a tif file (non-gdal)

Source: Internet
Author: User

I don't know why, there is little information on TIF operations on the Internet, including how many codeprojects are not found, and gdal is mostly used on the Internet. But this is a thing for the function that only wants to merge images, it is really cool, (9 dll should be full, quite scary) and there are quite a few descriptions of the completion of generation and reading TIF, which is generally used to deal with GIS.

 

Original download: http://download.csdn.net/detail/patizi/200992 but that write messy, I encapsulated into a class !!!

Using system; using system. collections. generic; using system. drawing; using system. drawing. imaging; using system. io; using system. runtime. interopservices; // using system. text; namespace savemultipagetiffarticle {public class creattiff {public bool create1_file (image [] IMG, string dstfile) {return get1_file (IMG, dstfile);} public bool add1_file (string srcfile, string dstfile) {image I1 = image. FR Omfile (srcfile); image LoadImage = new Bitmap (I1); // filestream Fr = file. open (dstfile, filemode. open, fileaccess. readwrite); image origionalfile = image. fromfile (dstfile); int pagenumber = getpagenumber (origionalfile); image [] IMG = new image [pagenumber + 1]; for (INT I = 0; I <pagenumber; I ++) {origionalfile. selectactiveframe (framedimension. page, I); IMG [I] = new Bitmap (origionalfile);} IMG [pagen Umber] = LoadImage; origionalfile. dispose (); i1.dispose (); Return getaskfile (IMG, dstfile);} private bool getaskfile (image [] IMG, string dstfile) {try {If (IMG = NULL) return false; If (IMG. length <2) return false; // if there is only one file, it can be saved as tiff directly. There is no need to process imagecodecinfo codecinfo = imagecodecinfo here. getimageencoders () [3]; If (codecinfo. formatdescription! = "Tiff") return false; For (INT I = 0; I  threshold) {destinationvalue + = (byte) pixelvalue;} If (pixelvalue = 1) {destinationbuffer [destinationindex] = destinationvalue; destinationindex ++; destinationvalue = 0; pixelv Alue = 128;} else {pixelvalue >>=1;} sourceindex + = 4;} If (pixelvalue! = 128) {destinationbuffer [destinationindex] = destinationvalue ;}// copy binary image data to destination bitmap marshal. copy (destinationbuffer, 0, destinationdata. scan0, imagesize); // unlock destination bitmap destination. unlockbits (destinationdata); // return destination;} private int getpagenumber (image IMG) {guid objguid = IMG. framedimensionslist [0]; framedimension objdimension = new framedimension (objguid); // gets the total number of frames in. TIFF File int pagenumber = IMG. getframecount (objdimension); Return pagenumber ;}}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.