I want to display a Vertical Gradient as the background for a ListField Row in BlackBerry. I have used shadedFillPath function to achieve this, but failed:
int[] cols = new int[]{0xFFFFFF, 0xEEEEEE,0xEEEEEE,0XDDDDDD };
int[] xInds = new int[]{0, Display.getWidth(), Display.getWidth(), 0};
int[] yInds = new int[]{focusRect.y, focusRect.y,
this.getRowHeight()+focusRect.y,this.getRowHeight()+focusRect.y};
graphics.drawShadedFilledPath(xInds, yInds,null, cols, null);
try this
int[] X_PTS = { 0, getPreferredWidth(),getPreferredWidth(),0};
int[] Y_PTS = { 0,0, getPreferredHeight(),getPreferredHeight()};
int[] drawColors = { Colors.CategoryFocusGradientStart, Colors.CategoryFocusGradientStart,
Colors.CategoryFocusGradientEnd, Colors.CategoryFocusGradientEnd };
try {
g.drawShadedFilledPath(X_PTS, Y_PTS, null, drawColors, null);
} catch (IllegalArgumentException e) {
Log.Error(e,this,"Bad arguments.");
}
Its not the #rfsk2010 answer , but nearly (you must change that 0's for y):
Into:
public void drawListRow(ListField listField, Graphics graphics,int index, int y, int width)
Do this:
int[] X_PTS = { 0, getPreferredWidth(),getPreferredWidth(),0};
int[] Y_PTS = { y, y, getPreferredHeight(),getPreferredHeight()};
int[] drawColors = { Colors.CategoryFocusGradientStart, Colors.CategoryFocusGradientStart,
Colors.CategoryFocusGradientEnd, Colors.CategoryFocusGradientEnd };
try {
graphics.drawShadedFilledPath(X_PTS, Y_PTS, null, drawColors, null);
} catch (IllegalArgumentException e) {
Log.Error(e,this,"Bad arguments.");
}
Related
I just want to know how can I change ListField's item background color. I have two items in my ListField like this one.
|First One|Second One.................|
I need to change first one's background color.
My drawListRow(..) method looks like this
public void drawListRow(ListField listField, Graphics graphics,
int index, int y, int width) {
int oldColor = 0;
try {
oldColor = graphics.getColor();
String txt = (vector.elementAt(index)).toString();
int xPos = 15;
int yPos = 5 + y;
//graphics.clear();
graphics.setColor(Color.GREEN);
graphics.fillRect(0, y, (Display.getWidth()*10/100), yPos);
graphics.drawText(txt, xPos, yPos);
//graphics.fillRect(0,(index*Display.getHeight()/10),Display.getWidth(),Display.getHeight()/10);
} finally {
graphics.setColor(oldColor);
}
}
But this is not working.
Though you have attached an image, I am still confused. The image didn't answer some question, for example, how it will look on a row get focused (I didn't understand actually).
But you can check following output and code. I think you can customize the look as you wish if you check the code.
Generated Output
How to use
public class MyScreen extends MainScreen {
private Vector listElements;
public MyScreen() {
setTitle("Custom ListField Demo");
// data for the ListField
listElements = new Vector();
for (int i = 0; i < 4; i++) {
listElements.addElement("Some text for row " + i);
}
ListField taskList = new ListField() {
// disable default focus drawing
protected void drawFocus(Graphics graphics, boolean on) {
};
};
taskList.setCallback(new ListCallback(listElements));
taskList.setSize(listElements.size());
taskList.setRowHeight(40);
add(taskList);
}
}
ListCallback implementation
class ListCallback implements ListFieldCallback {
final int COLOR_INDEX_NORMAL_BG = 0x1D6789;
final int COLOR_INDEX_FOCUSED_BG = 0x0E8CB3;
final int COLOR_NORMAL_BG = 0x2A2A2A;
final int COLOR_FOCUSED_BG = 0x1F1F1F;
private Vector listElements;
public ListCallback(Vector listElements) {
this.listElements = listElements;
}
public void drawListRow(ListField list, Graphics graphics, int index, int y,
int width) {
int rowHeight = list.getRowHeight(index);
boolean isSelectedRow = (list.getSelectedIndex() == index);
int indexBgColor = isSelectedRow ? COLOR_INDEX_FOCUSED_BG : COLOR_INDEX_NORMAL_BG;
int rowBgColor = isSelectedRow ? COLOR_FOCUSED_BG : COLOR_NORMAL_BG;
final int indexWidth = width / 10;
// draw row background
fillRectangle(graphics, rowBgColor, 0, y, width, rowHeight);
// draw index background
fillRectangle(graphics, indexBgColor, 0, y, indexWidth, rowHeight);
// set text color, draw text
Font font = list.getFont();
graphics.setColor(Color.WHITE );
graphics.setFont(font);
String indexText = "" + (index + 1);
String textToDraw = "";
try {
textToDraw = (String) listElements.elementAt(index);
} catch (Exception exc) {
}
int xText = (indexWidth - font.getAdvance(indexText)) / 2;
int yText = (rowHeight - font.getHeight()) / 2;
graphics.drawText(indexText, xText, y + yText, 0, indexWidth);
final int margin = 5;
int availableWidth = (width - indexWidth) - 2 * margin;
xText = indexWidth + margin;
yText = (rowHeight - font.getHeight()) / 2;
graphics.drawText(textToDraw, xText, y + yText, DrawStyle.ELLIPSIS, availableWidth);
}
private void fillRectangle(Graphics graphics, int color, int x, int y, int width, int height) {
graphics.setColor(color);
graphics.fillRect(x, y, width, height);
}
public Object get(ListField list, int index) {
// not implemented
return "";
}
public int indexOfList(ListField list, String prefix, int string) {
// not implemented
return 0;
}
public int getPreferredWidth(ListField list) {
return Display.getWidth();
}
}
If you need to change onFocus Background color than add drwFocus method on your ListField.
protected void drawFocus(Graphics graphics, boolean on) {
//get the focus rect area
XYRect focusRect = new XYRect();
getFocusRect(focusRect);
boolean oldDrawStyleFocus = graphics.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS);
try {
if (on) {
//set the style so the fields in the row will update its color accordingly
graphics.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, true);
int oldColour = graphics.getColor();
try {
graphics.setColor(0xc8d3db); //set the color and draw the color
graphics.fillRect(focusRect.x, focusRect.y,
focusRect.width, focusRect.height);
} finally {
graphics.setColor(oldColour);
}
//to draw the row again
drawListRow(this, graphics, getSelectedIndex(),
focusRect.y, focusRect.width);
// drawRow(graphics, focusRect.x,focusRect.y, focusRect.width,focusRect.height);
}
} finally {
graphics.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, oldDrawStyleFocus);
}
}
Check the edited answer,
protected void drawFocus(Graphics graphics, boolean on) {
XYRect focusRect = new XYRect();
getFocusRect(focusRect);
boolean oldDrawStyleFocus = graphics.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS);
try {
if (on) {
graphics.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, true);
int oldColour = Color.BLACK;
try {
graphics.fillRect(focusRect.x, focusRect.y,
focusRect.width, focusRect.height);
} finally {
graphics.setColor(oldColour);
}
//to draw the row again
drawListRow(this, graphics, getSelectedIndex(),
focusRect.y, focusRect.width);
}
} finally {
graphics.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, oldDrawStyleFocus);
}
}
I want to show a image from the SD card in a BitmapField. How to do that? Can anyone give me some sample code for that?
This may be Help full.
public Bitmap getImage(){
Bitmap bitmapImage=null;
try{
InputStream input;
FileConnection fconn = (FileConnection) Connector.open("file:///store/home/user/dirname/imgname.png", Connector.READ_WRITE);
input = fconn.openInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int j = 0;
while((j=input.read()) != -1) {
baos.write(j);
}
byte[] byteArray = baos.toByteArray();
bitmapImage = Bitmap.createBitmapFromBytes(byteArray,0,byteArray.length,1);
}catch(Exception ioe){
System.out.println(ioe);
}
return bitmapImage;
}
Enjoy..
Hi Guys above code is useful for BB OS >= 5.0
I'm using a code which can used for OS 4.2 or higher.
private Bitmap resizeBitmap(Bitmap image, int width, int height)
{
int rgb[] = new int[image.getWidth()*image.getHeight()];
image.getARGB(rgb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
int rgb2[] = rescaleArray(rgb, image.getWidth(), image.getHeight(), width, height);
Bitmap temp2 = new Bitmap(width, height);
temp2.setARGB(rgb2, 0, width, 0, 0, width, height);
return temp2;
}
private int[] rescaleArray(int[] ini, int x, int y, int x2, int y2)
{
int out[] = new int[x2*y2];
for (int yy = 0; yy < y2; yy++)
{
int dy = yy * y / y2;
for (int xx = 0; xx < x2; xx++)
{
int dx = xx * x / x2;
out[(x2 * yy) + xx] = ini[(x * dy) + dx];
}
}
return out;
}
Try this sample code:
public class LoadingScreen extends MainScreen implements FieldChangeListener
{
private VerticalFieldManager ver;
private ButtonField showImage;
private BitmapField bitmapField;
public LoadingScreen()
{
ver=new VerticalFieldManager(USE_ALL_WIDTH);
showImage=new ButtonField("Show Image",Field.FIELD_HCENTER);
showImage.setChangeListener(this);
ver.add(showImage);
bitmapField=new BitmapField(null,Field.FIELD_HCENTER);
bitmapField.setPadding(10, 0, 10, 0);
ver.add(bitmapField);
add(ver);
}
public void fieldChanged(Field field, int context)
{
if(field==showImage)
{
selectImageFromSDCARD();
}
}
private void selectImageFromSDCARD()
{
String PATH="";
if(SDCardTest.isSDCardAvailable())//sdcard available then
PATH = System.getProperty("fileconn.dir.memorycard.photos");//The default stored Images Path;
else
PATH = System.getProperty("fileconn.dir.photos");//The default stored Images Path;
FilePicker filePicker=FilePicker.getInstance();
filePicker.setPath(PATH);
filePicker.setListener(new Listener()
{
public void selectionDone(String url)
{
System.out.println("======================URL: "+url);
try
{
FileConnection file = (FileConnection)Connector.open(url);
if(file.exists())
{
InputStream inputStream = file.openInputStream();
byte[] data=new byte[inputStream.available()];
data=IOUtilities.streamToBytes(inputStream);
Bitmap bitmap=Bitmap.createBitmapFromBytes(data, 0, data.length,1);//Here we get the Image;
Bitmap scaleBitmap=new Bitmap(400, 300);//Now we are scaling that image;
bitmap.scaleInto(scaleBitmap, Bitmap.FILTER_LANCZOS);
bitmapField.setBitmap(scaleBitmap);
}
else
{
bitmapField.setBitmap(Bitmap.getBitmapResource("icon.png"));
}
}
catch (IOException e)
{
bitmapField.setBitmap(Bitmap.getBitmapResource("icon.png"));
}
}
});
filePicker.show();
}
protected boolean onSavePrompt() //It doesn't show the "Save","Discard","Cancel" POPUP;
{
return true;
}
public boolean onMenu(int instance) //It doesn't show the Menu;
{
return true;
}
}
If you have any doubts refer this Blog: Get Image From SDcard
I am using a customlistfield by extending VerticalFieldManager, and for the row I am usingf another CustoRowManager that extends Manager. The CustomRowManager has 2 TextField and a BitmapField . This list is implemented for a live xml feed. For loading the bitmapfield I am displaying placeholders which is then replaced by the actual image from background thread. I am not able to figure out how I should replace place holders with the bitmapfield. using invalidate() is one option, but on which element I should perform it.
public class CustomList extends VerticalFieldManager{
private int totalHeight = 0;
private int screenHeight = 0;
private int scrollPosition = 0;
protected void sublayout(int width, int height)
{
width = 480;
height = 230;
super.sublayout(width,height);
setExtent(width, height);
}
protected boolean navigationClick(int status, int time)
{
int index;
System.out.println("CLICKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
if ((status & KeypadListener.STATUS_FOUR_WAY) == KeypadListener.STATUS_FOUR_WAY)
{
index = this.getFieldWithFocusIndex();
UiApplication.getUiApplication().pushScreen(new TopNewsScreen(_vec, index));
}
return true;
}
Bitmap _bmp = null;
BitmapField _bmF = null;
Object _Obj = null;
TopNews _topNews = null;
String _headStr = null, _metaStr = null;
CustTextField _headNews = null, _metaData = null;
CustomRow _custRow = null;
Vector _vec;
public CustomList(Vector _vec,long _property)
{
super(_property);
this._vec = new Vector();
this._vec = _vec;
int _size = _vec.size();
int i ;
for(i = 0; i <_size; i++)
{
_headStr = new String();
_metaStr = new String();
_bmp = Bitmap.getBitmapResource("img/1.jpg");
_bmF = new BitmapField(_bmp);
_topNews = (TopNews)_vec.elementAt(i);
_headStr = _topNews.getHeadline();
_metaStr = _topNews.getMetaData();
int _newsLeng = _headStr.length(), alert = 0;
if(_newsLeng <= 35)
{
alert = 0;
}else if(_newsLeng>35&&_newsLeng<=70)
{
alert = 1;
}else {
alert = 2;
_headStr = this.truncate(_headStr,70);
}
_custRow = new CustomRow(alert);
_headNews = new CustTextField(_headStr,25,0x05235b,TextField.NON_FOCUSABLE);
_metaData = new CustTextField(_metaStr,15,0x666666,TextField.NON_FOCUSABLE);
_custRow.add(_headNews);
_custRow.add(_metaData);
_custRow.add(_bmF);
super.add(_custRow);
}
}
String truncate(String value, int length)
{
if (value != null && value.length() > length)
value = value.substring(0, length);
return value;
}
}
class CustomRow extends Manager implements FocusChangeListener{
private int _headLeng;
private NullField _focus = null;
CustomRow(int _headLeng)
{
super(Manager.FOCUSABLE|
Manager.NO_HORIZONTAL_SCROLL
|Manager.NO_VERTICAL_SCROLL);
this._headLeng = _headLeng;
_focus = new NullField(NullField.FOCUSABLE);
_focus.setFocusListener(CustomRow.this);
this.add(_focus);
}
protected void sublayout(int width, int height)
{
if(_headLeng==0)
{
layoutChild(getField(0),0,0);
setPositionChild(getField(0),0 , 0);
layoutChild(getField(1),360,20);
setPositionChild(getField(1),10 , 10);
layoutChild(getField(2),300, 20);
setPositionChild(getField(2), 10, 65);
layoutChild(getField(3),90,65);
setPositionChild(getField(3), 380, 10);
}else
{
/* layoutChild(getField(0),0,0);
setPositionChild(getField(0),0 , 0);
layoutChild(getField(1),360,20);
setPositionChild(getField(1),10 , 10);
layoutChild(getField(2),300, 20);
setPositionChild(getField(2), 10, 50);
layoutChild(getField(3),90,65);
setPositionChild(getField(3), 380, 10); */
layoutChild(getField(0),0,0);
setPositionChild(getField(0),0 , 0);
layoutChild(getField(1),360,20);
setPositionChild(getField(1),10 , 10);
layoutChild(getField(2),300, 20);
setPositionChild(getField(2), 10, 65);
layoutChild(getField(3),90,65);
setPositionChild(getField(3), 380, 10);
}
height = 80;
width = 480;
setExtent(width, height);
}
protected void paint(Graphics graphics)
{
graphics.setColor(Color.GRAY);
graphics.drawLine(10, 79, Display.getWidth()-10, 79);
super.paint(graphics);
}
public void focusChanged(Field field, int eventType) {
// TODO Auto-generated method stub
this.getManager().invalidate();
}
protected void paintBackground(Graphics g) {
int prevBg = g.getBackgroundColor();
if (_focus.isFocus()) {
g.setBackgroundColor(Color.LIGHTBLUE);
} else {
g.setBackgroundColor(Color.WHITE);
}
g.clear();
g.setBackgroundColor(prevBg);
}
}
the below link has answer for the question, I should change the name to Blackberry lazyloading.
http://supportforums.blackberry.com/t5/Java-Development/Clumsy-layout-invalidate/m-p/1398763
In my app i have to show list of items in list field when i click on specific item in the list field the background color for a particular row change to grey color.How to develop this type of custom list field in Blackberrry.Any one please give ideas.
Thank You
you should draw rectangle in listfield row which is selected.. some thing like this. Here i have done it for on focus..
public void drawListRow(ListField list, Graphics g, int index, int y,int w) {
if (g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS))
{
g.setBackgroundColor(0x00572000);
//g.setBackgroundColor();
g.clear();
//g.setColor(Color.BLACK);
// g.fillRect(0,list.getWidth(),list.getWidth(),80);
g.setColor(Color.ORANGE);
g.fillRect(94,y+0,400,30);
//g.setColor(0x000000);
g.setColor(Color.WHITE);
g.drawText(text, 95, y+10, (DrawStyle.LEFT ), w );
}
else
{
g.setColor(0x00906966);
g.fillRect(94,y+0,400,30);
g.setColor(Color.ORANGE);
g.drawText(text, 95, y+10, (DrawStyle.LEFT ), w );
}}
Try this ...
private class MyListField extends ListField{
//0,ListField.MULTI_SELECT
private boolean hasFocus = false;
public void onFocus(int direction){
hasFocus = true;
}
public void onUnfocus()
{
hasFocus = false;
super.onUnfocus();
invalidate();
}
public void paint(Graphics graphics)
{ int width = Display.getWidth();
//Get the current clipping region
XYRect redrawRect = graphics.getClippingRect();
if(redrawRect.y < 0)
{
throw new IllegalStateException("Error with clipping rect.");
}
//Determine the start location of the clipping region and end.
int rowHeight = getRowHeight();
int curSelected;
//If the ListeField has focus determine the selected row.
if (hasFocus)
{
curSelected = getSelectedIndex();
}
else
{
curSelected = -1;
}
int startLine = redrawRect.y / rowHeight;
int endLine = (redrawRect.y + redrawRect.height - 1) / rowHeight;
endLine = Math.min(endLine, getSize() - 1);
int y = startLine * rowHeight;
//Setup the data used for drawing.
int[] yInds = new int[]{y, y, y + rowHeight, y + rowHeight};
int[] xInds = new int[]{0, width, width, 0};
//Set the callback - assuming String values.
ListFieldCallback callBack = this.getCallback();
//Draw each row
for(; startLine <= endLine; ++startLine)
{
//If the line we're drawing is the currentlySelected line then draw the fill path in LIGHTYELLOW and the
//font text in Black.
if(startLine == curSelected){
graphics.setColor(Color.LIGHTYELLOW);
graphics.drawFilledPath(xInds, yInds, null, null);
graphics.setColor(Color.BLACK);
graphics.drawText((String)callBack.get(this, startLine), 0, yInds[0]);
}
else{
//Draw the odd or selected rows.
graphics.setColor(Color.LIGHTGREY);
graphics.drawText((String)callBack.get(this, startLine), 0, yInds[0]);
}
//Assign new values to the y axis moving one row down.
y += rowHeight;
yInds[0] = y;
yInds[1] = yInds[0];
yInds[2] = y + rowHeight;
yInds[3] = yInds[2];
}
//super.paint(graphics);
}
}
.
.
.
refer this [LINK] : http://berrytutorials.blogspot.com/2009/11/create-custom-listfield-change.html
I can not find a way to stop the out of memory error. The error occurs when I move the brightness or contrast track bar a few times.
Here is the code from the main form design for the button_click event that that opens the brightness and contrast form and send the value of "foto".
private void menuItemBrightness_Click(object sender, EventArgs e)
{
BrightnessContrast bFrm = new BrightnessContrast();
bFrm.Foto = imageHandler.CurrentBitmap;
if (bFrm.ShowDialog() == DialogResult.OK)
{
this.Cursor = Cursors.WaitCursor;
imageHandler.RestorePrevious();// this is for a undo or redo ... ignore this part
imageHandler.CurrentBitmap = bFrm.Foto1;
pictureBox1.Refresh();
this.Cursor = Cursors.Default;
}
}
Here is the complete code for the brightness and contras form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace SMART {
public partial class BrightnessContrast : Form {
ImageHandler imageHandler = new ImageHandler();
public int B = 0;
private int C = 0;
private static Bitmap foto;
private static Bitmap foto1;
private static Bitmap NewBitmap;
public BrightnessContrast()
{
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
InitializeComponent();
btnOK.DialogResult = DialogResult.OK;
btnCancel.DialogResult = DialogResult.Cancel;
domainUpDownB.SelectedIndex = 255;
domainUpDownC.SelectedIndex = 75;
}
private void BrightnessForm_Load(object sender, EventArgs e)
{ pictureBox2.Image = foto; }
public Bitmap Foto
{
get { return foto; }
set { foto = value; }
}
public Bitmap Foto1
{
get { return foto1; }
set { foto1 = value; }
}
public void brightnesstrackBar1_ValueChanged(object sender, EventArgs e)
{
domainUpDownB.Text = ((int)brightnessTrackBar.Value).ToString();
B = ((int)brightnessTrackBar.Value);
pictureBox2.Image = AdjustBrightness(foto, B);
foto1 = (Bitmap)pictureBox2.Image;
}
private void domainUpDown_TextChanged(object sender, EventArgs e)
{
try
{
brightnessTrackBar.Value = Convert.ToInt32(domainUpDownB.Text);
brightnesstrackBar1_ValueChanged(sender, e);
}
catch (Exception)
{
MessageBox.Show("Incorect Input Value Format");
}
}
public static Bitmap AdjustBrightness(Bitmap Image, int Value)
{
Bitmap TempBitmap = Image;
float FinalValue = (float)Value / 255.0f;
NewBitmap = new Bitmap(TempBitmap.Width, TempBitmap.Height);
Graphics NewGraphics = Graphics.FromImage(NewBitmap);
float[][] FloatColorMatrix ={
new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {FinalValue, FinalValue, FinalValue, 1, 1
}
};
ColorMatrix NewColorMatrix = new ColorMatrix(FloatColorMatrix);
ImageAttributes Attributes = new ImageAttributes();
Attributes.SetColorMatrix(NewColorMatrix);
NewGraphics.DrawImage(TempBitmap, new Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), 0, 0, TempBitmap.Width, TempBitmap.Height, GraphicsUnit.Pixel, Attributes);
Attributes.Dispose();
NewGraphics.Dispose();
return NewBitmap;
}
public void contrastrackBar1_ValueChanged(object sender, EventArgs e)
{
domainUpDownC.Text = ((int)contrastTrackBar.Value).ToString();
C = ((int)contrastTrackBar.Value);
pictureBox2.Image = AdjustContrast(foto, C);
foto1 = (Bitmap)pictureBox2.Image;
}
public static Bitmap AdjustContrast(Bitmap Image, int Value)
{
Bitmap TempBitmap = Image;
float FinalValue = (float)Value*0.04f;
NewBitmap = new Bitmap(TempBitmap.Width, TempBitmap.Height);
Graphics NewGraphics = Graphics.FromImage(NewBitmap);
ImageAttributes Attributes = new ImageAttributes();
ColorMatrix NewColorMatrix = new ColorMatrix (new float[][] {
new float[] {FinalValue, 0f, 0f, 0f, 0f},
new float[] {0f, FinalValue, 0f, 0f, 0f},
new float[] {0f, 0f, FinalValue, 0f, 0},
new float[] {0f, 0f, 0f, 1f, 0f},
new float[] {0.001f, 0.001f, 0.001f, 0f, 1f}
});
Attributes.SetColorMatrix(NewColorMatrix);
NewGraphics.DrawImage(TempBitmap, new Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), 0, 0, TempBitmap.Width, TempBitmap.Height, GraphicsUnit.Pixel, Attributes);
Attributes.Dispose();
NewGraphics.Dispose();
return NewBitmap;
}
OK here is the problem ... if I load a big image(as in pixels for example) and start moving the track Bar after a few moves it will show the famous "Out of memory exception was unhanded" and the error points to this line
NewGraphics.DrawImage(TempBitmap,
new System.Drawing.Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), 0, 0,
TempBitmap.Width, TempBitmap.Height, System.Drawing.GraphicsUnit.Pixel,
Attributes);
I am using Attributes.Dispose(); NewGraphics.Dispose(); way i still have the error what I am missing?
Dispose gets rid of the unmanged resources (handles, unmanaged memory). There is probably a managed memory footprint here as well and that only gets free when the garbage collect occurs. My guess is that you need to reuse some of these bigger memory objects rather than having to recreate them each time.