如何显示上述<多分页图像; IMG />标签? [英] How to show multi paged image in <img/> tag?
问题描述
我创建了一个形象的ByteArray从的ReportViewer像下面
字节= reportViewer.ServerReport.Render(图像,空,出mime类型,出编码,扩展出去,出去streamids,出警告);
和我使用低于创建的映像中有12页的代码保存在一个物理路径。
System.IO.File.WriteAllBytes(@C:\test.jpeg,字节);
我想表明在<这一形象; IMG> $ C 。$ C>与另一个之后的所有网页标签
我曾尝试< IMG SRC =C://test.jpeg />
这说明了只有第一页在它
任何人都可以帮助我在此
< DIV CLASS =h2_lin>解决方案
在下方找到我用来解决这个问题的答案。
查找步骤
第一挡获得的图像作为图像
名单流的所有帧
公开名单<图像> GetAllFrames(流Sm)
{
名单<图像>照片=新的List<图像>();
位图位图=新位图(SM);
诠释计数= bitmap.GetFrameCount(FrameDimension.Page);
为(INT IDX = 0; IDX<计数; IDX ++)
{
bitmap.SelectActiveFrame(FrameDimension.Page,IDX);
MemoryStream的字节流=新的MemoryStream();
bitmap.Save(字节流,ImageFormat.Tiff);
images.Add(Image.FromStream(字节流));
}
返回图像;
}
二 - 将所有帧到一个位图
公共位图CombineAllFrames(列表<图像>测试)
{
INT宽度= 0;
INT高度= 0;
位图finalImage = NULL;
试
{
的foreach(在测试位图位图)
{
高度+ = bitMap.Height;
宽度= bitMap.Width>宽度是多少? bitMap.Width:宽度;
}
finalImage =新位图(宽,高);使用
(System.Drawing.Graphics GC = Graphics.FromImage(finalImage))
{
gc.Clear(Color.White);
INT偏移= 0;
的foreach(在测试位图位图)
{
gc.DrawImage(位图,新的矩形(0,偏移,bitmap.Width,bitmap.Height));
偏差+ = bitmap.Width;
}
}
}
赶上(例外)
{
扔;
}
返回finalImage;
}
这方法创建一个位图,将所有的帧追加到单一垂直。
。如果你想让它做水平更新为
宽+ = bitmap.Width;
高度= bitmap.Height>高度? bitmap.Height:高度;
g.DrawImage(图像,
新System.Drawing.Rectangle(偏移,0,image.Width,image.Height));
第三步 - 现在,如果你想要创建的图像
调用下面的一个字节数组方法。
公共字节[] GetBytesFromImage(位图finalImage)
{
ImageConverter转换器=新ImageConverter( );
回报率(字节[])convertor.ConvertTo(finalImage的typeof(字节[]));
}
我认为这将帮助一些人真正需要的。请发表如果有人找到一种简单的方法来做到这一点。
I have created a image bytearray from ReportViewer like below
bytes= reportViewer.ServerReport.Render("Image", null, out mimeType, out encoding, out extension, out streamids, out warnings);
And i saved in a physical path using below code which created a image has 12 pages in it.
System.IO.File.WriteAllBytes(@"C:\test.jpeg", bytes);
I wanted to show this image in <img>
tag with all the pages one after other.
I have tried <img src="c://test.jpeg" />
which shows up only first page in it.
Can anyone help me on this ?
Find the answer below which i used to resolve this. Find the steps
First- Get all the frames from the stream of image as list of Images
public List<Image> GetAllFrames(Stream sm)
{
List<Image> images = new List<Image>();
Bitmap bitmap = new Bitmap(sm);
int count = bitmap.GetFrameCount(FrameDimension.Page);
for (int idx = 0; idx < count; idx++)
{
bitmap.SelectActiveFrame(FrameDimension.Page, idx);
MemoryStream byteStream = new MemoryStream();
bitmap.Save(byteStream, ImageFormat.Tiff);
images.Add(Image.FromStream(byteStream));
}
return images;
}
Second - Combine all frames in to a single bitmap.
public Bitmap CombineAllFrames(List<Image> test)
{
int width = 0;
int height = 0;
Bitmap finalImage = null;
try
{
foreach (Bitmap bitMap in test)
{
height += bitMap.Height;
width = bitMap.Width > width ? bitMap.Width : width;
}
finalImage = new Bitmap(width, height);
using (System.Drawing.Graphics gc = Graphics.FromImage(finalImage))
{
gc.Clear(Color.White);
int offset = 0;
foreach (Bitmap bitmap in test)
{
gc.DrawImage(bitmap, new Rectangle(0, offset, bitmap.Width, bitmap.Height));
offset += bitmap.Width;
}
}
}
catch (Exception)
{
throw;
}
return finalImage;
}
this methods creates a bitmap which will append all the frames into single one vertically. If you want it horizontally make update it to
width += bitmap.Width;
height = bitmap.Height > height ? bitmap.Height : height;
g.DrawImage(image,
new System.Drawing.Rectangle(offset, 0, image.Width, image.Height));
Third step - Now if you want a byte array for the created image call the below method.
public byte[] GetBytesFromImage(Bitmap finalImage)
{
ImageConverter convertor = new ImageConverter();
return (byte[])convertor.ConvertTo(finalImage, typeof(byte[]));
}
I think this will helps some one really needed. Please post if someone find a easy way to do it.
这篇关于如何显示上述<多分页图像; IMG />标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!