【发布时间】:2014-09-07 07:38:29
【问题描述】:
我想做的是在 android 中读取一些图像并将图像中的每个像素转换为 RGB 值,这是我找到的代码:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button test=(Button)findViewById(R.id.button1);
test.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
BufferedImage bi=ImageIO.read(new File("C:\\images\\Sunset.jpg"));
int[] pixel;
for (int y = 0; y < bi.getHeight(); y++) {
for (int x = 0; x < bi.getWidth(); x++) {
pixel = bi.getRaster().getPixel(x, y, new int[3]);
System.out.println(pixel[0] + " - " + pixel[1] + " - " + pixel[2] + " - " + (bi.getWidth() * y + x));
}
}
}
});
}
}
但是我在导入一些这样的包时遇到了问题:
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
而且我不知道如何下载它们或解决此问题的最佳方法.. 有帮助吗??
【问题讨论】:
-
你应该使用这个:developer.android.com/reference/android/graphics/… BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888;位图位图 = BitmapFactory.decodeFile(photoPath, options); selected_photo.setImageBitmap(位图);
标签: android awt javax.imageio