Hi, Readers.
Today I would like to talk about an interesting topic, how to rotate and flip picture/image in Business Central.
As you know, most of the picture software supports rotating pictures including Windows. For example,
Generally, we will upload the processed pictures to Business Central. So do you know that we can also rotate images directly in Business Central? Let’s see how this is done. This time we’re going to use CodeUnit Image (ID 3971).
CodeUnit Image (ID 3971): Provides functionality for working with images.
It contains many interesting methods.
The main method is procedure RotateFlip, but we need to create the image, rotate it, and then save the image, so we also need to use procedure FromStream and procedure Save.
procedure RotateFlip(RotateFlipType: Enum “Rotate Flip Type”): Rotates, flips, or rotates and flips the image.
One important parameter is Rotate Flip Type.
enum 3972 “Rotate Flip Type”: Specifies how much an image is rotated and the axis used to flip the image.
Value | Summary |
RotateNoneFlipNone | Specifies no clockwise rotation and no flipping. |
Rotate90FlipNone | Specifies a 90-degree clockwise rotation without flipping. |
Rotate180FlipNone | Specifies a 180-degree clockwise rotation without flipping. |
Rotate270FlipNone | Specifies a 270-degree clockwise rotation without flipping. |
RotateNoneFlipX | Specifies no clockwise rotation followed by a horizontal flip. |
Rotate90FlipX | Specifies a 90-degree clockwise rotation followed by a horizontal flip. |
Rotate180FlipX | Specifies a 180-degree clockwise rotation followed by a horizontal flip. |
Rotate270FlipX | Specifies a 270-degree clockwise rotation followed by a horizontal flip. |
Let me do a simple test with Rotate90FlipX and Rotate90FlipNone.
Rotate the item picture:
Test video:
Very interesting, give it a try!!!😁
Source Code: GitHub (Please note that the source code is for reference only, you can improve it according to your own needs)
pageextension 50112 ZYItemCard extends "Item Card"
{
actions
{
addafter("&Bin Contents")
{
action(Rotate90FlipX)
{
Caption = 'Rotate 90 Flip X';
ApplicationArea = All;
Promoted = true;
PromotedCategory = Process;
Image = Change;
trigger OnAction()
begin
RotateFlipPicture(Enum::"Rotate Flip Type"::Rotate90FlipX);
end;
}
action(Rotate90FlipNone)
{
Caption = 'Rotate 90 Flip None';
ApplicationArea = All;
Promoted = true;
PromotedCategory = Process;
Image = Change;
trigger OnAction()
begin
RotateFlipPicture(Enum::"Rotate Flip Type"::Rotate90FlipNone);
end;
}
}
}
local procedure RotateFlipPicture(RotateFlipType: Enum "Rotate Flip Type")
var
Image: Codeunit Image;
InS: InStream;
OutS: OutStream;
TempBlob: Codeunit "Temp Blob";
ItemTenantMedia: Record "Tenant Media";
FileName: Text;
begin
if Rec.Picture.Count > 0 then begin
ItemTenantMedia.Get(Rec.Picture.Item(1));
ItemTenantMedia.CalcFields(Content);
ItemTenantMedia.Content.CreateInStream(InS, TextEncoding::UTF8);
Image.FromStream(InS);
Image.RotateFlip(RotateFlipType);
TempBlob.CreateOutStream(OutS);
Image.Save(OutS);
TempBlob.CreateInStream(InS);
Clear(Rec.Picture);
FileName := Rec.Description + '.png';
Rec.Picture.ImportStream(InS, FileName);
Rec.Modify(true);
end;
end;
}
END
Hope this will help.
Thanks for reading.
ZHU
コメント