如何翻转 EncodedImage Blackberry
嘿。我想水平翻转图像,我使用以下代码:
public static EncodedImage flip (Bitmap png)
{
int width = png.getWidth();
int height = png.getHeight();
Bitmap temp = new Bitmap(width,height);
int[] argb = new int[ width * height ];
int[] invertArgb = new int[ width * height ];
png.getARGB( argb, 0, width, 0, 0, width, height );
for ( int i = height - 1; i >= 0; --i ) {
for ( int j = width - 1; j >= 0; --j ) {
invertArgb[ ( width - j - 1 ) + ( width * i ) ] = argb[ j + ( width * i ) ];
}
}
temp.setARGB( invertArgb, 0, width, 0, 0, width, height );
PNGEncoder encoder = new PNGEncoder(temp, true);
byte[] imageBytes = null;
try {
imageBytes = encoder.encode(true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
EncodedImage fullImage = EncodedImage.createEncodedImage(imageBytes, 0, imageBytes.length);
return fullImage;
}
但是..有人知道如何直接翻转 EncodedImage
而不进行转换,因为它需要一点点
时间PNGEncoder.java 在这里: http://www.mobiyana.com/code/blackberry/PNGEncoder .java
Hy. I want to flip horizontal an image and I use this code:
public static EncodedImage flip (Bitmap png)
{
int width = png.getWidth();
int height = png.getHeight();
Bitmap temp = new Bitmap(width,height);
int[] argb = new int[ width * height ];
int[] invertArgb = new int[ width * height ];
png.getARGB( argb, 0, width, 0, 0, width, height );
for ( int i = height - 1; i >= 0; --i ) {
for ( int j = width - 1; j >= 0; --j ) {
invertArgb[ ( width - j - 1 ) + ( width * i ) ] = argb[ j + ( width * i ) ];
}
}
temp.setARGB( invertArgb, 0, width, 0, 0, width, height );
PNGEncoder encoder = new PNGEncoder(temp, true);
byte[] imageBytes = null;
try {
imageBytes = encoder.encode(true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
EncodedImage fullImage = EncodedImage.createEncodedImage(imageBytes, 0, imageBytes.length);
return fullImage;
}
Buut.. does anyone have an ideea how to flip directly EncodedImage
without converting because it's taking a little bit long
P.S. PNGEncoder.java is here: http://www.mobiyana.com/code/blackberry/PNGEncoder.java
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个有效的解决方案是提供两个版本的图像;一种是正常的,另一种是翻转的。当然,您必须考虑加载所需的时间与图像所需的空间量。如果您正在寻求更快的加载时间,那么这是一个至少应该考虑的设计决策。
A valid solution is to provide two versions of the images; one normal and one flipped. Of course you will have to take into consideration the amount of time it takes to load versus the amount of space your images will require. It's a design decision that should at least be considered if you are looking for faster load times.
我想 Graphics.drawTexturedPath() 可以为你做一些事情。看看这个javadoc 来自 RIM
Graphics.drawTexturedPath() can do things for you I suppose. Take a look at this javadoc from RIM