android bufferedimage bitmap,Java BufferedImage / Android Bitmap

这篇博客探讨了如何通过定义一个接口来实现跨平台的兼容性,具体是在Android和桌面版中使用不同的图像对象。在Android上使用Bitmap对象,在桌面版上使用BufferedImage对象。调用者根据平台传递相应的实现,代码无需关心平台细节。是否采用此方法取决于图像对象在库中使用的广泛程度,如果仅涉及少量代码,直接使用反射可能更为简便。
摘要由CSDN通过智能技术生成

You could have your library not use either one, but some interface that you define that has all of the functions you need. Then for the Android version, you implement the interface using a Bitmap object, and for the desktop version, you implement the interface with a BufferedImage. The caller that uses your library passes in the implementation of the interface that corresponds to the platform the caller is using, and your code doesn't ever have to worry about platform specific stuff.

Of course, whether or not this is worth the effort depends on how extensively the image objects are used in your library. If it's just a line or two of code that needs to read the image, it may not be worth the trouble, and the reflection methods given in other answers might be easier.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值