?????????? ????? ? ???-??????? ASP.NET

????????

? ??? ?????? ???????? ??????? ???????????? ????????? Aspose ??? ??????????? ?????? ?? ??????? ????????? ??? ???-???????? ASP.NET. ??????? ???????????: ?????????? ????? ?????????? zip-????? ?? ???????????? ? ???-???????, ??? ????????? ?? ??? ?? ?????? ???. ????????? ?????????? ????????????????? ?? ??? ?? ???-???????? ? ?????????.

?????????? ???-??????? ASP.NET

?????????????? Visual Studio, ???????? ?????? ???-???????? ASP.NET Core ?? ?????????? Razor. ?????????????? ????????? ??????? NuGet, ?????????????? ??? ?????? ??? ????? ???????: Aspose.Zip ??? ??????????? ?? Aspose.Imaging ??? ??????? ?????????.
???????? ???????? Index.cshtml ? ?????? Solution Explorer. ????? ??????? ????? ?? ???? ???????? ? ????????? enctype="multipart/form-data" ? ???? <form>. ???????? ???? ???????? ???? ?? ???-??????. ????? ??????? ??? ???? ???????? - ???? ???? file ??? ????????????? ??????, ???? ???? number ??? ???????? ???? ????????. ??? ????? ???????? HTML ??? ?????:

1<form method="post" enctype="multipart/form-data">
2    <span>Images archive: </span><input type="file" name="uploadedFile" required="required" />
3    <br />
4    <span>Rotation angle: </span><input type="number" value="30" min="0" max="360" name="rotateDegree" required="required" />
5    <br />
6    <input type="submit" value="Upload" />
7</form>

????? ?????? ????? ???????? ?????????.

??????? ?????? ???????????

????, ?????????? ????? zip-????? ?? ???????????? ?? ???????? ?????. ?? ???????? ???? ????? ?? ??????? ???????? ?????????????? ?????? ASP.NET, ??? ???????? ???????? ??????????? ????? OnPost ??? ??????? Index.cshtml.cs. ? ?????? ????? ?????? ?? ???????????? zip-????? ?? ????????? ???????????? ????????????, ? ????? ????????? ????? ??????????. ??? ???????? ??????:

1public void OnPost(IFormFile uploadedFile, int rotateDegree) {
2    ?????????????? (???????? ????? = ????? ?????(uploadedFile.OpenReadStream())) {
3        foreach (????? ArchiveEntry ? archive.Entries) {
4		   // ????????? ?????????? ?? ????????? ????.
5		}
6    }
7}

???????? ??????????

?? ?????????????? ?????????? Aspose.Imaging, ??? ???????? ?????????? ??? ?????? ????? ??? ????? ???????, ???????????? ???? ??????????. ???????? ???? ???????:

 1    using (MemoryStream rotated = new MemoryStream())
 2    {
 3        using (RasterImage image = (RasterImage)Image.Load(extracted))
 4        {
 5            // Before rotation, the image should be cached for better performance
 6            if (!image.IsCached)
 7                image.CacheData();
 8                    
 9            image.Rotate(rotateDegree, true, Color.CornflowerBlue);
10            image.Save(rotated);
11        }                          
12    }

?????? ???????? ?? ????????? ??????????

??? ???????? ????????? ????? ??????????? ????????? ? ?????? ????????, ??? ?????????? ?? ??????????. ??????? ??????????? public List<byte[]> ImageBytes { get; ????????? ?????; } ?? IndexModel. ?? ?????????? ??? ?????? ???????????? ??????? ?????????. ??? ???????? ?? ?? ???-????????, ?? ?????????????? data URI. ??? ???????? ??????????? ????? ?????????? ?? ????? base64. ??? ??? ???????????? Razor ?? Index.cshtml

1@{
2if (Model.ImageBytes != null && Model.ImageBytes.Count > 0) {
3        <h4>????????? ??????????:</h4>
4        foreach (????[] ?????????? ? Model.ImageBytes) {
5            <img src="data:image;base64,@Convert.ToBase64String(image)" width="150"/>
6        }
7    }
8}

?????????? ?????????

????, ?�??????? ??? ?????. ????? ????? ?????? ???? ???????????, ????? ?? ??? ?????? ???? ???????? ?????????? ??, ???????, ?????????.
?? ?? ??????????? ???? ??????????? ? ????? ??????. ? ???????? ????????? ??? ???? ?????????? ???????????? ????? ? ???? ?????.
????? ???????? ???????? ????? OnPost.

 1    public void OnPost(IFormFile uploadedFile, int rotateDegree)
 2    {
 3        ImageBytes = new List<byte[]>();
 4
 5        using (Archive archive = new Archive(uploadedFile.OpenReadStream()))
 6        {
 7            foreach (ArchiveEntry entry in archive.Entries)
 8            {
 9                if (entry.IsDirectory)
10                    continue;
11
12                using (MemoryStream extracted = new MemoryStream())
13                {
14                    entry.Open().CopyTo(extracted);
15                    extracted.Seek(0, SeekOrigin.Begin);
16                    using (MemoryStream rotated = new MemoryStream())
17                    {
18                        using (RasterImage image = (RasterImage)Image.Load(extracted))
19                        {
20                            if (!image.IsCached)  // Before rotation, the image should be cached for better performance
21                                image.CacheData();
22
23                            image.Rotate(rotateDegree, true, Color.CornflowerBlue);
24                            image.Save(rotated);
25                        }
26                        
27                        this.ImageBytes.Add(rotated.ToArray());
28                    }
29                }
30            }
31        }
32    }

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.