从 AWT 和 JAI 转换为 Android

发布于 2024-11-18 14:42:16 字数 1208 浏览 2 评论 0原文

我在将 java 项目转换为 android 项目时遇到问题。是什么让 我混淆相当于 SampleModel、ColorModel、WritableRaster, 和 Android 的 TiledImage ?以下是截取的代码:

SampleModel sampleModel = RasterFactory.createBandedSampleModel(
               DataBuffer.TYPE_BYTE, 4 * numXTiles, 4* numYTiles, 1);
   ColorModel colorModel = PlanarImage.createColorModel(sampleModel);
   WritableRaster decWRaster = RasterFactory.createWritableRaster(
               sampleModel, null);
   for (int j = 0; j < numYTiles; j++) {
            for (int i = 0; i < numXTiles; i++) {
               int indexEnc = disEnc.readByte();
               if (indexEnc < 0) indexEnc = indexEnc + 128;
               System.out.print(indexEnc + " ");

               int[] codeWord = codeBook[indexEnc];
               decWRaster.setPixels(i * 4, j * 4, 4, 4, codeWord);
            }
         }
         TiledImage decTImage = new TiledImage(0, 0, 4 * numXTiles,
               4 * numYTiles, 0, 0, sampleModel, colorModel);
         decTImage.setData(decWRaster);
         JAI.create("FileStore", decTImage, decPath + "test4.bmp",
"BMP");

该代码用于创建一个以 int[] 作为输入的图像,并平铺 每个像素为 4x4 框,宽度为 numXTiles*4,高度为 numYTiles*4。

有人可以帮忙吗?非常感谢:)

I have a problem about converting java project to android. What makes
me confuse is the equivalent to SampleModel, ColorModel, WritableRaster,
and TiledImage for android? Here is the snipped code:

SampleModel sampleModel = RasterFactory.createBandedSampleModel(
               DataBuffer.TYPE_BYTE, 4 * numXTiles, 4* numYTiles, 1);
   ColorModel colorModel = PlanarImage.createColorModel(sampleModel);
   WritableRaster decWRaster = RasterFactory.createWritableRaster(
               sampleModel, null);
   for (int j = 0; j < numYTiles; j++) {
            for (int i = 0; i < numXTiles; i++) {
               int indexEnc = disEnc.readByte();
               if (indexEnc < 0) indexEnc = indexEnc + 128;
               System.out.print(indexEnc + " ");

               int[] codeWord = codeBook[indexEnc];
               decWRaster.setPixels(i * 4, j * 4, 4, 4, codeWord);
            }
         }
         TiledImage decTImage = new TiledImage(0, 0, 4 * numXTiles,
               4 * numYTiles, 0, 0, sampleModel, colorModel);
         decTImage.setData(decWRaster);
         JAI.create("FileStore", decTImage, decPath + "test4.bmp",
"BMP");

This code is for creating an image with int[] as the input, and tiling
each pixel to 4x4 box which width is numXTiles*4 and height is
numYTiles*4.

Can anyone help? many thx :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文