public SampleView(Context context) { super(context); setFocusable(true); setFocusableInTouchMode(true); mPicture = new Picture(); drawSomething(mPicture.beginRecording(200, 100)); mPicture.endRecording(); mDrawable = new PictureDrawable(mPicture); }
/** * Method to create a new picture by scaling the current picture by the given x and y factors * * @param xFactor the amount to scale in x * @param yFactor the amount to scale in y * @return the resulting picture */ public Picture scale(double xFactor, double yFactor) { // set up the scale transform AffineTransform scaleTransform = new AffineTransform(); scaleTransform.scale(xFactor, yFactor); // create a new picture object that is the right size Picture result = new Picture((int) (getWidth() * xFactor), (int) (getHeight() * yFactor)); // get the graphics 2d object to draw on the result Graphics graphics = result.getGraphics(); Graphics2D g2 = (Graphics2D) graphics; // draw the current image onto the result image scaled g2.drawImage(this.getImage(), scaleTransform, null); return result; }
@Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.WHITE); canvas.drawPicture(mPicture); canvas.drawPicture(mPicture, new RectF(0, 100, getWidth(), 200)); mDrawable.setBounds(0, 200, getWidth(), 300); mDrawable.draw(canvas); ByteArrayOutputStream os = new ByteArrayOutputStream(); mPicture.writeToStream(os); InputStream is = new ByteArrayInputStream(os.toByteArray()); canvas.translate(0, 300); canvas.drawPicture(Picture.createFromStream(is)); }
private Picture initialImage() { pic2 = new Picture(500, 600); pic1 = new Picture(500, 600); for (int x = 0; x < pic2.width(); x++) for (int y = 0; y < pic2.height(); y++) { double dist = 1.0 - Math.sqrt((x - 300) * (x - 300) + (y - 200) * (y - 200)) / 500; int red = (int) (dist < 0.5 ? 0 : Math.min(Math.pow(dist, 0.4) + Math.pow(dist - 0.5, 0.1), 1.0) * 255); int green = (int) (dist * 255); int blue = 0; pic2.set(x, y, new Color(red, green, blue)); } return pic2; }
private static void handlePost(Post post) { Main.post_post_hash.put(post, post); for (Picture picture : post.pictures) { Helper.downloadFileFromURLToFileInTemp(picture.thumb_url, picture.thumb_name); picture.md5_id = Helper.createMD5FromFileInTemp(picture.thumb_name); Helper.moveTempImageToStore(picture.thumb_name, new File(Main.blogdir, picture.md5_id)); if (!Main.pic_pic_hash.containsKey(picture)) { Main.pic_pic_hash.put(picture, picture); Main.pic_post_hash.put(picture, post); Helper.downloadFileFromURLToFileInTemp(picture.media_url, picture.media_name); Helper.moveTempImageToStore(picture.media_name, new File(Main.blogdir, picture.md5_id)); } else { if (!post.equals(Main.pic_post_hash.get(picture))) { dup_post_list.put(post, Main.pic_post_hash.get(picture)); } } } }
public void actionPerformed(ActionEvent e) { String cmd = (e.getActionCommand()); if (cmd.equals(aboutItem.getText())) JOptionPane.showMessageDialog( this, "Simple Image Program for DB2004\nversion 0.1\nThanks to BvS", "About imageLab", JOptionPane.INFORMATION_MESSAGE); else if (cmd.equals(quitItem.getText())) System.exit(0); else if (cmd.equals(openItem.getText())) { int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { pic2 = new Picture(chooser.getSelectedFile().getName()); pic1 = new Picture(pic2.width(), pic2.height()); lab.setIcon(pic2.getJLabel().getIcon()); sliderPanel.setVisible(false); pack(); repaint(); } catch (Exception ex) { JOptionPane.showMessageDialog( this, "Could not open " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(), "Open Error", JOptionPane.INFORMATION_MESSAGE); } } } else if (cmd.equals(saveItem.getText())) { int returnVal = chooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { pic2.save(chooser.getSelectedFile().getName()); } catch (Exception ex) { JOptionPane.showMessageDialog( this, "Could not write " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(), "Save Error", JOptionPane.INFORMATION_MESSAGE); } } } }
public String toString() { StringBuilder output = new StringBuilder(); // String NEW_LINE = System.getProperty("line.separator"); output.append("Common Name: " + myCommonName + "\n"); output.append(myGenericInfo.toString()); output.append(myPicture.toString()); output.append(mySound.toString()); return output.toString(); }
private static void tryResUrls(Picture picture) { String hi_res = ""; String url = picture.media_url.toString(); for (String ending : Main.endings) { try { hi_res = url.replace(url.substring(url.lastIndexOf("_"), url.lastIndexOf(".")), ending); URL hi_url = new URL(hi_res); File hi_name = Helper.extractMediaFileNameFromURL(hi_url); if (hi_name.equals(picture.media_name)) { picture.hi_url = hi_url; picture.hi_name = hi_name; picture.downloaded_hi = true; break; } else { boolean success = Helper.downloadFileFromURLToFileInTemp(hi_url, hi_name); if (success) { picture.hi_url = hi_url; picture.hi_name = hi_name; picture.downloaded_hi = true; Helper.moveTempImageToStore(hi_name, new File(Main.blogdir, picture.md5_id)); break; } } } catch (MalformedURLException ex) { Main.error(String.format("Attempted hi res url %s is a malformed URL.", hi_res)); } } }
protected void importPicture(List<Picture> poiPictures, Sheet poiSheet, SSheet sheet) { for (Picture poiPicture : poiPictures) { PictureData poiPicData = poiPicture.getPictureData(); Integer picDataIx = importedPictureData.get(poiPicData); // ZSS-735 if (picDataIx != null) { sheet.addPicture( picDataIx.intValue(), toViewAnchor(poiSheet, poiPicture.getClientAnchor())); } else { Format format = Format.valueOfFileExtension(poiPicData.suggestFileExtension()); if (format != null) { SPicture pic = sheet.addPicture( format, poiPicData.getData(), toViewAnchor(poiSheet, poiPicture.getClientAnchor())); importedPictureData.put(poiPicData, pic.getPictureData().getIndex()); } else { // TODO log we ignore a picture with unsupported format } } } }
public int buildBird(String[] birdData, int location) throws FileNotFoundException { myCommonName = birdData[location++]; myGenericInfo = new GenericInfo(); location = myGenericInfo.buildGenericInfo(birdData, location); myPicture = new Picture(); location = myPicture.buildPicture(birdData, location); mySound = new Sound(); location = mySound.buildSound(birdData, location); // System.out.println(mySound.toString()); // System.out.println(location); return location; }
/** * Method to add a picture to the frame sequence * * @param picture the picture to add */ public void addFrame(Picture picture) { // add this picture to the list pictureList.add(picture); // write out this frame picture.write(directory + baseName + numberFormat.format(frameNumber) + ".jpg"); // if this sequence is being shown update the frame if (shown) { if (pictureFrame != null) pictureFrame.setPicture(picture); else pictureFrame = new PictureFrame(picture); } // increment the frame number frameNumber++; }
public String getMyPicture() { return myPicture.getBirdPictureLocation(); }