Crop bmp image into 2 pieces and 3 pieces

Hi!
1. I want to crop a bmp image into 2 pieces and show the two cop image in 2 picturebox.
2. I want to crop a bmp image into 3 pieces and show theme in 3 picturebox.
Can anyone help me?

Hi,
put three pictureboxes to a Form named Form1
public Form1()
InitializeComponent();
//create an image
Bitmap bmp = new Bitmap(1024, 768);
//draw something to it
using (Graphics g = Graphics.FromImage(bmp))
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.Clear(Color.Green);
g.FillEllipse(Brushes.Yellow, new Rectangle(0, 0, bmp.Width, bmp.Height));
//and crop ionto the array
Bitmap[] bmps = CropIntoThree(bmp);
this.pictureBox1.SizeMode = this.pictureBox2.SizeMode = this.pictureBox3.SizeMode = PictureBoxSizeMode.Zoom;
if(bmps[0] != null)
this.pictureBox1.Image = bmps[0];
if(bmps[1] != null)
this.pictureBox2.Image = bmps[1];
if(bmps[2] != null)
this.pictureBox3.Image = bmps[2];
private Bitmap[] CropIntoThree(Bitmap bmp)
Bitmap[] bmps = new Bitmap[3];
//get a third of the width
int third = (int)Math.Ceiling(bmp.Width / 3.0);
for (int i = 0; i < 3; i++)
//if the last third should be smaller (by 1 or 2 pixels, you could use the modulo operator here too)
if (i * third + third > bmp.Width)
third = bmp.Width - i * third;
bmps[i] = bmp.Clone(new Rectangle(i * third, 0, third, bmp.Height), bmp.PixelFormat);
return bmps;
[And dont forget to Dispose the bitmaps when you do not need them anymore, e.g. in the FormClosing event.]
Regards,
  Thorsten

Similar Messages

  • Could any one tell me how to divide a BMP image into pixel blocks

    I am new in Java, Could anyone please show me how to block an BMP image into segmented blocks. Please help.

    could you be a bit more specific? What segmented blocks are you talking about? Is the width and the height of these segmented blocks givenby the user or does it have to be equal blocks of the whole image?

  • Goto saving images into a pdf and a message comes up " cannot start print job"

    I an having a problem with my lightroom 4- I goto save my images into a PDF and it comes up " cannot start print job" and wont even save the images. What can be the problem, ive never had the situation before.

    Hi Sasha,
    Using Acrobat, you can create forms that are called AcroForms. The forms created in LC Designer are called XFA (XML Forms Architecture) and are more data centric. While both will open in Acrobat, they are completely different animals.
    The issue with users not being able to save the data with Reader is that the form is not Reader Enabled. You can Reader Enable a form using one of two methods:
    Reader Enable the form using Acrobat Professional (V8 or below) or Acrobat Standard (V9 or above). Note there are licensing restrictions.
    Reader Enable the form using the full server product Adobe LiveCycle Reader Extensions ES2.5. This involves additional licensing fees.
    Have a look here: http://assure.ly/etkFNU, at the features that are available depending on whether the user has Acrobat or Reader; if the form is Reader Enabled; and how the form was Reader Enabled.
    The issue of Reader Enabling would also apply to AcroForms.
    I don't think that you need to dive into LC Designer just yet, as forms created in LC Designer face the same issues about Reader Enabling as forms developed in Acrobat.
    If your usage complies with the EULA, then you could Reader Enable your form in Acrobat.
    Hope that helps,
    Niall

  • How to insert embedded image into TextArea htmlText (and add IOErrorEvent.IO_ERROR listener).

    I unsuccessfully tried to find way to insert embedded image into TextArea via <img> tag. Can you point me out how to do this?
    Also, please, tell me how to handle IOErrorEvent from TextArea because adding IOErrorEvent.IO_ERROR listener to TextArea doesn't cause any effect when image url of img tag has not been found.
    Thanks

    i 've successfully inserted the image into the database... here is my code
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package PMS;
    import java.io.File;
    import java.io.FileInputStream;
    import java.sql.Blob;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    public class Browse_java
    static Connection con=null;
    public static void main(String args[])
    try{
    System.out.println("(browse.java) just entered in to the class");
    con = new PMS.DbConnection().getConnection();
    System.out.println("(browse.java) connection string is"+con);
    PreparedStatement ps = con.prepareStatement("INSERT INTO img_exp VALUES(?,?)");
    System.out.println("(browse.java) prepare statement object is"+ps);
    File file =new File("C:/Documents and Settings/Administrator/Desktop/Leader.jpg");
    FileInputStream fs = new FileInputStream(file);
    byte blob[]=new byte[(byte)file.length()];
    fs.read(blob);
    ps.setString(1,"C:/Documents and Settings/Administrator/Desktop/Leader.jpg");
    ps.setBytes(2, blob);
    System.out.println("(browse.java)length of picture is"+fs.available());
    int i = ps.executeUpdate();
    System.out.println("image inserted successfully"+i);
    catch(Exception e)
    e.printStackTrace();
    finally
    try {
    con.close();
    } catch (SQLException ex) {
    ex.printStackTrace();
    }

  • Load a redrawn image into a JLabel and save it into a BufferedImage?

    Hello, I'm doing a small application to rotate an image, it works, but I'd like to show it into a JLabel that I added, and also store the converted image into a BufferedImage to save it into a database, this is what I have so far:
    public void getImage() {
    try{
    db_connection connect = new db_connection();
    Connection conn = connect.getConnection();
    Statement stmt = conn.createStatement();
    sql = "SELECT image " +
    "FROM image_upload " +
    "WHERE image_id = 1";
    rset = stmt.executeQuery(sql);
    if(rset.next()){
    img1 = rset.getBinaryStream(1);
    buffImage = ImageIO.read(img1);
    rset.close();
    } catch(Exception e){
    System.out.println(e);
    public void paint(Graphics g){
    super.paint(g);
    Graphics2D g2 = (Graphics2D) g;
    ImageIcon imgIcon = new ImageIcon(buffImage);
    AffineTransform tx = AffineTransform.getRotateInstance(rotacion, imgIcon.getIconWidth()/2, imgIcon.getIconHeight()/2);
    g2.drawImage(imgIcon.getImage(), tx, this);
    jLabel1.setIcon(imgIcon);
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
    // TODO add your handling code here:
    setRotacion(getRotacion() + 1.5707963249999999);
    repaint();
    I get the image from a db, then using the paint() method I rotate the image, it works, but the new image is outside of the JLabel and I don't know how to assign the new one into the JLabel (like overwritting the original) and also how to store the new image into a BufferedImage to upload it into the database converted, thanks in advanced, any help would be appreciated, thanks!!
    Edited by: saman0suke on 25-dic-2011 14:07
    Edited by: saman0suke on 25-dic-2011 15:08

    I was able already to fill the JLabel with the modified content, just by creating a new BufferedImage, then create this one into a Graphics2D object and the drawing the image into it, last part, inserting the modified image into the database, so far, so good, thanks!
    EDIT: Ok, basic functionality is ok, I can rotate the image using AffineTransform class, and I can save it to the database and being displayed into a JLabel, now, there's a problem, the image for this example is 200 width and 184 height, but when I rotate it the width can be 184 and the height 200 depending on the position, but the BufferedImage that I create always read from original saved image:
    bimage = new BufferedImage(buffImage.getWidth(), buffImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Is there a way that I can tell BufferedImage new width and height after rotate it? :( as far as I understand this cannot be done because before the image bein rotated the bufferedImage is already created and, even being able to do it how can I get width and height from rotated image? thanks!
    Edited by: saman0suke on 25-dic-2011 19:40

  • I have a mac pro book and i need further editing tools, i need to do more professional design , i use key note a lot , but i cant crop an image in key note and i find it limiting. what is the next step?

    I Have a macbook pro and i want to edit my pictures further. Such as writing on them with different fonts etc.. ,but also being able to crop them the size i want, which key notes wont let me do. What is the next step?
    thanks!!

    Try the excellent shareware application, Graphic Converter. In addition there are many very good photo editing programs for the Mac. Look for them all at MacUpdate or CNET Downloads.

  • How can we insert image into mssql server  and retrive without path ?

    please give us detail coding

    http://forum.java.sun.com/thread.jspa?threadID=654086&messageID=4505027
    http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=y2u&q=how+to+store+image+in+mysql+and+display+with+example+in+jdbc&btnG=Search&meta=

  • Using photoshop elements 13 but the option to crop a single image is grayed out and also the option to crop a scanned image into individual pictures is grayed out - any ideas?

    The option to crop an image is always grayed out or unavailable - both for single images and when I want to crop scanned images into individual pictures. Any idea what I may be doing wrong?

    Did you try using the crop tool to see if it is working?  See the tool I am talking about.
    I suspect you are in Guided Mode rather than in Quick Mode or Expert Mode.

  • Photoshop CC: Have a template that I moved image into.  Image is too small.  How do I resize the image while in the template?  Or must I go to original image file and resize there again and again until I get the right fit?

    I have a template that I am able to plug different pictures into at different times.  The problem is that when I plug an image into that template, I find that the image is either too big or too small.  Is there a way to plug the image into the template and resize the image (and not the template itself) OR will I have to go to the file with the original image and resize it there and then try to plug it in to the template to see if it fits------and if it does not fit, go back to the original file with the image and resize it again and see if that fits---and so on and so on...........?  I have tried the" image size" option but it's hit or miss------mostly miss!
    Thanks!

    Read up on Smart Objects. It looks like you have no idea as to how to create and use them.
    Jut create a Smart Object from the layer containing whatever it image it is that you are "plugging into your template".  But you do need to learn the application at its most basic levels.
    Photoshop is a professional level application that makes no apologies for its very long and steep learning curve.  You cannot learn Photoshop in a forum, one question at a time.
    Or is it possible that you don't even have Photoshop proper but the stripped-down Photoshop Elements?"
    If the latter is the case, you're in the wrong forum.  This is not the Elements forum.
    Here's the link to the forum you would want if you're working in Elements.:
    https://forums.adobe.com/community/photoshop_elements/content
    If you do have Photoshop proper, please provide the exact version number of that application and of your OS.
    (edited for clarification)

  • How to change the image into byte and byte array into image

    now i am developing one project. i want change the image into byte array and then byte array into image.

    FileInputStream is = new FileInputStream(file);
    byte[] result = IOUtils.toByteArray(is);
    with apache common IO lib

  • Error in importing image into SAP using SE78

    Hi to all,
    I was trying to upload a '.bmp" image into SAP using SE78 but I failed.
    Se78 -> BMAP Bitmap Image -> Graphic -> Import -> Specified the complete path ->given name desc and type .
    Ended up with the following message.
    Graphic TRF_LOGO_REV could not be saved
    (2TRF_LOGO_REV)
    Pls. help as I am not sure whether I missed any step.
    Thankx in advance.

    Hi,
    Go to SE78 Transaction ie Aministration of form graphics,
           there select GRAPHICS General Graphics,under this BMAP Bitmap Images will come.
           select that,then a sub window will appear.
    There give the name of your logo and select the import button which is at the extreme left.
           Then again a sub window appears,there give the path name and name of the logo,and some description then press enter.
    Now the logo is uploaded,for preview you can select last button which is print preview.
    Now goto the form,select the window where you want to print the logo.
           Then in that window place the cursor at tag coloumn and select command line.
           Now go to INSERT and select GRAPHICS.A subwindow appers click on 'stored on Document Server',
           give the name of the logo and press enter.
           Then the image information will be displayed on the form.Save the form and activate it.
    Go to se38 transaction write the print program and execute.
    Regards,
    jaya

  • Combine bmp files into one single pdf?

    I've got 76 scanned pages in bmp format, and need to print them. Ideas? I can't be bothered to select each one of them separately in Preview and click on Print, then OK 76 times...
    Many thanks.

    There are some Apple Script Folder Action scripts that will convert image files from one format to another, so you can drop a set of images into a folder and they will all get individually converted to another file format. I don't know if you can create a multi-page pdf bundle, unless you have PostScipt maybe, then you can just append all the ps files into one large multi-page PS file.
    Even working with Automator you will have to learn a little about scripting anyway. Typing text commands in Terminal isn't that much different. Fink is really not that hard to install and work with. You do have to learn a little about Terminal and how to execute comands from the shell prompt.
    I think the solution to your problem would probably involve a combination of an Apple Script that executes a Terminal command to run the ImageMagick convert utility, and I think that it could be attached as a Folder Action to operate on a group of files when you drop them into it. I am not sure if Apple Script or Automator can do this work all by itself. They are really just fancy GUI wrappers for the instructions to other programs to do what they do. By themselves they don't actually do the work, they facilitate the flow of the work to the appropriate tools. ImageMagick is one such appropriate tool for your image conversion problem.
    I have been thinking about setting this up to handle faxing out a multi-page pdf document that is created by scanning single pages as individual jpg images. Sometimes I have to fill out a form and fax it somewhere, and my scanner is a single sheet scanner. So that would be handy to drag and drop a few pages of jpgs to a folder and have the convert utility bundle them to a pdf and have Preview open it, ready for faxing. Now, I use Terminal to
    cd ~/Desktop (or folder that contains my scanned jpgs)
    convert *.jpg fax_file.pdf
    open -a Preview fax_file.pdf
    Then in Preview Print... and Fax
    I could fax right from the command line also, but I like being able to look at the document first to check for errors, and get the fax number from Address Book.
    I'll post back if I ever get an Apple Script/Folder Action working, but I am in the middle of upgrading to Tiger and backing a lot of files up, so I might not get to work on it for a while.
    Try out fink, there are lots of free software tools that you might find useful.
    G3 Desktop, SonnetEncoreZIF G4 1GHz, 768MB, WingsAV-6MB, DVR-106D, 120GB Maxtor   Mac OS X (10.3.9)   PCI-TempoUltraATA66 120GB, 60GB, TangoUSB/FW, ATI Radeon

  • Problem in saving the image into SQL database..

    Hello,
    In my application I have to save image file (say jpg) into the database and retrieve back and display it on the applet. I am through with grabbing the pixels of the image & sending the pixel array to the servlet but I am struck in how to store the image into the database and retrieve the same.
    Can anybody please help me in this regard... its really urgent...
    Thanks in advance
    Swarna

    Hello.
    I've been researching this problem (saving images in a MySQL database) in order to accomplish a task I was assigned to. Finally I was able to do it. I'd be glad if it will be of any use.
    First of all: the original question was related to an applet. So, the post from rkippen should be read. It says almost everything, leaving the code job for us. Since I managed to write some code, I'll put it here, but I'm not dealing with the byte transferring issue.
    To obtain a byte array from a file I'd open the file with FileInputStream and use a loop to read bytes from it and save them into a ByteArrayOutputStream object. The ByteArrayOutputStream class has a method named �toByteArray()� which returns an array of bytes (byte [] b = baos.toByteArray()) that can be transferred in a socket connection, as said by rkippen.
    My problem was to save an image captured by a web camera. I had an Image object, which I converted into a byte array and saved into the database. Eventually I had to read the image and show it to the user.
    The table in the MySQL database could be:
    CREATE TABLE  test (
      id int(11) NOT NULL auto_increment,
      img blob NOT NULL,
      PRIMARY KEY  (id)
    )I had problems trying to use the �setBlob� and �getBlob� methods in the Statement object, so I used the �setBytes� and �getBytes� methods . In the end, I liked these methods most because they where more suitable to my application.
    The database operations are:
        public int insertImage(Image image) throws SQLException {
            int id = -1;
            String sql = "insert into test (img) values (?)\n";
            PreparedStatement ps = this.getStatement(sql);  // this method is trivial
            byte [] bytes = this.getBytes(imagem); // * see below
            ps.setBytes(1, bytes);
            ps.executeUpdate();
            id = ps.getGeneratedKeys().getInt(0); //Actually I couldn't make this line work yet.
            return id;
        public Image selectImage(int id) throws SQLException {
            Image img = null;
            String sql = "select img from test where id = ?\n";
            PreparedStatement ps = getStatement(sql);
            ps.setInt(1, id);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                byte [] bytes = rs.getBytes(1);
                img = this.getImage(bytes); // * see below
            return img;
        }* If the bytes are read directly from a file, I think it is not necessary to convert it into an Image. Just send the bytes to the database method would work. On the other hand, if the image read form the DB will be written directly into files, the bytes obtained from rs.getBytes(1) would be enough.
    The image operations are:
        public byte [] getBytes(Image image) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ImageIO.write(this.getBufferedImage(image), "JPEG", baos);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            return baos.toByteArray();
        public Image getImage(byte [] bytes)  {
            Image image = null;
            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            try {
                image = ImageIO.read(bais);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            return image;
        public BufferedImage getBufferedImage(Image image) {
            int width = image.getWidth(null);
            int height = image.getHeight(null);
            BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2d = bi.createGraphics();
            g2d.drawImage(image, 0, 0, null);
            return bi;
        }That's it. I hope it is useful.

  • Error while uploading the BMP image

    Hi All there,
    I am trying to upload the BMP image on desktop through Se78 but I am getting the error that
    This is not the a *.BMP file (they begin with <> ''BM")'
    Please help
    Regards
    Sagar

    Hi Sagar,
    You can try to save the image once again as .bmp image in your desktop and then try to upload through se78.
    Thanks
    Arul

  • Inserting Images into Dreamweaver through Div Tag

    Hi im quite new to Dreamweaver and i've got CS3...I've just
    designed and sliced up a website in Photoshop and have started to
    compile it together in Dreamweaver using HTML and CSS. I've just
    added a Div tag and added images into the page and i've got stuck,
    i cant seem to put another image next to one iv already placed
    their.
    I need help on how to work with Div Tags and applying images
    so that i can fix my website like a Jigsaw.
    I have provided the code i hav in my HTML so far...

    Maybe this will help you -
    Taking a Fireworks comp to a CSS-based layout in Dreamweaver
    http://www.adobe.com/devnet/fireworks/articles/web_standards_layouts_pt1.html
    http://www.adobe.com/devnet/fireworks/articles/web_standards_layouts_pt2.html
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "DThandi" <[email protected]> wrote in
    message
    news:gk8anj$4qc$[email protected]..
    > Let me show you the before and after images of the site
    im working on,
    > then
    > maybe what im trying to describe can become more
    clearer...Your right that
    > i do
    > need some basic understanding, I actually used to know
    the answer to my
    > own
    > question but since i havn't played around with
    Dreamweaver for a while i
    > seem
    > to have forgotten.
    >
    > This was the image on Photshop:
    >
    http://i187.photobucket.com/albums/x151/ohhchakdeh/SAMPLE.jpg
    >
    > This is where I am stuck now:
    >
    http://i187.photobucket.com/albums/x151/ohhchakdeh/stuck.jpg
    >
    > These are all the small images i have sliced up from
    Photshop:
    >
    http://i187.photobucket.com/albums/x151/ohhchakdeh/Untitled.jpg
    >
    > As you can see i have trouble coding in HTML. So far i
    have been
    > following a
    > tutorial video showing me how to had images and align
    them through Div
    > Tag...But now i am trying to put images side by side in
    the Navigation
    > area and
    > on top of and underneath each other. As you can see i
    have Home.jpg and
    > Home-Scrap.jpg. Home Scrap needs to go under Home and
    both of them images
    > need
    > to go next to image Left-Short.jpg.
    >
    > Thank You
    >

Maybe you are looking for

  • How can we handle database exceptions in bpel?

    Hi, I'm calling a couple of pl/sql based services in my bpel flow. Given the services are pl/sql based we might hit some databse errors . For example: -Existing State of Packages has been discarded -Database is down -PL/sql procedure itself throws an

  • DSM window is a big window with log in it

    All, I have a strange issue. On some PC's, when the user logs off or switches from one scrren to another, the DSM window opens.  This is what I would expect.  However, it opens a large window (around 1/3 of the screen) rather than a very small one. 

  • Inventory Management: Blocked stock coming up in OnHand

    Hello Experts - We've implemented 2LIS_03_BF for our inventory management reports. However, the OnHand quantity is also picking up Blocked quantity. I used the same code as given by SAP. For a material, the OnHand quantity is 13 in our reports when t

  • Mail not saving sent messages

    I've noticed that Mail is not saving my sent messages. I started to notice this yesterday. It's very erratic though. Sometimes it does, sometimes it doesn't. I have the option selected in preferences to Store Sent Messages on the Server (my .mac acco

  • Satellite A100: looking for software to control the fan speed

    Hi, I'm looking for software to control/read out the fan speed of my laptop, because Power Saver does not seem to do anything. It does not seem to matter if i set the 'Cooling Method' to 'Battery Optimized' or 'Maximum Performance', or even the fixed