Commits

radim  committed e826393

Support for non-16bit-images to the device screenshot action. Contribution by christian at fi12 dot de.

  • Participants
  • Parent commits 106d087

Comments (0)

Files changed (2)

File core/manifest.mf

 OpenIDE-Module: org.netbeans.modules.android.core/2
 OpenIDE-Module-Layer: org/netbeans/modules/android/core/layer.xml
 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/android/core/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.10
+OpenIDE-Module-Specification-Version: 1.11
 OpenIDE-Module-Java-Dependencies: Java > 1.6
 AutoUpdate-Show-In-Client: false
 

File core/src/org/netbeans/modules/android/core/ui/DeviceNode.java

                 if (image == null) {
                     throw new IOException("No screenshot"); //NOI18N
                 }
-                final BufferedImage img = new BufferedImage(image.width, image.height, BufferedImage.TYPE_USHORT_565_RGB);
+                int imageType;
+
+                // determine image format
+                switch(image.bpp) {
+                    case 16: {
+                        imageType = BufferedImage.TYPE_USHORT_565_RGB;
+                        break;
+                    }
+
+                    default: {
+                        imageType = BufferedImage.TYPE_INT_ARGB;
+                        break;
+                    }
+                }
+
+                final BufferedImage img = new BufferedImage(image.width, image.height, imageType);
                 final DataBuffer db = img.getRaster().getDataBuffer();
                 for (int y=0; y<image.height; y++) {
                     for (int x=0; x<image.width; x++) {
-                        byte l = image.data[2*(y*image.width+x)];
-                        byte h = image.data[2*(y*image.width+x)+1];
-                        int color = ((h<<8)|(l&0xff)) & 0xffff;                        
+                        int color;
+
+                        switch(imageType) {
+                            case BufferedImage.TYPE_USHORT_565_RGB: {
+                                byte l = image.data[2*(y*image.width+x)];
+                                byte h = image.data[2*(y*image.width+x)+1];
+                                color = ((h<<8)|(l&0xff)) & 0xffff;
+                                break;
+                            }
+
+                            default: {
+                                color = image.getARGB((image.bpp / 8) * (y * image.width + x));
+                                break;
+                            }
+                        }
+                        
                         db.setElem(y*image.width+x, color);
                     }
                 }