如何在tiff中保存多页面 [英] How to save mutipage in tiff
本文介绍了如何在tiff中保存多页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我正在使用以下代码进行jpg n tiff压缩。
为jpg工作正常但是对于tiff它不是羚牛倍数,而不是只有1页evn如果缓冲区有2其中的页面..
请帮助plzzz
Hi i am using the below code for jpg n tiff compression.
for jpg its working fine but for tiff it is not takin multipages,instead of takes only 1 page evn if the buffer has 2 pages in it..
kindly help plzzz
{x_dpi = float.Parse(ds.Tables[0].Rows[0]["XPOS"].ToString());
y_dpi = float.Parse(ds.Tables[0].Rows[0]["YPOS"].ToString());
_bmpW = Int32.Parse(ds.Tables[0].Rows[0]["WIDTH"].ToString());
_bmpH = Int32.Parse(ds.Tables[0].Rows[0]["HEIGHT"].ToString());
IMAGE_TYPE = ds.Tables[0].Rows[0]["IMAGE_TYPE"].ToString();
int bmpW = _bmpW;
//New image target width
int bmpH = _bmpH;
Int32 newWidth = bmpW;
Int32 newHeight = bmpH;
HttpFileCollection files = HttpContext.Current.Request.Files;
HttpPostedFile uploadfile = files["RemoteFile"];
Bitmap upBmp = (Bitmap)Bitmap.FromStream(uploadfile.InputStream);
Bitmap newBmp = new Bitmap(newWidth, newHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
FileName = uploadfile.FileName;
newBmp.SetResolution(x_dpi, y_dpi);
//Get the uploaded image width and height
Double upWidth = upBmp.Width;
Double upHeight = upBmp.Height;
int newX = 0;
//Set the new top left drawing position on the image canvas
int newY = 0;
Double reDuce;
//Keep the aspect ratio of image the same if not 4:3 and work out the newX and newY positions
//to ensure the image is always in the centre of the canvas vertically and horizontally
if (upWidth > upHeight)
{
//Landscape picture
reDuce = newWidth / upWidth;
//calculate the width percentage reduction as decimal
newHeight = ((Int32)(upHeight * reDuce));
//reduce the uploaded image height by the reduce amount
newY = ((Int32)((bmpH - newHeight) / 2));
//Position the image centrally down the canvas
newX = 0;
//Picture will be full width
}
else if (upWidth < upHeight)
{
//Portrait picture
reDuce = newHeight / upHeight;
//calculate the height percentage reduction as decimal
newWidth = ((Int32)(upWidth * reDuce));
//reduce the uploaded image height by the reduce amount
newX = ((Int32)((bmpW - newWidth) / 2));
//Position the image centrally across the canvas
newY = 0;
//Picture will be full hieght
}
else if (upWidth == upHeight)
{
//square picture
reDuce = newHeight / upHeight;
//calculate the height percentage reduction as decimal
newWidth = ((Int32)(upWidth * reDuce));
//reduce the uploaded image height by the reduce amount
newX = ((Int32)((bmpW - newWidth) / 2));
//Position the image centrally across the canvas
newY = ((Int32)((bmpH - newHeight) / 2));
//Position the image centrally down the canvas
}
//Create a new image from the uploaded picture using the Graphics class
//Clear the graphic and set the background colour to white
//Use Antialias and High Quality Bicubic to maintain a good quality picture
Graphics newGraphic = Graphics.FromImage(newBmp);
try
{
//newGraphic.DrawImage(upBmp, newX, newY, newWidth, newHeight);
EncoderParameters eps = new EncoderParameters(1);
if (IMAGE_TYPE.ToUpper() == "JPG")
{ newGraphic.Clear(Color.White);
newGraphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
newGraphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
newGraphic.DrawImage(upBmp, newX, newY, newWidth, newHeight);
newBmp.Save(Path + FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
}
else if (IMAGE_TYPE.ToUpper() == "TIF" || IMAGE_TYPE.ToUpper() == "TIFF")
{ eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
//newBmp.BitsPerSample = 1;
//newBmp.SamplesPerPixel = 1;
System.Drawing.Imaging.Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
ImageCodecInfo myImageCodecInfo;
myEncoder = System.Drawing.Imaging.Encoder.Compression;
myEncoderParameters = new EncoderParameters(1);
// Save the image with a color depth of 24 bits per pixel.
//myEncoderParameter =
// new EncoderParameter(myEncoder, 24L);
myEncoderParameter = new EncoderParameter(myEncoder, (long)3);
myEncoderParameters.Param[0] = myEncoderParameter;
myImageCodecInfo = GetEncoderInfo("image/tiff");
upBmp.Save(Path + FileName, myImageCodecInfo, myEncoderParameters);
}
else if (IMAGE_TYPE.ToUpper() == "PDF")
{
eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
//newBmp.BitsPerSample = 1;
//newBmp.SamplesPerPixel = 1;
System.Drawing.Imaging.Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
ImageCodecInfo myImageCodecInfo;
myEncoder = System.Drawing.Imaging.Encoder.Compression;
myEncoderParameters = new EncoderParameters(1);
// Save the image with a color depth of 24 bits per pixel.
//myEncoderParameter =
// new EncoderParameter(myEncoder, 24L);
myEncoderParameter = new EncoderParameter(myEncoder, (long)3);
myEncoderParameters.Param[0] = myEncoderParameter;
myImageCodecInfo = GetEncoderInfo("image/tiff");
newBmp.Save(Path + FileName, myImageCodecInfo, myEncoderParameters);
}
推荐答案
我做了其他方法来解决这个问题。
as i ws使用第三方工具
i did other way out to solve this issue .
as i ws using thirtd party tool
这篇关于如何在tiff中保存多页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文