Aardio Web Images: Download, Process & Save

To fetch web images and save them locally after processing with GDI in Aardio, you can follow these steps:

  1. The protocol used for transmitting data on the internet is called HTTP.
  2. Create a GDI bitmap object and load network image data into it.
  3. Process bitmap images using GDI image processing functions, such as resizing, rotating, and more.
  4. Create a file object to save the bitmap to a file.

Here is a sample code demonstrating how to implement this functionality.

local http = require("http")
local gdi = require("gdi")
local file = require("file")

-- 发送HTTP请求,获取网络图片数据
local response = http.get("http://example.com/image.jpg")
local imageData = response.body

-- 创建GDI位图对象并加载网络图片数据
local bmp = gdi.CreateBitmapFromMemory(imageData)

-- 调整位图大小为300x300
local newBmp = gdi.CreateCompatibleBitmap(bmp, 300, 300)
gdi.StretchBlt(newBmp, 0, 0, 300, 300, bmp, 0, 0, bmp:GetWidth(), bmp:GetHeight())

-- 保存位图到本地文件
local filePath = "C:\\path\\to\\save\\image.jpg"
local fileObj = file.new(filePath, "wb")
fileObj:write(newBmp:SaveToMemory("image/jpeg"))
fileObj:close()

In the above code, we start by using the http.get function to send an HTTP request to fetch data of a network image. Then, we use gdi.CreateBitmapFromMemory to create a GDI bitmap object and load the network image data into it. Next, we create a new bitmap object using gdi.CreateCompatibleBitmap function, and use gdi.StretchBlt function to resize the original bitmap to 300×300 size. Finally, we create a file object using file.new function and save the bitmap data to the file using the write method.

Please note that you need to replace the paths related to the http, gdi, and file modules in the code with the corresponding paths under your Aardio installation directory. Additionally, you also need to replace the file path for saving images with the actual path you wish to save them to.

bannerAds