I'm using Eclipse and it's giving me an error saying "Cannot invoke compareTo(int) on the primitive type int". Here is my code:
namespace Laser_Control2
{
public partial class LaserControlForm : Form
{
public LaserControlForm()
{
InitializeComponent();
}
// Manipulate a bitmap image
// Extract the pixel map data
// To run this example, paste it into a form and handle the form's Paint event
// by calling the LockUnlockBitsExample method, passing e as PaintEventArgs.
private void LockUnlockBitsExample(PaintEventArgs e)
{
// Create a new bitmap.
Bitmap bmp = new Bitmap("c:\\fakePhoto.jpg");
// Lock the bitmap's bits.
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData =
bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
bmp.PixelFormat);
// Get the address of the first line.
IntPtr ptr = bmpData.Scan0;
// Declare an array to hold the bytes of the bitmap.
int bytes = Math.Abs(bmpData.Stride) * bmp.Height;
byte[] rgbValues = new byte[bytes];
// Copy the RGB values into the array.
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
// Set every third value to 255. A 24bpp bitmap will look red.
for (int counter = 2; counter < rgbValues.Length; counter += 3)
rgbValues[counter] = 255;
// Copy the RGB values back to the bitmap
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);
// Unlock the bits.
bmp.UnlockBits(bmpData);
// Draw the modified image.
e.Graphics.DrawImage(bmp, 0, 150);
}
private void loadPdfButton_Click(object sender, EventArgs e)
{
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
PdfDocument doc = new PdfDocument(); // Create Spire object - a new document
doc.LoadFromFile(@"E:/Test/test2.pdf"); // Load test2.pdf into new document
Image bmp = doc.SaveAsImage(0, 0, 32, 32); // Save the .pdf doc as a .bmp
pictureBox1.Image = bmp;
bmp.Save("convertToBmp.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
System.Diagnostics.Process.Start("convertToBmp.bmp");
}
}
private void clearButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
The example we were given in class does a similar thing except it is using a double value, so I'm not sure why the file from class works, but mine doesn't. I'd appreciate any help.
Example from class:
public class ReadingMaterial implements Comparable<ReadingMaterial> {
private int pages;
private String title;
private String author;
public ReadingMaterial(int pages, String title, String author)
{
super();
this.title = title;
this.pages = pages;
this.author = author;
}
public int getPages()
{
return pages;
}
public void setPages(int pages)
{
this.pages = pages;
}
public String getAuthor()
{
return author;
}
public void setAuthor(String author)
{
this.author = author;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
@Override
public int compareTo(ReadingMaterial o) {
if(pages.compareTo(o.getPages()) > 0)
return -1;
else if(pages.compareTo(o.getPages()) < 0)
return 1;
else
{
return 0;
}
}
@Override
public String toString()
{
return "The reading material you selected is titled " + title + " with" + pages + "pages. It is written by " + author + ".";
}
}