1、用 Loader 载入图像
2、将载入的图像转为 BitmapData
3、按照X,Y轴 进行遍历
4、画一个菱形 shape 并转为 BitmapData
5、用PNGEncoder 或者JPGEncoder 载入 BitmapData 图像特定区域(固定大小)的 ByteArray
6、载入FileStream保存该位置的图像
但是问题在于 要得到图像特定区域的 ByteArray 只能使用 getPixels 取得 Rectangle 矩形块,如何才能将图像按照特定区块(非矩形)方式遍历保存呢?
问题解决补充:首先,建一个 矩形区块 BitmapData(w,h),然后用copyPixels,在原图中截取一个Rectangle(x,y,w,h),复制到BitmapData的point(0,0)位置,这样就得到一个要填充菱形区块的矩形了,然后以填充的方式填充到自己画好的菱形中去,输出BitmapData,获取BitmapData的byteArray,然后将其输出到PNGEncoder 或 JPGEncoder 转存为图像,这就已经可以得到不同位置的高质量菱形位图了。
2、将载入的图像转为 BitmapData
3、按照X,Y轴 进行遍历
4、画一个菱形 shape 并转为 BitmapData
5、用PNGEncoder 或者JPGEncoder 载入 BitmapData 图像特定区域(固定大小)的 ByteArray
6、载入FileStream保存该位置的图像
但是问题在于 要得到图像特定区域的 ByteArray 只能使用 getPixels 取得 Rectangle 矩形块,如何才能将图像按照特定区块(非矩形)方式遍历保存呢?
问题解决补充:首先,建一个 矩形区块 BitmapData(w,h),然后用copyPixels,在原图中截取一个Rectangle(x,y,w,h),复制到BitmapData的point(0,0)位置,这样就得到一个要填充菱形区块的矩形了,然后以填充的方式填充到自己画好的菱形中去,输出BitmapData,获取BitmapData的byteArray,然后将其输出到PNGEncoder 或 JPGEncoder 转存为图像,这就已经可以得到不同位置的高质量菱形位图了。
本文介绍了一种从原始图像中截取非矩形区块(例如菱形)的方法,并将其转换为高质量位图的过程。具体步骤包括创建矩形BitmapData、使用copyPixels复制指定矩形区域、填充自定义形状、输出BitmapData并使用PNGEncoder或JPGEncoder保存。
6807

被折叠的 条评论
为什么被折叠?



