この小さなチュートリアルでは、**C# を使用して PowerPoint で画像にハイパーリンクを追加する方法についての情報と、ハイパーリンクを作成するための構成、段階的なプロセス、および実行可能なサンプル コードに関するすべての必要な情報を提供します。 C# を使用して PPTX の画像を作成します。サンプル コードは完全なシナリオを示しており、Windows、macOS、Linux などの任意のオペレーティング システムで使用できます。
C# で PPT の画像にハイパーリンクを追加する手順
- 環境を構成して Aspose.Slides for .NET をアプリケーションに追加します
- 新しい空の Presentation オブジェクトを作成します
- プレゼンテーション スライド コレクションの最初の slide にアクセスします
- ソース PNG イメージをディスクからバイト配列として読み取ります
- プレゼンテーションの Images コレクションに画像を追加し、IPPImage クラス オブジェクトを使用してその画像にアクセスします。
- 上記の追加された画像を使用して、選択したスライドの図形コレクションに画像フレームを挿入します
- Hyperlink クラスを使用して額縁形状の外部ハイパーリンクを追加し、ハイパーリンク プロパティを設定します。
- PNG 画像へのハイパーリンクを含む PPTX としてプレゼンテーションを保存します。
前述の手順は、C# を使用して PPTX で画像へのハイパーリンクを挿入するためのガイドです。プロセスは、Presentation クラスを使用して空のプレゼンテーションを作成し、プレゼンテーションのスライド コレクション内の最初のデフォルト スライドにアクセスすることから始まります。続いて、PNG 画像が選択したスライド内のピクチャ フレームとして追加され、Hyperlink クラス オブジェクトを使用して、追加された画像に外部 Web サイトのハイパーリンクが設定されます。
C# を使用して PPTX の画像にハイパーリンクを挿入するコード
using System; | |
using System.IO; | |
using Aspose.Slides; | |
using Aspose.Slides.Export; | |
namespace TestSlides | |
{ | |
public class InsertHyperlink | |
{ | |
public static void AddImageHyperlink() // Function to add hyperlink to an image in PPTX in C# | |
{ | |
// Load the product license | |
Aspose.Slides.License lic = new Aspose.Slides.License(); | |
lic.SetLicense("Aspose.Total.lic"); | |
// Using Presentation class object create an empty presentation | |
using (Presentation presentationWithHyperlink = new Presentation()) | |
{ | |
// Access the first slide inside the slides collection | |
ISlide slideForPng = presentationWithHyperlink.Slides[0]; | |
// Add the Image from the disk in the images collection of the presentation | |
IPPImage imageFromDisk = presentationWithHyperlink.Images.AddImage(File.ReadAllBytes("aspose_logo.png")); | |
// Insert a picture frame in the shapes collection of the slide | |
IPictureFrame pictureFrame = slideForPng.Shapes.AddPictureFrame(ShapeType.Rectangle, 20, 20, 90, 90, imageFromDisk); | |
// Insert the hyperlink for the added picture frame | |
pictureFrame.HyperlinkClick = new Hyperlink("https://www.aspose.com/"); | |
// Add a tooltip for the hyperlink | |
pictureFrame.HyperlinkClick.Tooltip = "More than 75% of Fortune 100 companies show trust in Aspose APIs"; | |
// Save the presentation with hyperlinked image on the disk | |
presentationWithHyperlink.Save("preswithHyperlink.pptx", SaveFormat.Pptx); | |
} | |
System.Console.WriteLine("Done"); | |
} | |
} | |
} |
この機能を使用して C# で PPTX の画像へのハイパーリンクを挿入する 際に、Slide オブジェクトを使用してターゲット スライドへの参照を保持し、IPPImage オブジェクトを使用して画像コレクション内に追加された新しい画像への参照を保持しました。 Hyperlink クラス オブジェクトは、外部リンクやツールヒント テキストなどのプロパティを設定することにより、追加された画像形状のハイパーリンクを設定するために使用されます。プレゼンテーション内の内部スライドへのハイパーリンクを設定することもできます。
このチュートリアルでは、C# を使用して PPT で画像にハイパーリンクを追加する方法を学びました。 PDF を PowerPoint プレゼンテーションに変換する場合は、C# を使用して PDF をプレゼンテーションに変換する方法 の記事を参照してください。