基于MIDP2.0实现图片的缩放功能

ensp VRRP+MSTP综合性实验 网络结构拓扑图 实验要求 要求: 1、全网互通,IP地址任意规划,路径最优,无环路。 2、AR1上面有一个loopback口,ip地址为1.1.1.1/24, 要求所有电脑能访问。 3、vlan10通过LSW1访问1.1.1.1,当LSW1出现问题即使 g0/0/1故障亦能通过lsw2访问。 vlan30通过LSW2访问1.1.1.1,当LSW2出现问题即使 g0/0/1故障亦能通过lsw1访问。 4、LSW1为vlan10的主根,vlan30的备根。 LSW2为vlan30的主根,vlan1 阅读详情
 以前在SUN的论坛看到过关于图片缩放的处理,是基于MIDP2.0实现的。今天看到有网友在问这个问题,因此去翻了一下以前的帖子找到了源代码,自己写了一个测试程序验证了一下效果还算可以。希望可以解这位网友的燃眉之急。

    源代码如下:

package com.j2medev.image;

import javax.microedition.lcdui.*;


public class ImageUtil
{


    // fixed point constants
    private static final int FP_SHIFT = 13;

    private static final int FP_ONE = 1 << FP_SHIFT;

    private static final int FP_HALF = 1 << (FP_SHIFT - 1);

    // resampling modes - valid values for the mode parameter of resizeImage()
    // any other value will default to MODE_BOX_FILTER because of the way the
    // conditionals are set in resizeImage()
    public static final int MODE_POINT_SAMPLE = 0;

    public static final int MODE_BOX_FILTER = 1;

    /**
     * getPixels Wrapper for pixel grabbing techniques. I separated this step
     * into it's own function so that other APIs (Nokia, Motorola, Siemens,
     * etc.) can easily substitute the MIDP 2.0 API (Image.getRGB()).
     *
     * @param src
     *            The source image whose pixels we are grabbing.
     * @return An int array containing the pixels in 32 bit ARGB format.
     */
    int[] getPixels(Image src)
    {
        int w = src.getWidth();
        int h = src.getHeight();
        int[] pixels = new int[w * h];
        src.getRGB(pixels, 0, w, 0, 0, w, h);
        return pixels;
    }

    /**
     * drawPixels Wrapper for pixel drawing function. I separated this step into
     * it's own function so that other APIs (Nokia, Motorola, Siemens, etc.) can
     * easily substitute the MIDP 2.0 API (Image.createRGBImage()).
     *
     * @param pixels
     *            int array containing the pixels in 32 bit ARGB format.
     * @param w
     *            The width of the image to be created.
     * @param h
     *            The height of the image to be created. This parameter is
     *            actually superfluous, because it must equal pixels.length / w.
     * @return The image created from the pixel array.
     */
    Image drawPixels(int[] pixels, int w, int h)
    {
        return Image.createRGBImage(pixels, w, h, true);
    }

    /**
     * resizeImage Gets a source image along with new size for it and resizes
     * it.
     *
     * @param src
     *            The source image.
     * @param destW
     *            The new width for the destination image.
     * @param destH
     *            The new heigth for the destination image.
     * @param mode
     *            A flag indicating what type of resizing we want to do. It
     *            currently supports two type: MODE_POINT_SAMPLE - point sampled
     *            resizing, and MODE_BOX_FILTER - box filtered resizing
     *            (default).
     * @return The resized image.
     */
    Image resizeImage(Image src, int destW, int destH, int mode)
    {
        int srcW = src.getWidth();
        int srcH = src.getHeight();

        // create pixel arrays
        int[] destPixels = new int[destW * destH]; // array to hold destination
                                                   // pixels
        int[] srcPixels = getPixels(src); // array with source's pixels

        if (mode == MODE_POINT_SAMPLE)
        {
            // simple point smapled resizing
            // loop through the destination pixels, find the matching pixel on
            // the source and use that
            for (int destY = 0; destY < destH; ++destY)
            {
                for (int destX = 0; destX < destW; ++destX)
                {
                    int srcX = (destX * srcW) / destW;
                    int srcY = (destY * srcH) / destH;
                    destPixels[destX + destY * destW] = srcPixels[srcX + srcY
                            * srcW];
                }
            }
        } else
        {
            // precalculate src/dest ratios
            int ratioW = (srcW << FP_SHIFT) / destW;
            int ratioH = (srcH << FP_SHIFT) / destH;

            int[] tmpPixels = new int[destW * srcH]; // temporary buffer for the
                                                     // horizontal resampling
                                                     // step

            // variables to perform additive blending
            int argb; // color extracted from source
            int a, r, g, b; // separate channels of the color
            int count; // number of pixels sampled for calculating the average

            // the resampling will be separated into 2 steps for simplicity
            // the first step will keep the same height and just stretch the
            // picture horizontally
            // the second step will take the intermediate result and stretch it
            // vertically

            // horizontal resampling
            for (int y = 0; y < srcH; ++y)
            {
                for (int destX = 0; destX < destW; ++destX)
                {
                    count = 0;
                    a = 0;
                    r = 0;
                    b = 0;
                    g = 0; // initialize color blending vars
                    int srcX = (destX * ratioW) >> FP_SHIFT; // calculate
                                                             // beginning of
                                                             // sample
                    int srcX2 = ((destX + 1) * ratioW) >> FP_SHIFT; // calculate
                                                                    // end of
                                                                    // sample

                    // now loop from srcX to srcX2 and add up the values for
                    // each channel
                    do
                    {
                        argb = srcPixels[srcX + y * srcW];
                        a += ((argb & 0xff000000) >> 24); // alpha channel
                        r += ((argb & 0x00ff0000) >> 16); // red channel
                        g += ((argb & 0x0000ff00) >> 8); // green channel
                        b += (argb & 0x000000ff); // blue channel
                        ++count; // count the pixel
                        ++srcX; // move on to the next pixel
                    } while (srcX <= srcX2
                            && srcX + y * srcW < srcPixels.length);

                    // average out the channel values
                    a /= count;
                    r /= count;
                    g /= count;
                    b /= count;

                    // recreate color from the averaged channels and place it
                    // into the temporary buffer
                    tmpPixels[destX + y * destW] = ((a << 24) | (r << 16)
                            | (g << 8) | b);
                }
            }

            // vertical resampling of the temporary buffer (which has been
            // horizontally resampled)
            System.out.println("Vertical resampling...");
            for (int x = 0; x < destW; ++x)
            {
                for (int destY = 0; destY < destH; ++destY)
                {
                    count = 0;
                    a = 0;
                    r = 0;
                    b = 0;
                    g = 0; // initialize color blending vars
                    int srcY = (destY * ratioH) >> FP_SHIFT; // calculate
                                                             // beginning of
                                                             // sample
                    int srcY2 = ((destY + 1) * ratioH) >> FP_SHIFT; // calculate
                                                                    // end of
                                                                    // sample

                    // now loop from srcY to srcY2 and add up the values for
                    // each channel
                    do
                    {
                        argb = tmpPixels[x + srcY * destW];
                        a += ((argb & 0xff000000) >> 24); // alpha channel
                        r += ((argb & 0x00ff0000) >> 16); // red channel
                        g += ((argb & 0x0000ff00) >> 8); // green channel
                        b += (argb & 0x000000ff); // blue channel
                        ++count; // count the pixel
                        ++srcY; // move on to the next pixel
                    } while (srcY <= srcY2
                            && x + srcY * destW < tmpPixels.length);

                    // average out the channel values
                    a /= count;
                    a = (a > 255) ? 255 : a;
                    r /= count;
                    r = (r > 255) ? 255 : r;
                    g /= count;
                    g = (g > 255) ? 255 : g;
                    b /= count;
                    b = (b > 255) ? 255 : b;

                    // recreate color from the averaged channels and place it
                    // into the destination buffer
                    destPixels[x + destY * destW] = ((a << 24) | (r << 16)
                            | (g << 8) | b);
                }
            }
        }

        // return a new image created from the destination pixel buffer
        return drawPixels(destPixels, destW, destH);
    }

}

    有兴趣的网友可以仔细研究一下。我准备了一个图片,然后写了一个测试的MIDlet。下面是效果对比。


 

 

 

 

 

 

 

/*
 * Created on 2004-12-24
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.j2medev.image;

import java.io.IOException;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class TestMIDlet extends MIDlet
{
    private Display display;

    private Form form;

    protected void startApp() throws MIDletStateChangeException
    {
       
        display = Display.getDisplay(this);
        Image srcImage = null;
        try
        {
            srcImage = Image.createImage("/welcome.png");

        } catch (IOException e)
        {
        }
        ImageUtil iu = new ImageUtil();
        form = new Form("Image");
        int width = form.getWidth();
        int height = form.getHeight();
        Image destImage = iu.resizeImage(srcImage, width, height,
                ImageUtil.MODE_POINT_SAMPLE);
        form.append(destImage);
        display.setCurrent(form);

    }


    protected void pauseApp()
    {
      
    }


    protected void destroyApp(boolean arg0) throws MIDletStateChangeException
    {
       

    }

}

 

阿里平头哥与华为芯片的比较 阿里平头哥与华为芯片代表了中国AI芯片领域的两种典型发展路径:平头哥通过兼容CUDA生态快速切入市场,以较低成本提供接近国际水平的AI算力;华为则坚持全栈自研路线,构建从芯片到框架的完整技术体系,更注重供应链安全和自主可控。从短期来看,平头哥PPU在单卡性能参数上全面超越昇腾910B,接近英伟达H20水平,且成本优势明显,有望在云服务和互联网应用领域取得更大市场份额。而华为昇腾则凭借全栈自研和端边云协同优势,在政企市场和科研领域更具竞争力。 阅读详情

相关推荐

5分钟搞定阿里云千问大模型API申请:手把手教你获取API Key

本文提供了一份高效的阿里云通义千问大模型API Key获取实战指南。通过清晰的步骤,帮助开发者在五分钟内完成从账号准备、精准导航控制台到创建并验证API Key的全过程,并强调了密钥安全管理和基础调用测试的重要性,助力快速集成AI能力。

ol789012345的博客 1354

基于ESP8266的3D打印农场状态监控系统FarmLight开源项目详解

物联网技术通过将物理设备连接到网络,实现数据的采集、传输与远程控制,其核心原理在于嵌入式系统与网络通信协议的结合。这项技术的价值在于能够将虚拟信息映射到物理世界,实现状态的实时、直观可视化,从而提升设备管理与运维效率。在分布式设备监控、智能家居和工业自动化等应用场景中,状态可视化是关键的工程实践需求。本文聚焦于一个具体的开源实现——FarmLight项目,它巧妙地运用ESP8266微控制器和WS2812B LED,构建了一套用于3D打印农场的轻量级状态指示灯系统。该项目不仅解决了多台3D打印机状态全局感知的

congji3817的博客 425

命令行执行YOLO训练命令报错:1.PermissionError: [WinError 5] 拒绝访问 2.OMP: Error#15: Initializing libiomp5md.dll...

(已解决!)报错:1.PermissionError: [WinError 5] 拒绝访问 2.OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.

Gpengyuyan的博客 1125

J2ME经验总结之图片缩放

作者:hunhun1981出自:http://blog.csdn.net/hunhun1981/  public static Image ZoomImage(Image src, int desW, int desH) {  Image desImg = null;  int srcW = src.getWidth(); // 原始图像宽  int srcH = src.getH

1453

centos7下安装gcc-10.3.0

生成多个系统版本的代码,如果你的操作系统是32位,默认就已经设置为 disable,这时gcc仅能生成32位的可执行程序;这里只开启了c,c++ 和fortran,因为支持的语言越多,就需要安装越多的相应静态与动态库,还有五花八门的依赖库,这会让管理变得困难,体积也会变得庞大。启用posix标准的线程支持,这个设置取决于宿主或目标操作系统的类型,其它可用值有:aix,dec,solaris,win32等,如果你是其它的类UNIX系统,就需要设置相应的值。指定安装路径,这里没有指定,就直接放到文件夹里就好。

lxystar2003的博客 1189

IMU、INS、GNSS与组合导航:从原理到工程实践全解析

在自动驾驶、无人机和机器人等智能系统的定位方案中,IMU、INS、GNSS和组合导航常被混为一谈,但它们在硬件层级、数据特性和误差机制上截然不同。IMU作为惯性测量单元,以百赫兹以上频率输出加速度和角速度;INS基于IMU完成姿态、速度与位置的递推解算,却因积分累积误差而随时间漂移;GNSS提供绝对位置,但易受遮挡和干扰。组合导航通过卡尔曼滤波将两者融合,实现短期不飘、长期不偏的连续定位,这正是高精度导航系统的技术底座。工程落地时,从IMU标定、Allan方差分析到相机/LiDAR与IMU外参标定,再到松耦

weixin_29193259的博客 384

MIDP1.0实现图片的缩放

使用MIDP1.0来实现图片的缩放 1>两种方式实现图片的放缩: (1)先放缩宽,然后放缩高,时间复杂度比较低 代码实现:private static final Image scale(Image srcImage, int desWidth, int desHight) {int srcWidth = srcImage.getWidth();in...

weixin_30772261的博客 110

STM32CubeMX | HAL库实战:ADC多通道采集模式深度解析(轮询、DMA、TIM触发)

本文深度解析了基于STM32CubeMX与HAL库实现ADC多通道数据采集的三种核心模式:轮询、DMA以及TIM触发DMA。文章通过对比分析,详细阐述了各模式的配置要点、适用场景与潜在陷阱,旨在帮助开发者根据实时性、CPU占用及采样精度等需求,选择并实现高效稳定的多通道数据采集方案。

postgres8guard的博客 972

收集了几个关于J2ME图片缩放的函数

收集了几个图像缩放函数,可能实现的方式很多,感觉这几个还是不错的,分享下说明:以下函数都是基于MIDP2.0的,缩放后保留透明色。代码1,resizeImage函数 public static Image resizeImage(Image src, int destW, int destH) { int srcW = src.getWidth();

千里积于跬步,江海成于小流 1099

26. Fabric2.2 司法存证的智能合约分析

有很多同学反馈 Fabric 智能合约读起来比较费劲,对于新手不友好看不懂,这里选择一个司法存证的智能合约,阅读、分析智能合约基础框架与核心流程代码,培养大家智能合约编写的方法论。

菜鸟的博客 1340

RK+linux教程:RK3588 RGA硬件加速在YOLOv5图像预处理中的深度应用教程

摘要: 本教程深入解析了RK3588芯片的RGA硬件加速器在YOLOv5图像预处理中的应用。通过专用硬件设计,RGA支持图像缩放、边界填充等核心操作,结合零拷贝技术显著提升处理效率。重点分析了LetterBox算法的RGA实现,包括参数计算、边界填充和性能优化,并与传统CPU处理对比,展示了RGA在高分辨率图像处理中的优势。教程还提供了统一的预处理接口设计,便于在OpenCV与RGA方案间灵活切换,为RK3588平台的深度学习部署提供实用优化方案。

LXY_LOVE36的博客 977

J2ME图片缩放

 这个函数是我以前在网上搜罗到的,且不谈效果,性能什么的。只觉得它非常好用。用了很长时间,可惜不知道是谁。真要谢谢这位作者了。这个函数使用了midp2.0的getRGB()函数,效率不错,基本上没什么可优化的了。public static Image ZoomImage(Image src, int desW, int desH) {  Image desImg = null;

Ray的专栏 1231

自私兽群优化器(SHO)详解:从生物本能到智能优化

自私兽群优化器(SHO)是一种受动物群体自私行为启发的智能优化算法。该算法模拟动物在捕食威胁下的两种行为:聚集行为(全局搜索)和自私行为(局部搜索),将优化问题的解空间映射为生存环境,候选解视为猎物个体。SHO通过安全性评估将猎物分为安全、危险和高危三类,分别采用不同的位置更新策略,并引入捕食者角色增加选择压力。相比传统优化算法,SHO具有无需梯度信息、自适应平衡探索与开发、参数简单等优势,特别适合高维复杂和多模态优化问题。算法通过马尔可夫链理论保证收敛性,已在工程设计和数据挖掘等领域展现出良好性能。

qq_42212808的博客 198

如何在MIDP中实现图片放缩(转自linuxmine)

关键字: J2ME              设计游戏的朋友经常会遇到对图片资源的操作。今天浏览web发现此贴不错。所以抄过这边来原文:www.linuxmine.com/45911.html无论在midp1.0还是在 midp2.0中,系统都没有给我们提供对图片进行伸缩操作的api.但是其实我们只要在程序代码中略施小计,就能达到这个效果,只是效果要比美术做出来的图片,呵呵,差多啦,同时也

无花专栏--http://www.ucweb.com 963

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

J2ME(MIDP2.0)图像处理演示程序(完整源代码)增强版

J2ME(MIDP2.0)图像处理演示程序(完整源代码)增强版此程序的创意来自于the3gwireless(http://blog.csdn.net/the3gwireless),第一版的源代码由the3gwireless利用从互联网上获得的资料整理修改完成。本例的目的是帮助J2ME的爱好者学习和掌握基本的图像处理知识,也希望其它深谙此道的朋友对代码进行进一步完善和增强。由于此代码主要

4657

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

[转]J2ME中对Image的缩放

 a sniplet from the article "Taking Pictures with MMAPI"http://developers.sun.com/techtopics/mobility/midp/articles/picture/ clapton_xp@hotmail.com创建缩略图MIDP2.0中可以对图片中的像素进行操作,在MIDP1.0中则不然。本例用

blog://clapton/ 1215

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

MIDP 1.0 的图片放缩, setClip实现

 public Image resizeImage(Image image, int scale) {//scale 是放缩比率哈, 100是正常大小        int sWidth = image.getWidth();        int sHeight = image.getHeight();        int Width = sWidth * scale

Scent of Mobile Application 2682

J2ME图片缩放函数

public static Image ZoomImage(Image src, int desW, int desH){    Image desImg = null;    int srcW = src.getWidth(); // 原始图像宽    int srcH = src.getHeight(); // 原始图像高    int[] srcBuf = new int

759

J2ME图片缩放和透明效果

<br />这个函数是我以前在网上搜罗到的,且不谈效果,性能什么的。只觉得它非常好用。<br />用了很长时间,可惜不知道是谁。真要谢谢这位作者了。<br />这个函数使用了midp2.0的getRGB()函数,效率不错,基本上没什么可优化的了。<br /><br />public static Image ZoomImage(Image src, int desW, int desH) { <br />  Image desImg = null; <br />  int srcW = src.getWid

有家客栈 君子不器 359

J2ME中图片缩放的优化

无论在midp1.0还是在midp2.0中,系统都没有给我们提供对图片进行伸缩操作的api.但是其实我们只要在程序代码中略施小计,就能达到这个效果,只是效果要比美术做出来的图片,呵呵,差多啦,同时也会造成性能损失。伸缩图片的构造原理就是简单沿x,y轴按比例放缩,比如说我们需要把一张16*16的png图片转化成一张32*32的图片,那么我们可以先对该图片做一个水平方向上的拉伸操作,然后再把水平拉伸后

专栏 705

如何在MIDP中实现图片放缩

  无论在midp1.0还是在midp2.0中,系统都没有给我们提供对图片进行伸缩操作的api.但是其实我们只要在程序代码中略施小计,就能达到这个效果,只是效果要比美术做出来的图片,呵呵,差多啦,同时也会造成性能损失。伸缩图片的构造原理就是简单沿x,y轴按比例放缩,比如说我们需要把一张16*16的png图片转化成一张32*32的图片,那么我们可以先对该图片做一个水平方向上的拉伸操作,然后再把水平拉

Stone的专栏 1741

J2ME插值算法实现图片的放大缩小

文章来源:J2ME开发网前段时间接触了一些数字图像处理的问题,在1位师兄的指导下,在j2me平台,完成了一些基本的2D图像处理算法。就当是对这段知识做一下总结,决定把这些算法写出来,和各位朋友共同探讨。这篇文章先介绍图像放大缩小的实现,程序是以Nokia S40的机器为平台实现的。1、实现图形缩放的基本思想:图像的变形变换,简单的说就是把源图像每个点坐标通过变形运算转为目标图像相应点的新坐标,但是

mobilechannel的专栏 1050
上一篇: MIDP图形用户界面结构分析
下一篇: 刘翔一句话给了社会一耳光[ZZ]
mingjava
博客等级 码龄24年 68粉丝 114原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值